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") }