Skip to content

Commit 7b1d58a

Browse files
authored
feat: add python & nodejs support (#62)
1 parent 24b9985 commit 7b1d58a

17 files changed

+607
-759
lines changed

.github/workflows/build.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
strategy:
1818
matrix:
1919
backend:
20-
# - libnode
20+
- nodejs
2121
- lua
22-
# - python310
22+
- python
2323
- quickjs
2424
steps:
2525
- uses: actions/checkout@v4

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ jobs:
99
strategy:
1010
matrix:
1111
backend:
12-
# - libnode
12+
- nodejs
1313
- lua
14-
# - python310
14+
- python
1515
- quickjs
1616
steps:
1717
- uses: actions/checkout@v4

src/legacy/api/APIHelp.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
#include <cmath>
1919
#include <iostream>
20+
#include <ll/api/utils/StringUtils.h>
2021
#include <string>
2122
#include <vector>
2223

@@ -458,7 +459,7 @@ std::string ValueToJson(Local<Value> v, int formatIndent) {
458459
switch (v.getKind()) {
459460
case ValueKind::kString:
460461
result = "\"" + v.asString().toString() + "\"";
461-
ReplaceStr(result, "\n", "\\n");
462+
result = ll::string_utils::replaceAll(result, "\n", "\\n");
462463
break;
463464
case ValueKind::kNumber:
464465
if (CheckIsFloat(v)) {

src/legacy/api/APIHelp.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,3 @@ struct EnumDefineBuilder {
317317
return builder.build();
318318
}
319319
};
320-
321-
inline void ReplaceStr(std::string& str, const std::string& from, const std::string& to) {
322-
size_t startPos = 0;
323-
while ((startPos = str.find(from, startPos)) != std::string::npos) {
324-
str.replace(startPos, from.length(), to);
325-
startPos += to.length();
326-
}
327-
}

src/legacy/api/EventAPI.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
#include "engine/EngineOwnData.h"
1515
#include "engine/GlobalShareData.h"
1616
#include "legacy/events/EventHooks.h"
17+
#include "legacy/main/NodeJsHelper.h"
18+
#include "legacy/main/PythonHelper.h"
1719
#include "ll/api/chrono/GameChrono.h"
1820
#include "ll/api/event/EventBus.h"
1921
#include "ll/api/event/command/ExecuteCommandEvent.h"
@@ -867,13 +869,13 @@ void InitBasicEventListeners() {
867869
ev.cancel();
868870
return;
869871
}
870-
#ifdef LLSE_BACKEND_NODEJS
871-
if (!NodeJsHelper::processConsoleNpmCmd(ev.mCommand)) {
872+
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
873+
if (!NodeJsHelper::processConsoleNpmCmd(ev.commandContext().mCommand)) {
872874
ev.cancel();
873875
return;
874876
}
875-
#elif defined(LLSE_BACKEND_PYTHON)
876-
if (!PythonHelper::processConsolePipCmd(ev.mCommand)) {
877+
#elif defined(LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON)
878+
if (!PythonHelper::processConsolePipCmd(ev.commandContext().mCommand)) {
877879
ev.cancel();
878880
return;
879881
}
@@ -994,7 +996,7 @@ void InitBasicEventListeners() {
994996
using namespace ll::chrono_literals;
995997

996998
scheduler.add<ll::schedule::RepeatTask>(1_tick, [] {
997-
#ifndef LLSE_BACKEND_NODEJS
999+
#ifndef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
9981000
try {
9991001
std::list<ScriptEngine*> tmpList;
10001002
{

src/legacy/engine/EngineManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ bool EngineManager::registerEngine(ScriptEngine* engine) {
3434
ScriptEngine* EngineManager::newEngine(string pluginName, bool isHotLoad) {
3535
ScriptEngine* engine = nullptr;
3636

37-
#if defined(LLSE_BACKEND_NODEJS)
37+
#if defined(LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS)
3838
engine = NodeJsHelper::newEngine();
3939
#elif !defined(SCRIPTX_BACKEND_WEBASSEMBLY)
4040
engine = new ScriptEngineImpl();

src/legacy/main/BindAPIs.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ void BindAPIs(ScriptEngine* engine) {
4040
engine->set("colorLog", Function::newFunction(ColorLog));
4141
engine->set("fastLog", Function::newFunction(FastLog));
4242

43-
#ifndef LLSE_BACKEND_NODEJS // NodeJs has its own functions below
43+
#ifndef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS // NodeJs has its own functions below
4444
engine->set("setTimeout", Function::newFunction(SetTimeout));
4545
engine->set("setInterval", Function::newFunction(SetInterval));
4646
engine->set("clearInterval", Function::newFunction(ClearInterval));

src/legacy/main/BuiltinCommands.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
#include <string>
1414

15-
#ifdef LLSE_BACKEND_PYTHON
15+
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
1616
#include "PythonHelper.h"
1717
#endif
1818

@@ -22,7 +22,7 @@ extern ScriptEngine* debugEngine;
2222
#define OUTPUT_DEBUG_SIGN() std::cout << "> " << std::flush
2323

2424
bool ProcessDebugEngine(const std::string& cmd) {
25-
#ifdef LLSE_BACKEND_PYTHON
25+
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
2626
// process python debug seperately
2727
return PythonHelper::processPythonDebugEngine(cmd);
2828
#endif

src/legacy/main/Configs.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@
1212

1313
#endif
1414

15+
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_PYTHON
16+
17+
#define LLSE_BACKEND_PYTHON
18+
19+
#endif
20+
21+
#ifdef LEGACY_SCRIPT_ENGINE_BACKEND_NODEJS
22+
23+
#define LLSE_BACKEND_NODEJS
24+
25+
#endif
26+
1527
///////////////////////// Configs /////////////////////////
1628

1729
// Plugins & Base libs path
@@ -20,7 +32,6 @@
2032

2133
// Plugin package information
2234
#define LLSE_PLUGIN_PACKAGE_EXTENSION ".llplugin"
23-
#define LLSE_PLUGIN_PACKAGE_TEMP_DIR "./plugins/LeviLamina/temp"
2435
#define LLSE_PLUGIN_PACKAGE_UNCOMPRESS_TIMEOUT 30000
2536

2637
// Current language information

0 commit comments

Comments
 (0)