Skip to content

Commit 07742ca

Browse files
committed
feat: add ll.pluginsRoot and ll.getCurrentPluginInfo apis
1 parent ad2462a commit 07742ca

File tree

4 files changed

+64
-0
lines changed

4 files changed

+64
-0
lines changed

docs/apis/ScriptAPI/Ll.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Some interfaces related to loader operations are provided here.
1717
| `ll.isBeta` | `Boolean` | Whether the current version is a beta version |
1818
| `ll.isDev` | `Boolean` | Whether the current version is a dev version |
1919
| `ll.isRelease` | `Boolean` | Whether the current version is a release version |
20+
| `ll.pluginsRoot` | `String` | Root directory of LeviLamina plugins |
2021

2122
### Get LegacyScriptEngine loader version string
2223

@@ -49,6 +50,13 @@ Some interfaces related to loader operations are provided here.
4950
| plugin.filePath | Path to plugin | `String` |
5051
| plugin.others | Other information | `Object` |
5152

53+
### Get information about current Plugin
54+
55+
`ll.getCurrentPluginInfo()`
56+
57+
- Return value: Plugin Object
58+
- Return value type: `Plugin`
59+
5260
### List all loaded plugins
5361

5462
`ll.listPlugins()`

docs/apis/ScriptAPI/Ll.zh.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
| `ll.isBeta` | `Boolean` | 当前版本是否为测试版 |
1818
| `ll.isDev` | `Boolean` | 当前版本是否为开发版 |
1919
| `ll.isRelease` | `Boolean` | 当前版本是否为发布版本 |
20+
| `ll.pluginsRoot` | `String` | LeviLamina插件的根目录 |
2021

2122
### 获取 LegacyScriptEngine 版本字符串
2223

@@ -49,6 +50,13 @@
4950
| plugin.filePath | 插件路径 | `String` |
5051
| plugin.others | 其他信息 | `Object` |
5152

53+
### 获取当前插件的信息
54+
55+
`ll.getCurrentPluginInfo()`
56+
57+
- 返回值: 插件对象
58+
- 返回值类型: `Plugin`
59+
5260
### 列出所有已加载的插件
5361

5462
`ll.listPlugins()`

src/legacy/api/LlAPI.cpp

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
#include "api/LlAPI.h"
22

33
#include "api/APIHelp.h"
4+
#include "engine/EngineOwnData.h"
45
#include "engine/GlobalShareData.h"
56
#include "ll/api/Versions.h"
67
#include "ll/api/data/Version.h"
8+
#include "ll/api/mod/Mod.h"
79
#include "ll/api/mod/ModManagerRegistry.h"
810
#include "ll/api/reflection/Serialization.h"
911
#include "ll/api/utils/SystemUtils.h"
@@ -24,6 +26,7 @@ ClassDefine<void> LlClassBuilder = defineClass("ll")
2426
.property("isRelease", &LlClass::isRelease)
2527
.property("isBeta", &LlClass::isBeta)
2628
.property("isDev", &LlClass::isDev)
29+
.property("pluginsRoot", &LlClass::getPluginsRoot)
2730

2831
.function("versionString", &LlClass::versionString)
2932
.function("requireVersion", &LlClass::requireVersion)
@@ -36,6 +39,7 @@ ClassDefine<void> LlClassBuilder = defineClass("ll")
3639
.function("eval", &LlClass::eval)
3740
.function("registerPlugin", &LlClass::registerPlugin)
3841
.function("getPluginInfo", &LlClass::getPluginInfo)
42+
.function("getCurrentPluginInfo", &LlClass::getCurrentPluginInfo)
3943
.function("checkVersion", &LlClass::requireVersion)
4044
.function("onUnload", &LlClass::onUnload)
4145

@@ -169,6 +173,13 @@ Local<Value> LlClass::getVersionStatus() {
169173
}
170174
}
171175

176+
Local<Value> LlClass::getPluginsRoot() {
177+
try {
178+
return String::newString(ll::mod::getModsRoot().u8string());
179+
}
180+
CATCH("Fail in getPluginsRoot")
181+
}
182+
172183
Local<Value> LlClass::registerPlugin(const Arguments& args) {
173184
if (args.size() == 0) {
174185
return Boolean::newBoolean(true);
@@ -313,6 +324,41 @@ Local<Value> LlClass::getPluginInfo(const Arguments& args) {
313324
}
314325
CATCH("Fail in getPluginInfo");
315326
}
327+
328+
Local<Value> LlClass::getCurrentPluginInfo(const Arguments& args) {
329+
try {
330+
auto plugin = getEngineOwnData()->plugin;
331+
if (plugin) {
332+
auto result = Object::newObject();
333+
334+
result.set("name", plugin->getManifest().name);
335+
if (plugin->getManifest().description.has_value()) {
336+
result.set("desc", plugin->getManifest().description.value());
337+
}
338+
339+
auto ver = Array::newArray();
340+
ver.add(Number::newNumber(plugin->getManifest().version->major));
341+
ver.add(Number::newNumber(plugin->getManifest().version->minor));
342+
ver.add(Number::newNumber(plugin->getManifest().version->patch));
343+
344+
result.set("version", ver);
345+
result.set("versionStr", plugin->getManifest().version->to_string());
346+
result.set("filePath", plugin->getManifest().entry);
347+
if (plugin->getManifest().extraInfo.has_value()) {
348+
auto others = Object::newObject();
349+
for (const auto& [k, v] : plugin->getManifest().extraInfo.value()) {
350+
others.set(k, v);
351+
}
352+
result.set("others", others);
353+
}
354+
355+
return result;
356+
}
357+
return {};
358+
}
359+
CATCH("Fail in getCurrentPluginInfo");
360+
}
361+
316362
Local<Value> LlClass::versionString(const Arguments&) {
317363
try {
318364
auto& ver = lse::LegacyScriptEngine::getInstance().getSelf().getManifest().version;

src/legacy/api/LlAPI.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class LlClass {
1919
static Local<Value> isDev();
2020
static Local<Value> isWine();
2121
static Local<Value> isDebugMode();
22+
static Local<Value> getPluginsRoot();
2223

2324
static Local<Value> registerPlugin(const Arguments& args);
2425
static Local<Value> versionString(const Arguments& args);
@@ -31,6 +32,7 @@ class LlClass {
3132
static Local<Value> require(const Arguments& args);
3233
static Local<Value> eval(const Arguments& args);
3334
static Local<Value> getPluginInfo(const Arguments& args);
35+
static Local<Value> getCurrentPluginInfo(const Arguments& args);
3436
static Local<Value> onUnload(const Arguments& args);
3537

3638
// For Compatibility

0 commit comments

Comments
 (0)