From f7e5203a20ef41cf9bc59d339b4f85007a7f3764 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 15 May 2017 17:20:06 +1000 Subject: Separate ZIO and MBuffer data structures - lua_load no longer takes a null reader function --- tests/lapi.js | 6 ++--- tests/lbaselib.js | 71 +++++++++++++------------------------------------------ tests/lcorolib.js | 23 ++++-------------- tests/ldebug.js | 31 ++++++------------------ tests/lmathlib.js | 55 ++++++++++-------------------------------- tests/lstrlib.js | 2 +- tests/ltablib.js | 35 +++++++-------------------- tests/ltm.js | 71 +++++++++++++------------------------------------------ 8 files changed, 70 insertions(+), 224 deletions(-) (limited to 'tests') diff --git a/tests/lapi.js b/tests/lapi.js index 8b269b1..b739860 100644 --- a/tests/lapi.js +++ b/tests/lapi.js @@ -375,7 +375,7 @@ test('lua_load and lua_call it', function (t) { L = lauxlib.luaL_newstate(); - lua.lua_load(L, null, bc, lua.to_luastring("test-lua_load"), lua.to_luastring("binary")); + lua.lua_load(L, function(L, s) { let r = s.bc; s.bc = null; return r; }, {bc: bc}, lua.to_luastring("test-lua_load"), lua.to_luastring("binary")); lua.lua_call(L, 0, 1); @@ -398,11 +398,9 @@ test('lua script reads js upvalues', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); - lua.lua_load(L, null, bc, lua.to_luastring("test-lua_load"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_pushliteral(L, "hello"); lua.lua_setglobal(L, lua.to_luastring("js")); diff --git a/tests/lbaselib.js b/tests/lbaselib.js index bfaac9c..2594cd9 100644 --- a/tests/lbaselib.js +++ b/tests/lbaselib.js @@ -2,9 +2,6 @@ const test = require('tape'); -const tests = require("./tests.js"); -const toByteCode = tests.toByteCode; - const lua = require('../src/lua.js'); const lauxlib = require('../src/lauxlib.js'); const lualib = require('../src/lualib.js'); @@ -19,13 +16,11 @@ test('print', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-print"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -53,13 +48,11 @@ test('setmetatable, getmetatable', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-setmetatable-getmetatable"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -98,13 +91,11 @@ test('rawequal', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-rawequal"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -144,13 +135,11 @@ test('rawset, rawget', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-rawequal"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -191,13 +180,11 @@ test('type', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-type"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -244,13 +231,11 @@ test('error', function (t) { t.throws(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-error"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -267,13 +252,11 @@ test('error, protected', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-error"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_pcall(L, 0, -1, 0); @@ -299,13 +282,11 @@ test('pcall', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-pcall"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -335,13 +316,11 @@ test('xpcall', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-pcall"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -377,13 +356,11 @@ test('ipairs', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-ipairs"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -406,13 +383,11 @@ test('select', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-select"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -451,13 +426,11 @@ test('tonumber', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-tonumber"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -503,13 +476,11 @@ test('assert', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-assert"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_pcall(L, 0, -1, 0); @@ -531,13 +502,11 @@ test('rawlen', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-rawlen"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -578,13 +547,11 @@ test('next', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-next"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -619,13 +586,11 @@ test('pairs', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-pairs"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -669,13 +634,11 @@ test('pairs with __pairs', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-pairs"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); diff --git a/tests/lcorolib.js b/tests/lcorolib.js index 342b560..4faf13b 100644 --- a/tests/lcorolib.js +++ b/tests/lcorolib.js @@ -2,9 +2,6 @@ const test = require('tape'); -const tests = require("./tests.js"); -const toByteCode = tests.toByteCode; - const lua = require('../src/lua.js'); const lauxlib = require('../src/lauxlib.js'); const lualib = require('../src/lualib.js'); @@ -28,13 +25,11 @@ test('coroutine.create, coroutine.yield, coroutine.resume', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-coroutine"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -71,13 +66,11 @@ test('coroutine.status', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-coroutine.status"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -112,13 +105,11 @@ test('coroutine.isyieldable', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-coroutine.isyieldable"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -153,13 +144,11 @@ test('coroutine.running', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-coroutine.running"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -194,13 +183,11 @@ test('coroutine.wrap', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-coroutine.wrap"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); diff --git a/tests/ldebug.js b/tests/ldebug.js index 99e37d9..8809bde 100644 --- a/tests/ldebug.js +++ b/tests/ldebug.js @@ -2,9 +2,6 @@ const test = require('tape'); -const tests = require("./tests.js"); -const toByteCode = tests.toByteCode; - const lua = require('../src/lua.js'); const lauxlib = require('../src/lauxlib.js'); const lualib = require('../src/lualib.js'); @@ -19,13 +16,11 @@ test('luaG_typeerror', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_pcall(L, 0, -1, 0); @@ -49,13 +44,11 @@ test('luaG_typeerror', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_pcall(L, 0, -1, 0); @@ -78,13 +71,11 @@ test('luaG_typeerror', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_pcall(L, 0, -1, 0); @@ -107,13 +98,11 @@ test('luaG_typeerror', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_pcall(L, 0, -1, 0); @@ -135,13 +124,11 @@ test('luaG_concaterror', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_pcall(L, 0, -1, 0); @@ -163,13 +150,11 @@ test('luaG_opinterror', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_pcall(L, 0, -1, 0); @@ -191,13 +176,11 @@ test('luaG_tointerror', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-typeerror"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_pcall(L, 0, -1, 0); diff --git a/tests/lmathlib.js b/tests/lmathlib.js index 8fcd9a8..b227af0 100644 --- a/tests/lmathlib.js +++ b/tests/lmathlib.js @@ -2,9 +2,6 @@ const test = require('tape'); -const tests = require("./tests.js"); -const toByteCode = tests.toByteCode; - const lua = require('../src/lua.js'); const lauxlib = require('../src/lauxlib.js'); const lualib = require('../src/lualib.js'); @@ -20,13 +17,11 @@ test('math.abs, math.sin, math.cos, math.tan, math.asin, math.acos, math.atan', t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -85,13 +80,11 @@ test('math.ceil, math.floor', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -121,13 +114,11 @@ test('math.deg, math.rad', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -157,13 +148,11 @@ test('math.log', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -199,13 +188,11 @@ test('math.exp', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -229,13 +216,11 @@ test('math.min, math.max', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -265,13 +250,11 @@ test('math.random', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -299,13 +282,11 @@ test('math.sqrt', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -329,13 +310,11 @@ test('math.tointeger', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -359,13 +338,11 @@ test('math.type', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -401,13 +378,11 @@ test('math.ult', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -431,13 +406,11 @@ test('math.fmod', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -461,13 +434,11 @@ test('math.modf', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-math"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); diff --git a/tests/lstrlib.js b/tests/lstrlib.js index dbd27d9..817ebcb 100644 --- a/tests/lstrlib.js +++ b/tests/lstrlib.js @@ -444,7 +444,7 @@ test('string.dump', function (t) { let dv = lua.lua_todataview(L, -1); - lua.lua_load(L, null, dv, lua.to_luastring("test"), lua.to_luastring("binary")); + lua.lua_load(L, function(L, s) { let r = s.dv; s.dv = null; return r; }, {dv: dv}, lua.to_luastring("test"), lua.to_luastring("binary")); lua.lua_call(L, 0, -1); diff --git a/tests/ltablib.js b/tests/ltablib.js index 43e742b..e2e8825 100644 --- a/tests/ltablib.js +++ b/tests/ltablib.js @@ -2,9 +2,6 @@ const test = require('tape'); -const tests = require("./tests.js"); -const toByteCode = tests.toByteCode; - const lua = require('../src/lua.js'); const lauxlib = require('../src/lauxlib.js'); const lualib = require('../src/lualib.js'); @@ -30,13 +27,11 @@ test('table.concat', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-table.concat"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -59,13 +54,11 @@ test('table.pack', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-table.pack"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -90,13 +83,11 @@ test('table.unpack', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-table.unpack"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -134,13 +125,11 @@ test('table.insert', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-table.insert"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -168,13 +157,11 @@ test('table.remove', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-table.remove"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -201,13 +188,11 @@ test('table.move', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-table.move"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -234,13 +219,11 @@ test('table.sort (<)', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-table.sort"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); @@ -267,13 +250,11 @@ test('table.sort with cmp function', function (t) { t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test-table.sort"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); diff --git a/tests/ltm.js b/tests/ltm.js index b1150e7..86fa52c 100644 --- a/tests/ltm.js +++ b/tests/ltm.js @@ -2,9 +2,6 @@ const test = require('tape'); -const tests = require("./tests.js"); -const toByteCode = tests.toByteCode; - const lua = require('../src/lua.js'); const lauxlib = require('../src/lauxlib.js'); const lualib = require('../src/lualib.js'); @@ -19,13 +16,11 @@ test('__index, __newindex: with actual table', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); lua.lua_call(L, 0, -1); }, "Program executed without errors"); @@ -51,13 +46,11 @@ test('__newindex: with non table', function (t) { t.plan(2); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.throws(function () { @@ -84,13 +77,11 @@ test('__index function in metatable', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); @@ -126,13 +117,11 @@ test('__newindex function in metatable', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -166,13 +155,11 @@ test('__index table in metatable', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -209,13 +196,11 @@ test('__newindex table in metatable', function (t) { t.plan(4); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -263,13 +248,11 @@ test('__index table with own metatable', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -316,13 +299,11 @@ test('__newindex table with own metatable', function (t) { t.plan(4); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -417,13 +398,11 @@ test('binary __xxx functions in metatable', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -469,13 +448,11 @@ test('__eq', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -507,13 +484,11 @@ test('__lt', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -545,13 +520,11 @@ test('__le', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -583,13 +556,11 @@ test('__le that uses __lt', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -625,13 +596,11 @@ test('__unm, __bnot', function (t) { t.plan(4); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -670,13 +639,11 @@ test('__len', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -709,13 +676,11 @@ test('__concat', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { @@ -748,13 +713,11 @@ test('__call', function (t) { t.plan(3); t.doesNotThrow(function () { - let bc = toByteCode(luaCode); - L = lauxlib.luaL_newstate(); lualib.luaL_openlibs(L); - lua.lua_load(L, null, bc, lua.to_luastring("test"), lua.to_luastring("binary")); + lauxlib.luaL_loadstring(L, lua.to_luastring(luaCode)); }, "Bytecode parsed without errors"); t.doesNotThrow(function () { -- cgit v1.2.3-54-g00ecf