diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-03-01 11:51:00 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-03-01 11:51:00 +0100 |
commit | 444182dbbb18f44cf7cafc378f092c28006be365 (patch) | |
tree | a7d539ec3698c113c6cb68697bd3ec6f39b499e0 | |
parent | ae8b95ee9c3871f506b20c74367fdc9e8cb098e2 (diff) | |
download | fengari-444182dbbb18f44cf7cafc378f092c28006be365.tar.gz fengari-444182dbbb18f44cf7cafc378f092c28006be365.tar.bz2 fengari-444182dbbb18f44cf7cafc378f092c28006be365.zip |
Loading tests (binary/text)
-rw-r--r-- | src/lcode.js | 20 | ||||
-rw-r--r-- | src/lfunc.js | 4 | ||||
-rw-r--r-- | src/llex.js | 4 | ||||
-rw-r--r-- | src/lopcodes.js | 34 | ||||
-rw-r--r-- | src/lparser.js | 10 | ||||
-rw-r--r-- | src/lua.js | 8 | ||||
-rw-r--r-- | src/lualib.js | 25 | ||||
-rw-r--r-- | tests/lapi.js | 6 | ||||
-rw-r--r-- | tests/lbaselib.js | 34 | ||||
-rw-r--r-- | tests/lcorolib.js | 10 | ||||
-rw-r--r-- | tests/ldebug.js | 14 | ||||
-rw-r--r-- | tests/lexparse.js | 39 | ||||
-rw-r--r-- | tests/lmathlib.js | 26 | ||||
-rw-r--r-- | tests/load.js | 8 | ||||
-rw-r--r-- | tests/ltablib.js | 16 |
15 files changed, 157 insertions, 101 deletions
diff --git a/src/lcode.js b/src/lcode.js index 9b48d4d..d8b0252 100644 --- a/src/lcode.js +++ b/src/lcode.js @@ -10,7 +10,7 @@ const lparser = require('./lparser.js'); const ltm = require('./ltm.js'); const lua = require('./lua.js'); const lvm = require('./lvm.js'); -const CT = lua.constants_type; +const CT = lua.CT; const OpCodesI = lopcode.OpCodesI; const TValue = lobject.TValue; @@ -483,7 +483,7 @@ const freeexps = function(fs, e1, e2) { const addk = function(fs, key, v) { let f = fs.f; let idx = fs.ls.h.__index(fs.ls.h, key); /* index scanner table */ - if (idx) { /* is there an index there? */ + if (idx && !idx.ttisnil()) { /* is there an index there? */ /* correct value? (warning: must distinguish floats from integers!) */ if (f.k[idx].ttype() === v.ttype() && f.k[idx].value === v.value) return idx; /* reuse index */ @@ -500,8 +500,7 @@ const addk = function(fs, key, v) { ** Add a string to list of constants and return its index. */ const luaK_stringK = function(fs, s) { - let o = new TValue(CT.LUA_TLNGSTR, s); - return addk(fs, o, o); /* use string itself as key */ + return addk(fs, s, s); /* use string itself as key */ }; @@ -512,8 +511,8 @@ const luaK_stringK = function(fs, s) { ** are no "precision" problems. */ const luaK_intK = function(fs, n) { - let k = new TValue(CT.LUA_TLNGSTR, `n`); - let o = new TValue(CT.LUA_TNUMINT, n); + let k = new TValue(CT.LUA_TLNGSTR, `${n.value}`); + let o = new TValue(CT.LUA_TNUMINT, n.value); return addk(fs, k, o); }; @@ -521,8 +520,7 @@ const luaK_intK = function(fs, n) { ** Add a float to list of constants and return its index. */ const luaK_numberK = function(fs, r) { - let o = new TValue(CT.LUA_TNUMFLT, r); - return addk(fs, o, o); /* use number itself as key */ + return addk(fs, r, r); /* use number itself as key */ }; @@ -530,8 +528,7 @@ const luaK_numberK = function(fs, r) { ** Add a boolean to list of constants and return its index. */ const boolK = function(fs, b) { - let o = new TValue(CT.LUA_TBOOLEAN, b); - return addk(fs, o, o); /* use boolean itself as key */ + return addk(fs, b, b); /* use boolean itself as key */ }; @@ -539,8 +536,7 @@ const boolK = function(fs, b) { ** Add nil to list of constants and return its index. */ const nilK = function(fs) { - let o = new TValue(CT.LUA_TNIL, null); - return addk(fs, o, o); + return addk(fs, new TValue(CT.LUA_TLNGSTR, `null`), new TValue(CT.LUA_TNIL, null)); }; /* diff --git a/src/lfunc.js b/src/lfunc.js index 37239b2..227606d 100644 --- a/src/lfunc.js +++ b/src/lfunc.js @@ -102,12 +102,16 @@ const luaF_close = function(L, level) { } }; +/* +** fill a closure with new closed upvalues +*/ const luaF_initupvals = function(L, cl) { for (let i = 0; i < cl.nupvalues; i++) { let uv = new UpVal(L); uv.refcount = 1; uv.u.value = null; uv.v = uv.u.value; + cl.upvals[i] = uv; } }; diff --git a/src/llex.js b/src/llex.js index 73cda58..63a1fbb 100644 --- a/src/llex.js +++ b/src/llex.js @@ -453,7 +453,7 @@ const read_string = function(ls, del, seminfo) { } } save_and_next(ls); /* skip delimiter */ - seminfo.ts = new TValue(CT.LUA_TLNGSTR, ls.buff.buffer.slice(1).join('')); + seminfo.ts = new TValue(CT.LUA_TLNGSTR, ls.buff.buffer.slice(1, ls.buff.buffer.length-1).join('')); }; const isreserved = function(w) { @@ -566,7 +566,7 @@ const llex = function(ls, seminfo) { let ts = new TValue(CT.LUA_TLNGSTR, ls.buff.buffer.join('')); seminfo.ts = ts; - let kidx = luaX_tokens.slice(0, 22).indexOf(ts.value) + let kidx = luaX_tokens.slice(0, 22).indexOf(ts.value); if (kidx >= 0) /* reserved word? */ return kidx + FIRST_RESERVED; else diff --git a/src/lopcodes.js b/src/lopcodes.js index 3f7f63b..bfcd993 100644 --- a/src/lopcodes.js +++ b/src/lopcodes.js @@ -209,6 +209,7 @@ const MAXARG_A = ((1 << SIZE_A) - 1); const MAXARG_B = ((1 << SIZE_B) - 1); const MAXARG_C = ((1 << SIZE_C) - 1); +/* this bit 1 means constant (0 means register) */ const BITRK = (1 << (SIZE_B - 1)); /* @@ -216,14 +217,22 @@ const BITRK = (1 << (SIZE_B - 1)); */ const NO_REG = MAXARG_A; +/* test whether value is a constant */ const ISK = function (x) { return x & BITRK; }; +/* gets the index of the constant */ const INDEXK = function (r) { return r & ~BITRK; }; +/* code a constant index as a RK value */ +const RKASK = function(x) { + return x | BITRK; +}; + + /* creates a mask with 'n' 1 bits at position 'p' */ const MASK1 = function(n, p) { return ((~((~0)<<(n)))<<(p)); @@ -267,7 +276,7 @@ const SETARG_sBx = function(i, b) { ** Pre-calculate all possible part of the instruction */ const fullins = function(ins) { - if (typeof ins === "integer") { + if (typeof ins === "number") { return { code: ins, opcode: (ins >> POS_OP) & MASK1(SIZE_OP, 0), @@ -280,13 +289,13 @@ const fullins = function(ins) { }; } else { let i = ins.code; - ins.opcode = (i >> POS_OP) & MASK1(SIZE_OP, 0), - ins.A = (i >> POS_A) & MASK1(SIZE_A, 0), - ins.B = (i >> POS_B) & MASK1(SIZE_B, 0), - ins.C = (i >> POS_C) & MASK1(SIZE_C, 0), - ins.Bx = (i >> POS_Bx) & MASK1(SIZE_Bx, 0), - ins.Ax = (i >> POS_Ax) & MASK1(SIZE_Ax, 0), - ins.sBx = ((i >> POS_Bx) & MASK1(SIZE_Bx, 0)) - MAXARG_sBx + ins.opcode = (i >> POS_OP) & MASK1(SIZE_OP, 0); + ins.A = (i >> POS_A) & MASK1(SIZE_A, 0); + ins.B = (i >> POS_B) & MASK1(SIZE_B, 0); + ins.C = (i >> POS_C) & MASK1(SIZE_C, 0); + ins.Bx = (i >> POS_Bx) & MASK1(SIZE_Bx, 0); + ins.Ax = (i >> POS_Ax) & MASK1(SIZE_Ax, 0); + ins.sBx = ((i >> POS_Bx) & MASK1(SIZE_Bx, 0)) - MAXARG_sBx; return ins; } }; @@ -320,6 +329,10 @@ module.exports.MAXARG_Bx = MAXARG_Bx; module.exports.MAXARG_C = MAXARG_C; module.exports.MAXARG_sBx = MAXARG_sBx; module.exports.NO_REG = NO_REG; +module.exports.OpArgK = OpArgK; +module.exports.OpArgN = OpArgN; +module.exports.OpArgR = OpArgR; +module.exports.OpArgU = OpArgU; module.exports.OpCodes = OpCodes; module.exports.OpCodesI = OpCodesI; module.exports.POS_A = POS_A; @@ -328,6 +341,7 @@ module.exports.POS_B = POS_B; module.exports.POS_Bx = POS_Bx; module.exports.POS_C = POS_C; module.exports.POS_OP = POS_OP; +module.exports.RKASK = RKASK; module.exports.SETARG_A = SETARG_A; module.exports.SETARG_Ax = SETARG_Ax; module.exports.SETARG_B = SETARG_B; @@ -344,5 +358,9 @@ module.exports.fullins = fullins; module.exports.getBMode = getBMode; module.exports.getCMode = getCMode; module.exports.getOpMode = getOpMode; +module.exports.iABC = iABC; +module.exports.iABx = iABx; +module.exports.iAsBx = iAsBx; +module.exports.iAx = iAx; module.exports.testAMode = testAMode; module.exports.testTMode = testTMode;
\ No newline at end of file diff --git a/src/lparser.js b/src/lparser.js index 40d6c88..aa48f10 100644 --- a/src/lparser.js +++ b/src/lparser.js @@ -10,7 +10,6 @@ const lobject = require('./lobject.js'); const lopcode = require('./lopcodes.js'); const lua = require('./lua.js'); const BinOpr = lcode.BinOpr; -const CT = lua.constants_type; const OpCodesI = lopcode.OpCodesI; const Proto = lfunc.Proto; const R = llex.RESERVED; @@ -239,7 +238,7 @@ const new_localvar = function(ls, name) { }; const new_localvarliteral = function(ls, name) { - new_localvar(ls, new TValue(CT.LUA_TLNGSTR, name)); + new_localvar(ls, new TValue(lua.CT.LUA_TLNGSTR, name)); }; const getlocvar = function(fs, i) { @@ -469,7 +468,7 @@ const enterblock = function(fs, bl, isloop) { ** create a label named 'break' to resolve break statements */ const breaklabel = function(ls) { - let n = new TValue(CT.LUA_TLNGSTR, "break"); + let n = new TValue(lua.CT.LUA_TLNGSTR, "break"); let l = newlabelentry(ls, ls.dyd.label, n, 0, ls.fs.pc); findgotos(ls, ls.dyd.label.arr[l]); }; @@ -507,7 +506,6 @@ const codeclosure = function(ls, v) { }; const open_func = function(ls, fs, bl) { - this.f = new Proto(); fs.prev = ls.fs; /* linked list of funcstates */ fs.ls = ls; ls.fs = fs; @@ -1132,7 +1130,7 @@ const gotostat = function(ls, pc) { label = str_checkname(ls); else { llex.luaX_next(ls); /* skip break */ - label = new TValue(CT.LUA_TLNGSTR, "break"); + label = new TValue(lua.CT.LUA_TLNGSTR, "break"); } let g = newlabelentry(ls, ls.dyd.gt, label, line, pc); findlabel(ls, g); /* close it if label already defined */ @@ -1538,7 +1536,7 @@ const luaY_parser = function(L, z, buff, dyd, name, firstchar) { lexstate.h = new Table(); /* create table for scanner */ L.stack[L.top++] = lexstate.h; funcstate.f = cl.p = new Proto(L); - funcstate.f.source = new TValue(CT.LUA_TLNGSTR, name); + funcstate.f.source = new TValue(lua.CT.LUA_TLNGSTR, name); lexstate.buff = buff; lexstate.dyd = dyd; dyd.actvar.n = dyd.gt.n = dyd.label.n = 0; @@ -28,8 +28,10 @@ const FENGARI_RELEASE = FENGARI_VERSION + "." + FENGARI_VERSION_RELEASE; const FENGARI_COPYRIGHT = FENGARI_RELEASE + " Copyright (C) 2017 BenoƮt Giannangeli\nBased on: " + LUA_COPYRIGHT; const FENGARI_AUTHORS = "B. Giannangeli"; +const LUA_VERSUFFIX = "_" + LUA_VERSION_MAJOR + "_" + LUA_VERSION_MINOR; + const LUA_INIT_VAR = "LUA_INIT"; -const LUA_INITVARVERSION = LUA_INIT_VAR + lualib.LUA_VERSUFFIX; +const LUA_INITVARVERSION = LUA_INIT_VAR + LUA_VERSUFFIX; const thread_status = { LUA_OK: 0, @@ -55,6 +57,8 @@ const constant_types = { LUA_NUMTAGS: 9 }; +const CT = constant_types; + constant_types.LUA_TSHRSTR = constant_types.LUA_TSTRING | (0 << 4); /* short strings */ constant_types.LUA_TLNGSTR = constant_types.LUA_TSTRING | (1 << 4); /* long strings */ @@ -128,6 +132,7 @@ class lua_Debug { } +module.exports.CT = CT; module.exports.FENGARI_AUTHORS = FENGARI_AUTHORS; module.exports.FENGARI_COPYRIGHT = FENGARI_COPYRIGHT; module.exports.FENGARI_RELEASE = FENGARI_RELEASE; @@ -171,6 +176,7 @@ module.exports.LUA_VERSION_MAJOR = LUA_VERSION_MAJOR; module.exports.LUA_VERSION_MINOR = LUA_VERSION_MINOR; module.exports.LUA_VERSION_NUM = LUA_VERSION_NUM; module.exports.LUA_VERSION_RELEASE = LUA_VERSION_RELEASE; +module.exports.LUA_VERSUFFIX = LUA_VERSUFFIX; module.exports.constant_types = constant_types; module.exports.lua_Debug = lua_Debug; module.exports.lua_upvalueindex = lua_upvalueindex; diff --git a/src/lualib.js b/src/lualib.js index d87cfbc..da9b290 100644 --- a/src/lualib.js +++ b/src/lualib.js @@ -2,21 +2,17 @@ "use strict"; const assert = require('assert'); -const lua = require('./lua.js'); - - -const LUA_VERSUFFIX = "_" + lua.LUA_VERSION_MAJOR + "_" + lua.LUA_VERSION_MINOR; const LUA_COLIBNAME = "coroutine"; -const LUA_TABLIBNAME = "table" -const LUA_IOLIBNAME = "io" -const LUA_OSLIBNAME = "os" -const LUA_STRLIBNAME = "string" -const LUA_UTF8LIBNAME = "utf8" -const LUA_BITLIBNAME = "bit32" -const LUA_MATHLIBNAME = "math" -const LUA_DBLIBNAME = "debug" -const LUA_LOADLIBNAME = "package" +const LUA_TABLIBNAME = "table"; +const LUA_IOLIBNAME = "io"; +const LUA_OSLIBNAME = "os"; +const LUA_STRLIBNAME = "string"; +const LUA_UTF8LIBNAME = "utf8"; +const LUA_BITLIBNAME = "bit32"; +const LUA_MATHLIBNAME = "math"; +const LUA_DBLIBNAME = "debug"; +const LUA_LOADLIBNAME = "package"; module.exports.LUA_BITLIBNAME = LUA_BITLIBNAME; @@ -28,5 +24,4 @@ module.exports.LUA_MATHLIBNAME = LUA_MATHLIBNAME; module.exports.LUA_OSLIBNAME = LUA_OSLIBNAME; module.exports.LUA_STRLIBNAME = LUA_STRLIBNAME; module.exports.LUA_TABLIBNAME = LUA_TABLIBNAME; -module.exports.LUA_UTF8LIBNAME = LUA_UTF8LIBNAME; -module.exports.LUA_VERSUFFIX = LUA_VERSUFFIX;
\ No newline at end of file +module.exports.LUA_UTF8LIBNAME = LUA_UTF8LIBNAME;
\ No newline at end of file diff --git a/tests/lapi.js b/tests/lapi.js index 6761425..c422ada 100644 --- a/tests/lapi.js +++ b/tests/lapi.js @@ -329,7 +329,7 @@ test('lua_pcall that breaks', function (t) { t.doesNotThrow(function () { let fn = function(L) { - return undefined_value; + return "undefined_value"; }; L = lauxlib.luaL_newstate(); @@ -382,7 +382,7 @@ test('lua_load and lua_call it', function (t) { L = lauxlib.luaL_newstate(); - lapi.lua_load(L, bc, "test-lua_load") + lapi.lua_load(L, null, bc, "test-lua_load", "binary"); lapi.lua_call(L, 0, 1); @@ -409,7 +409,7 @@ test('lua script reads js upvalues', function (t) { L = lauxlib.luaL_newstate(); - lapi.lua_load(L, bc, "test-lua_load") + lapi.lua_load(L, null, bc, "test-lua_load", "binary"); lapi.lua_pushstring(L, "hello"); lapi.lua_setglobal(L, "js"); diff --git a/tests/lbaselib.js b/tests/lbaselib.js index 72a2f15..be741dc 100644 --- a/tests/lbaselib.js +++ b/tests/lbaselib.js @@ -31,7 +31,7 @@ test('print', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-print"); + lapi.lua_load(L, null, bc, "test-print", "binary"); lapi.lua_call(L, 0, -1); @@ -65,7 +65,7 @@ test('setmetatable, getmetatable', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-setmetatable-getmetatable"); + lapi.lua_load(L, null, bc, "test-setmetatable-getmetatable", "binary"); lapi.lua_call(L, 0, -1); @@ -110,7 +110,7 @@ test('rawequal', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-rawequal"); + lapi.lua_load(L, null, bc, "test-rawequal", "binary"); lapi.lua_call(L, 0, -1); @@ -156,7 +156,7 @@ test('rawset, rawget', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-rawequal"); + lapi.lua_load(L, null, bc, "test-rawequal", "binary"); lapi.lua_call(L, 0, -1); @@ -203,7 +203,7 @@ test('type', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-type"); + lapi.lua_load(L, null, bc, "test-type", "binary"); lapi.lua_call(L, 0, -1); @@ -256,7 +256,7 @@ test('error', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-error"); + lapi.lua_load(L, null, bc, "test-error", "binary"); lapi.lua_call(L, 0, -1); @@ -279,7 +279,7 @@ test('error, protected', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-error"); + lapi.lua_load(L, null, bc, "test-error", "binary"); lapi.lua_pcall(L, 0, -1, 0); @@ -311,7 +311,7 @@ test('pcall', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-pcall"); + lapi.lua_load(L, null, bc, "test-pcall", "binary"); lapi.lua_call(L, 0, -1); @@ -347,7 +347,7 @@ test('xpcall', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-pcall"); + lapi.lua_load(L, null, bc, "test-pcall", "binary"); lapi.lua_call(L, 0, -1); @@ -389,7 +389,7 @@ test('ipairs', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-ipairs"); + lapi.lua_load(L, null, bc, "test-ipairs", "binary"); lapi.lua_call(L, 0, -1); @@ -418,7 +418,7 @@ test('select', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-select"); + lapi.lua_load(L, null, bc, "test-select", "binary"); lapi.lua_call(L, 0, -1); @@ -459,7 +459,7 @@ test('tonumber', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-tonumber"); + lapi.lua_load(L, null, bc, "test-tonumber", "binary"); lapi.lua_call(L, 0, -1); @@ -506,7 +506,7 @@ test('assert', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-assert"); + lapi.lua_load(L, null, bc, "test-assert", "binary"); lapi.lua_pcall(L, 0, -1, 0); @@ -534,7 +534,7 @@ test('rawlen', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-rawlen"); + lapi.lua_load(L, null, bc, "test-rawlen", "binary"); lapi.lua_call(L, 0, -1); @@ -581,7 +581,7 @@ test('next', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-next"); + lapi.lua_load(L, null, bc, "test-next", "binary"); lapi.lua_call(L, 0, -1); @@ -622,7 +622,7 @@ test('pairs', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-pairs"); + lapi.lua_load(L, null, bc, "test-pairs", "binary"); lapi.lua_call(L, 0, -1); @@ -672,7 +672,7 @@ test('pairs with __pairs', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-pairs"); + lapi.lua_load(L, null, bc, "test-pairs", "binary"); lapi.lua_call(L, 0, -1); diff --git a/tests/lcorolib.js b/tests/lcorolib.js index 022cda6..9c1d9b1 100644 --- a/tests/lcorolib.js +++ b/tests/lcorolib.js @@ -40,7 +40,7 @@ test('coroutine.create, coroutine.yield, coroutine.resume', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-coroutine"); + lapi.lua_load(L, null, bc, "test-coroutine", "binary"); lapi.lua_call(L, 0, -1); @@ -83,7 +83,7 @@ test('coroutine.status', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-coroutine.status"); + lapi.lua_load(L, null, bc, "test-coroutine.status", "binary"); lapi.lua_call(L, 0, -1); @@ -124,7 +124,7 @@ test('coroutine.isyieldable', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-coroutine.isyieldable"); + lapi.lua_load(L, null, bc, "test-coroutine.isyieldable", "binary"); lapi.lua_call(L, 0, -1); @@ -165,7 +165,7 @@ test('coroutine.running', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-coroutine.running"); + lapi.lua_load(L, null, bc, "test-coroutine.running", "binary"); lapi.lua_call(L, 0, -1); @@ -206,7 +206,7 @@ test('coroutine.wrap', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-coroutine.wrap"); + lapi.lua_load(L, null, bc, "test-coroutine.wrap", "binary"); lapi.lua_call(L, 0, -1); diff --git a/tests/ldebug.js b/tests/ldebug.js index 45194e9..472c66b 100644 --- a/tests/ldebug.js +++ b/tests/ldebug.js @@ -30,7 +30,7 @@ test('luaG_typeerror', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-typeerror"); + lapi.lua_load(L, null, bc, "test-typeerror", "binary"); lapi.lua_pcall(L, 0, -1, 0); @@ -60,7 +60,7 @@ test('luaG_typeerror', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-typeerror"); + lapi.lua_load(L, null, bc, "test-typeerror", "binary"); lapi.lua_pcall(L, 0, -1, 0); @@ -89,7 +89,7 @@ test('luaG_typeerror', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-typeerror"); + lapi.lua_load(L, null, bc, "test-typeerror", "binary"); lapi.lua_pcall(L, 0, -1, 0); @@ -118,7 +118,7 @@ test('luaG_typeerror', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-typeerror"); + lapi.lua_load(L, null, bc, "test-typeerror", "binary"); lapi.lua_pcall(L, 0, -1, 0); @@ -146,7 +146,7 @@ test('luaG_concaterror', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-typeerror"); + lapi.lua_load(L, null, bc, "test-typeerror", "binary"); lapi.lua_pcall(L, 0, -1, 0); @@ -174,7 +174,7 @@ test('luaG_opinterror', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-typeerror"); + lapi.lua_load(L, null, bc, "test-typeerror", "binary"); lapi.lua_pcall(L, 0, -1, 0); @@ -202,7 +202,7 @@ test('luaG_tointerror', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-typeerror"); + lapi.lua_load(L, null, bc, "test-typeerror", "binary"); lapi.lua_pcall(L, 0, -1, 0); diff --git a/tests/lexparse.js b/tests/lexparse.js new file mode 100644 index 0000000..8320588 --- /dev/null +++ b/tests/lexparse.js @@ -0,0 +1,39 @@ +"use strict"; + +const test = require('tape'); +const beautify = require('js-beautify').js_beautify; + +const tests = require("./tests.js"); +const toByteCode = tests.toByteCode; + +const lapi = require("../src/lapi.js"); +const lauxlib = require("../src/lauxlib.js"); +const linit = require('../src/linit.js'); + + +test('Hello World', function (t) { + let luaCode = ` + return "hello world" + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, null, luaCode, "test-load", "text"); + + lapi.lua_call(L, 0, -1); + + }, "JS Lua program ran without error"); + + t.strictEqual( + lapi.lua_tostring(L, -1), + "hello world", + "Correct element(s) on the stack" + ); + +});
\ No newline at end of file diff --git a/tests/lmathlib.js b/tests/lmathlib.js index 48ae1a2..ae0c40b 100644 --- a/tests/lmathlib.js +++ b/tests/lmathlib.js @@ -33,7 +33,7 @@ test('math.abs, math.sin, math.cos, math.tan, math.asin, math.acos, math.atan', linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); @@ -98,7 +98,7 @@ test('math.ceil, math.floor', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); @@ -134,7 +134,7 @@ test('math.deg, math.rad', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); @@ -170,7 +170,7 @@ test('math.log', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); @@ -212,7 +212,7 @@ test('math.exp', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); @@ -242,7 +242,7 @@ test('math.min, math.max', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); @@ -278,7 +278,7 @@ test('math.random', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); @@ -312,7 +312,7 @@ test('math.sqrt', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); @@ -342,7 +342,7 @@ test('math.tointeger', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); @@ -372,7 +372,7 @@ test('math.type', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); @@ -414,7 +414,7 @@ test('math.ult', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); @@ -444,7 +444,7 @@ test('math.fmod', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); @@ -474,7 +474,7 @@ test('math.modf', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-math"); + lapi.lua_load(L, null, bc, "test-math", "binary"); lapi.lua_call(L, 0, -1); diff --git a/tests/load.js b/tests/load.js index 4df3f6a..a71de6b 100644 --- a/tests/load.js +++ b/tests/load.js @@ -25,7 +25,7 @@ test('lua_load, binary mode', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, null, bc, "test-math", "binary"); + lapi.lua_load(L, null, bc, "test-load", "binary"); lapi.lua_call(L, 0, -1); @@ -47,17 +47,17 @@ test('lua_load, text mode', function (t) { t.plan(2); - // t.doesNotThrow(function () { + t.doesNotThrow(function () { L = lauxlib.luaL_newstate(); linit.luaL_openlibs(L); - lapi.lua_load(L, null, luaCode, "test-math", "text"); + lapi.lua_load(L, null, luaCode, "test-load", "text"); lapi.lua_call(L, 0, -1); - // }, "JS Lua program ran without error"); + }, "JS Lua program ran without error"); t.strictEqual( lapi.lua_tostring(L, -1), diff --git a/tests/ltablib.js b/tests/ltablib.js index 2ebf98c..c8a1e73 100644 --- a/tests/ltablib.js +++ b/tests/ltablib.js @@ -42,7 +42,7 @@ test('table.concat', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-table.concat"); + lapi.lua_load(L, null, bc, "test-table.concat", "binary"); lapi.lua_call(L, 0, -1); @@ -71,7 +71,7 @@ test('table.pack', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-table.pack"); + lapi.lua_load(L, null, bc, "test-table.pack", "binary"); lapi.lua_call(L, 0, -1); @@ -102,7 +102,7 @@ test('table.unpack', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-table.unpack"); + lapi.lua_load(L, null, bc, "test-table.unpack", "binary"); lapi.lua_call(L, 0, -1); @@ -146,7 +146,7 @@ test('table.insert', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-table.insert"); + lapi.lua_load(L, null, bc, "test-table.insert", "binary"); lapi.lua_call(L, 0, -1); @@ -180,7 +180,7 @@ test('table.remove', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-table.remove"); + lapi.lua_load(L, null, bc, "test-table.remove", "binary"); lapi.lua_call(L, 0, -1); @@ -213,7 +213,7 @@ test('table.move', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-table.move"); + lapi.lua_load(L, null, bc, "test-table.move", "binary"); lapi.lua_call(L, 0, -1); @@ -246,7 +246,7 @@ test('table.sort (<)', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-table.sort"); + lapi.lua_load(L, null, bc, "test-table.sort", "binary"); lapi.lua_call(L, 0, -1); @@ -279,7 +279,7 @@ test('table.sort with cmp function', function (t) { linit.luaL_openlibs(L); - lapi.lua_load(L, bc, "test-table.sort"); + lapi.lua_load(L, null, bc, "test-table.sort", "binary"); lapi.lua_call(L, 0, -1); |