aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-11-20 16:12:08 +1100
committerdaurnimator <quae@daurnimator.com>2017-11-20 16:12:08 +1100
commitaa1a44c84f11f97f6614b9c2fd252fddec4067eb (patch)
treee5790ca42c9f1d21d9b8f42d0422227056ba4a3f
parent0a8bc0b30644c514d822fb32a184318f7353a285 (diff)
downloadfengari-aa1a44c84f11f97f6614b9c2fd252fddec4067eb.tar.gz
fengari-aa1a44c84f11f97f6614b9c2fd252fddec4067eb.tar.bz2
fengari-aa1a44c84f11f97f6614b9c2fd252fddec4067eb.zip
src/lapi.js: chunkname can be null
-rw-r--r--src/lapi.js4
-rw-r--r--tests/lapi.js20
2 files changed, 22 insertions, 2 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 1be0837..be80672 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -912,9 +912,9 @@ const lua_arith = function(L, op) {
*/
const lua_load = function(L, reader, data, chunkname, mode) {
- assert(defs.is_luastring(chunkname), "lua_load expect an array of byte as chunkname");
- assert(mode ? defs.is_luastring(mode) : true, "lua_load expect an array of byte as mode");
if (!chunkname) chunkname = [defs.char["?"]];
+ else assert(defs.is_luastring(chunkname), "lua_load expect an array of byte as chunkname");
+ assert(mode ? defs.is_luastring(mode) : true, "lua_load expect an array of byte as mode");
let z = new lzio.ZIO(L, reader, data);
let status = ldo.luaD_protectedparser(L, z, chunkname, mode);
if (status === TS.LUA_OK) { /* no errors? */
diff --git a/tests/lapi.js b/tests/lapi.js
index 1dbdd5c..b764064 100644
--- a/tests/lapi.js
+++ b/tests/lapi.js
@@ -361,6 +361,26 @@ test('lua_pop', function (t) {
});
+test('lua_load with no chunkname', function (t) {
+ let L;
+
+ t.plan(2);
+
+ t.doesNotThrow(function () {
+ L = lauxlib.luaL_newstate();
+
+ lua.lua_load(L, function(L, s) { let r = s.code; s.code = null; return r; }, {code: lua.to_luastring("return 'hello'")}, null, null);
+
+ lua.lua_call(L, 0, 1);
+ }, "JS Lua program ran without error");
+
+ t.strictEqual(
+ lua.lua_tojsstring(L, -1),
+ "hello",
+ "Correct element(s) on the stack"
+ );
+});
+
test('lua_load and lua_call it', function (t) {
let luaCode = `
local a = "JS > Lua > JS \o/"