From ae8b95ee9c3871f506b20c74367fdc9e8cb098e2 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 1 Mar 2017 10:23:32 +0100 Subject: lua_load will load both binary and text --- tests/lapi.js | 1 - tests/lbaselib.js | 1 - tests/lcorolib.js | 1 - tests/ldebug.js | 1 - tests/llex.js | 1 - tests/lmathlib.js | 1 - tests/load.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/ltablib.js | 1 - tests/ltm.js | 1 - tests/lvm.js | 1 - tests/tests.js | 1 - 11 files changed, 68 insertions(+), 10 deletions(-) create mode 100644 tests/load.js (limited to 'tests') diff --git a/tests/lapi.js b/tests/lapi.js index 30366d5..6761425 100644 --- a/tests/lapi.js +++ b/tests/lapi.js @@ -1,4 +1,3 @@ -/*jshint esversion: 6 */ "use strict"; const test = require('tape'); diff --git a/tests/lbaselib.js b/tests/lbaselib.js index be5cdad..72a2f15 100644 --- a/tests/lbaselib.js +++ b/tests/lbaselib.js @@ -1,4 +1,3 @@ -/*jshint esversion: 6 */ "use strict"; const test = require('tape'); diff --git a/tests/lcorolib.js b/tests/lcorolib.js index 78024dd..022cda6 100644 --- a/tests/lcorolib.js +++ b/tests/lcorolib.js @@ -1,4 +1,3 @@ -/*jshint esversion: 6 */ "use strict"; const test = require('tape'); diff --git a/tests/ldebug.js b/tests/ldebug.js index 491b8ba..45194e9 100644 --- a/tests/ldebug.js +++ b/tests/ldebug.js @@ -1,4 +1,3 @@ -/*jshint esversion: 6 */ "use strict"; const test = require('tape'); diff --git a/tests/llex.js b/tests/llex.js index 1457af3..8b69acc 100644 --- a/tests/llex.js +++ b/tests/llex.js @@ -1,4 +1,3 @@ -/*jshint esversion: 6 */ "use strict"; const test = require('tape'); diff --git a/tests/lmathlib.js b/tests/lmathlib.js index ba6853c..48ae1a2 100644 --- a/tests/lmathlib.js +++ b/tests/lmathlib.js @@ -1,4 +1,3 @@ -/*jshint esversion: 6 */ "use strict"; const test = require('tape'); diff --git a/tests/load.js b/tests/load.js new file mode 100644 index 0000000..4df3f6a --- /dev/null +++ b/tests/load.js @@ -0,0 +1,68 @@ +"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('lua_load, binary mode', function (t) { + let luaCode = ` + return "hello world" + `, L; + + t.plan(2); + + t.doesNotThrow(function () { + + let bc = toByteCode(luaCode).dataView; + + L = lauxlib.luaL_newstate(); + + linit.luaL_openlibs(L); + + lapi.lua_load(L, null, bc, "test-math", "binary"); + + 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" + ); + +}); + + +test('lua_load, text mode', 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-math", "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/ltablib.js b/tests/ltablib.js index fa15d6a..2ebf98c 100644 --- a/tests/ltablib.js +++ b/tests/ltablib.js @@ -1,4 +1,3 @@ -/*jshint esversion: 6 */ "use strict"; const test = require('tape'); diff --git a/tests/ltm.js b/tests/ltm.js index a05d2b5..d749d7b 100644 --- a/tests/ltm.js +++ b/tests/ltm.js @@ -1,4 +1,3 @@ -/*jshint esversion: 6 */ "use strict"; const test = require('tape'); diff --git a/tests/lvm.js b/tests/lvm.js index 4f02ed5..5d4eae1 100644 --- a/tests/lvm.js +++ b/tests/lvm.js @@ -1,4 +1,3 @@ -/*jshint esversion: 6 */ "use strict"; const test = require('tape'); diff --git a/tests/tests.js b/tests/tests.js index 0963159..a47aee5 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -1,4 +1,3 @@ -/*jshint esversion: 6 */ "use strict"; const fs = require('fs'); -- cgit v1.2.3-54-g00ecf