From 27de87bca51c4353a2a726afc20a38b36442e31e Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Thu, 11 May 2017 09:38:36 +0200 Subject: ltests.js --- tests/test-suite/ltests.js | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/test-suite/ltests.js diff --git a/tests/test-suite/ltests.js b/tests/test-suite/ltests.js new file mode 100644 index 0000000..b4b575b --- /dev/null +++ b/tests/test-suite/ltests.js @@ -0,0 +1,34 @@ +"use strict"; + +global.WEB = false; + +const lua = require('../../src/lua.js'); +const lauxlib = require('../../src/lauxlib.js'); + + +const tpanic = function(L) { + console.error(`PANIC: unprotected error in call to Lua API (${lua.lua_tojsstring(L, -1)})\n`); + return process.exit(1); /* do not return to Lua */ +}; + +const newuserdata = function(L) { + lua.lua_newuserdata(L, lauxlib.luaL_checkinteger(L, 1)); + return 1; +}; + +const tests_funcs = { + "newuserdata": newuserdata +}; + +const luaB_opentests = function(L) { + lua.lua_atpanic(L, tpanic); + lauxlib.luaL_newlib(L, tests_funcs); + return 1; +}; + +const luaopen_tests = function(L) { + lauxlib.luaL_requiref(L, lua.to_luastring("T"), luaB_opentests, 1); + lua.lua_pop(L, 1); /* remove lib */ +}; + +module.exports.luaopen_tests = luaopen_tests; -- cgit v1.2.3-70-g09d2