From b482e19917395c842780bd2b8da7731158947c40 Mon Sep 17 00:00:00 2001 From: denis Date: Thu, 7 Sep 2017 03:44:37 +0300 Subject: src/lapi.js, src/lauxlib.js: lua_tointeger should return 0 when conversion fails for luaL_ref to work --- tests/lauxlib.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 tests/lauxlib.js (limited to 'tests/lauxlib.js') diff --git a/tests/lauxlib.js b/tests/lauxlib.js new file mode 100644 index 0000000..4e37296 --- /dev/null +++ b/tests/lauxlib.js @@ -0,0 +1,30 @@ +"use strict"; + +const test = require('tape'); + +global.WEB = false; + +const lua = require('../src/lua.js'); +const lauxlib = require("../src/lauxlib.js"); + +test('luaL_ref, lua_rawgeti, luaL_unref, LUA_REGISTRYINDEX', function (t) { + let L; + + t.plan(2); + + t.doesNotThrow(function () { + L = lauxlib.luaL_newstate(); + lua.lua_pushstring(L, lua.to_luastring("hello references!")); + + let r = lauxlib.luaL_ref(L, lua.LUA_REGISTRYINDEX); // pops a value, stores it and returns a reference + lua.lua_rawgeti(L, lua.LUA_REGISTRYINDEX, r); // pushes a value associated with the reference + lauxlib.luaL_unref(L, lua.LUA_REGISTRYINDEX, r); // releases the reference + + }, "JS Lua program ran without error"); + + t.strictEqual( + lua.lua_tojsstring(L, -1), + "hello references!", + "top is correct" + ); +}); -- cgit v1.2.3-54-g00ecf