diff --git a/cli/luanode.js b/cli/luanode.js index 267c7be..6036e85 100755 --- a/cli/luanode.js +++ b/cli/luanode.js @@ -59,7 +59,7 @@ function runString(code, chunkName) { } lualib.luaL_openlibs(L); - const status = lauxlib.luaL_loadbuffer(L, to_luastring(code), to_luastring(chunkName)); + const status = lauxlib.luaL_loadbuffer(L, to_luastring(code), to_luastring(code).length, to_luastring(chunkName)); if (status !== lua.LUA_OK) { const msg = safeToJsString(lua.lua_tostring(L, -1)); process.stderr.write("luanode: " + msg + "\n"); diff --git a/tests/cli.test.js b/tests/cli.test.js index 686720d..8f73c8f 100644 --- a/tests/cli.test.js +++ b/tests/cli.test.js @@ -49,4 +49,18 @@ describe("LuaNode-VM CLI", () => { fs.rmSync(dir, { recursive: true, force: true }); } }); + test("executes inline code and reports its chunk name", () => { + const cli = path.join(__dirname, "..", "cli", "luanode.js"); + + const success = spawnSync(process.execPath, [cli, "-e", "print('inline-ok')"], { encoding: "utf8" }); + expect(success.status).toBe(0); + expect(success.stderr).toBe(""); + expect(success.stdout.trim()).toBe("inline-ok"); + + const syntaxError = spawnSync(process.execPath, [cli, "-e", "this is not valid"], { encoding: "utf8" }); + expect(syntaxError.status).toBe(1); + expect(syntaxError.stdout).toBe(""); + expect(syntaxError.stderr).toContain("(command line):1:"); + }); + });