From c3109ddad4bd60e3109774360fc2d80a6025c949 Mon Sep 17 00:00:00 2001 From: jianf <2198972886@qq.com> Date: Wed, 25 Mar 2026 14:52:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=B9=E9=BD=90c=E5=B1=82=E4=B8=8Ecj?= =?UTF-8?q?=E5=B1=82=E9=94=99=E8=AF=AF=E7=A0=81=EF=BC=8C=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A5=E9=85=8D=E5=90=88c=E5=B1=82?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/bridge.cj | 8 ++++---- src/lua_runner_test.cj | 28 ++++++++++++++++------------ 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/bridge.cj b/src/bridge.cj index cc7a16f..782d508 100644 --- a/src/bridge.cj +++ b/src/bridge.cj @@ -72,7 +72,7 @@ public class LuaError <: Exception { match (code) { case 5001 => "JSON file load failed" case 5002 => "Memory allocation failed" - case 5003 => "File load error (permission or path issue)" + case 5003 => "File load error (path, permission, or compile-time syntax issue)" case 5004 => "Script runner initialization failed" case 5005 => "Lua state machine initialization failed or corrupted" case 5006 => "JSON parse error (format issue)" @@ -91,7 +91,7 @@ public class LuaError <: Exception { case 5019 => "Reset input file failed, may cause input pollution" case 5020 => "Error in callback functions" case 5021 => "change workdir error" - case 5022 => "Calling func no found" + case 5022 => "No callable chunk found" case _ => "Unknown error" } } @@ -192,9 +192,9 @@ public class LuaRunner { /// 运行Lua脚本 /// /// @param path 脚本路径 - /// @param arg 传递给脚本的参数 + /// @param arg 传递给脚本的单参数;管道模式下由底层按栈布局自动计算调用参数数量 /// @return 脚本执行结果字符串 - /// @throws LuaError 当脚本运行出错时抛出 + /// @throws LuaError 当脚本编译或运行出错时抛出 public func runScript(path: String, arg: String): String { let pathPtr = toCStr(path) let argPtr = toCStr(arg) diff --git a/src/lua_runner_test.cj b/src/lua_runner_test.cj index 6c74176..771401e 100644 --- a/src/lua_runner_test.cj +++ b/src/lua_runner_test.cj @@ -1,21 +1,23 @@ package luarunner -import std.unittest.* -import std.fs.* +import std.unittest.* // cjlint-ignore G.PKG.01 +import std.fs.* // cjlint-ignore G.PKG.01 -let scriptsDir = "./test/scripts" -let generatedScriptsDir = "./test/generated_scripts" +// cjlint-ignore G.NAM.05 +let SCRIPTS_DIR = "./test/scripts" +// cjlint-ignore G.NAM.05 +let GENERATED_SCRIPTS_DIR = "./test/generated_scripts" func scriptPath(name: String): String { - scriptsDir + "/" + name + SCRIPTS_DIR + "/" + name } func generatedScriptPath(name: String): String { - generatedScriptsDir + "/" + name + GENERATED_SCRIPTS_DIR + "/" + name } func ensureGeneratedScriptsDir(): Unit { - let dir = Path(generatedScriptsDir) + let dir = Path(GENERATED_SCRIPTS_DIR) if (!exists(dir)) { Directory.create(dir, recursive: true) } @@ -53,7 +55,7 @@ func testRunScriptSyntaxError(): Unit { runner.runScript(path, "") fail("Should throw syntax error") } catch (e: LuaError) { - @Expect(e.code, 5010) + @Expect(e.code, 5003) } } @@ -203,16 +205,16 @@ func testLoadLibOverflow(): Unit { @Test func testPackagePathConfig(): Unit { - let runner = LuaRunner(pkgpath: scriptsDir + "/pkgmods/?.lua") + let runner = LuaRunner(pkgpath: SCRIPTS_DIR + "/pkgmods/?.lua") let res = runner.runScript(scriptPath("pkgpath_require_mylib.lua"), "") - @Expect(res, "LoadedViaPkgPath") + @Expect(res, SCRIPTS_DIR + "/pkgmods/mylib.lua") } @Test func testPackagePathInitLuaPattern(): Unit { - let runner = LuaRunner(pkgpath: scriptsDir + "/pkgmods_init/?/init.lua") + let runner = LuaRunner(pkgpath: SCRIPTS_DIR + "/pkgmods_init/?/init.lua") let res = runner.runScript(scriptPath("pkgpath_require_nested.lua"), "") - @Expect(res, "LoadedViaInit") + @Expect(res, SCRIPTS_DIR + "/pkgmods_init/nestedpkg/init.lua") } // ==================== @@ -259,7 +261,9 @@ func testRedirectIoRead(): Unit { func testErrorCodesMapping(): Unit { @Expect(LuaError.getErrorMessage(5001), "JSON file load failed") @Expect(LuaError.getErrorMessage(5002), "Memory allocation failed") + @Expect(LuaError.getErrorMessage(5003), "File load error (path, permission, or compile-time syntax issue)") @Expect(LuaError.getErrorMessage(5010), "Script internal error, check result for details") + @Expect(LuaError.getErrorMessage(5022), "No callable chunk found") @Expect(LuaError.getErrorMessage(9999), "Unknown error") }