"use strict"; const test = require('tape'); const beautify = require('js-beautify').js_beautify; const tests = require("./tests.js"); const getState = tests.getState; const toByteCode = tests.toByteCode; const VM = require("../src/lvm.js"); const ldo = require("../src/ldo.js"); const lapi = require("../src/lapi.js"); const lauxlib = require("../src/lauxlib.js"); const lua = require('../src/lua.js'); const linit = require('../src/linit.js'); const CT = lua.constant_types; test('luaL_loadstring', function (t) { let luaCode = ` local a = "hello world" return a `, L; t.plan(3); t.doesNotThrow(function () { L = lauxlib.luaL_newstate(); linit.luaL_openlibs(L); lauxlib.luaL_loadstring(L, luaCode); }, "Lua program loaded without error"); t.doesNotThrow(function () { lapi.lua_call(L, 0, -1); }, "Lua program ran without error"); t.strictEqual( lapi.lua_tostring(L, -1), "hello world", "Correct element(s) on the stack" ); }); test('load', function (t) { let luaCode = ` local f = load("return 'js running lua running lua'") return f() `, L; t.plan(3); t.doesNotThrow(function () { L = lauxlib.luaL_newstate(); linit.luaL_openlibs(L); lauxlib.luaL_loadstring(L, luaCode); }, "Lua program loaded without error"); t.doesNotThrow(function () { lapi.lua_call(L, 0, -1); }, "Lua program ran without error"); t.strictEqual( lapi.lua_tostring(L, -1), "js running lua running lua", "Correct element(s) on the stack" ); }); test('luaL_loadbuffer', function (t) { let luaCode = ` local a = "hello world" return a `, L; t.plan(3); t.doesNotThrow(function () { let bc = toByteCode(luaCode).dataView; L = lauxlib.luaL_newstate(); linit.luaL_openlibs(L); lauxlib.luaL_loadbuffer(L, bc, null, "test"); }, "Lua program loaded without error"); t.doesNotThrow(function () { lapi.lua_call(L, 0, -1); }, "Lua program ran without error"); t.strictEqual( lapi.lua_tostring(L, -1), "hello world", "Correct element(s) on the stack" ); });