From 91427896625e01ce2ab7171e1cf2369c89e53658 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 2 May 2017 14:29:00 +1000 Subject: src/lobject: Add sethvalue method to TValue --- src/lobject.js | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src') diff --git a/src/lobject.js b/src/lobject.js index 5a202d4..5918a84 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -147,6 +147,11 @@ class TValue { this.value = x; } + sethvalue(x) { + this.type = CT.LUA_TTABLE; + this.value = x; + } + setfrom(tv) { /* in lua C source setobj2t is often used for this */ this.type = tv.type; this.value = tv.value; -- cgit v1.2.3-70-g09d2 From 77480d0f313b12272fd594d1bade97c4a2b7c8df Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 2 May 2017 14:39:41 +1000 Subject: src/lfunc.js: Pass arguments to LClosure constructor --- src/lfunc.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src') diff --git a/src/lfunc.js b/src/lfunc.js index 3f8fe2d..e12816d 100644 --- a/src/lfunc.js +++ b/src/lfunc.js @@ -56,9 +56,7 @@ class UpVal { } const luaF_newLclosure = function(L, n) { - let c = new lobject.LClosure(); - c.p = null; - c.nupvalues = n; + let c = new lobject.LClosure(L, n); while (n--) c.upvals[n] = null; return c; }; -- cgit v1.2.3-70-g09d2 From 5a28287e832a60133865386c8a034a5ca8b76bce Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 2 May 2017 15:06:46 +1000 Subject: src/lauxlib.js: Add luaL_dostring and luaL_dofile --- README.md | 2 -- src/lauxlib.js | 10 ++++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/README.md b/README.md index c14ff90..c0fd4f3 100644 --- a/README.md +++ b/README.md @@ -73,8 +73,6 @@ - [ ] luaL_addsize - [ ] luaL_checkoption - [ ] luaL_checkversion - - [ ] luaL_dofile - - [ ] luaL_dostring - [ ] luaL_gsub - [ ] luaL_newlibtable - [ ] luaL_optnumber diff --git a/src/lauxlib.js b/src/lauxlib.js index 68e7c12..1921237 100644 --- a/src/lauxlib.js +++ b/src/lauxlib.js @@ -403,6 +403,10 @@ const luaL_loadstring = function(L, s) { return luaL_loadbuffer(L, s, s.length, s); }; +const luaL_dostring = function(L, s) { + return (luaL_loadstring(L, s) || lua.lua_pcall(L, 0, lua.LUA_MULTRET, 0)); +}; + const luaL_getmetafield = function(L, obj, event) { if (!lua.lua_getmetatable(L, obj)) return lua.LUA_TNIL; @@ -699,6 +703,11 @@ if (typeof require === "function") { return luaL_loadfilex(L, filename, null); }; + const luaL_dofile = function(L, filename) { + return (luaL_loadfile(L, filename) || lua.lua_pcall(L, 0, lua.LUA_MULTRET, 0)); + }; + + module.exports.luaL_dofile = luaL_dofile; module.exports.luaL_loadfilex = luaL_loadfilex; module.exports.luaL_loadfile = luaL_loadfile; } @@ -729,6 +738,7 @@ module.exports.luaL_checkstack = luaL_checkstack; module.exports.luaL_checkstring = luaL_checkstring; module.exports.luaL_checktype = luaL_checktype; module.exports.luaL_checkudata = luaL_checkudata; +module.exports.luaL_dostring = luaL_dostring; module.exports.luaL_error = luaL_error; module.exports.luaL_execresult = luaL_execresult; module.exports.luaL_fileresult = luaL_fileresult; -- cgit v1.2.3-70-g09d2 From d9865ac5163f467268dcd894320bb283e053badb Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 2 May 2017 15:00:04 +1000 Subject: Use lfunc from lundump.js --- src/lfunc.js | 1 - src/lobject.js | 14 +------------- src/lundump.js | 18 +++++++++--------- 3 files changed, 10 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/lfunc.js b/src/lfunc.js index e12816d..69c7581 100644 --- a/src/lfunc.js +++ b/src/lfunc.js @@ -57,7 +57,6 @@ class UpVal { const luaF_newLclosure = function(L, n) { let c = new lobject.LClosure(L, n); - while (n--) c.upvals[n] = null; return c; }; diff --git a/src/lobject.js b/src/lobject.js index 5918a84..784720b 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -7,9 +7,7 @@ const defs = require('./defs.js'); const ljstype = require('./ljstype.js'); const luaconf = require('./luaconf.js'); const llimit = require('./llimit.js'); -const ltable = require('./ltable.js'); const CT = defs.constant_types; -const UpVal = require('./lfunc.js').UpVal; const char = defs.char; let tvalueCount = 0; @@ -206,17 +204,7 @@ class LClosure { constructor(L, n) { this.p = null; this.nupvalues = n; - - let _ENV = new UpVal(L); - _ENV.refcount = 0; - _ENV.v = null; - _ENV.u.open.next = null; - _ENV.u.open.touched = true; - _ENV.u.value = new TValue(CT.LUA_TTABLE, ltable.luaH_new(L)); - - this.upvals = [ - _ENV - ]; + this.upvals = Array(n); } } diff --git a/src/lundump.js b/src/lundump.js index 9162501..1d2d079 100644 --- a/src/lundump.js +++ b/src/lundump.js @@ -1,12 +1,12 @@ /*jshint esversion: 6 */ "use strict"; -const assert = require('assert'); +const assert = require('assert'); -const defs = require('./defs.js'); -const lobject = require('./lobject.js'); -const Proto = require('./lfunc.js').Proto; -const OpCodes = require('./lopcodes.js'); +const defs = require('./defs.js'); +const lfunc = require('./lfunc.js'); +const lobject = require('./lobject.js'); +const lopcodes = require('./lopcodes.js'); const LUAI_MAXSHORTLEN = 40; @@ -128,7 +128,7 @@ class BytecodeParser { readCode(f) { let n = this.readInt(); - let o = OpCodes; + let o = lopcodes; let p = BytecodeParser; for (let i = 0; i < n; i++) { @@ -191,7 +191,7 @@ class BytecodeParser { let n = this.readInt(); for (let i = 0; i < n; i++) { - f.p[i] = new Proto(this.L); + f.p[i] = new lfunc.Proto(this.L); this.readFunction(f.p[i], f.source); } } @@ -280,12 +280,12 @@ class BytecodeParser { luaU_undump() { this.checkHeader(); - let cl = new lobject.LClosure(this.L, this.readByte()); + let cl = lfunc.luaF_newLclosure(this.L, this.readByte()); this.L.stack[this.L.top] = new lobject.TValue(defs.CT.LUA_TLCL, cl); this.L.top++; - cl.p = new Proto(); + cl.p = new lfunc.Proto(); this.readFunction(cl.p); -- cgit v1.2.3-70-g09d2 From 59d5ff59e3b9eacc2b2aa8e92e71f31914d09545 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 2 May 2017 18:44:13 +1000 Subject: src/debug.js: Fix incorrect argument order to new TValue --- src/ldebug.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/ldebug.js b/src/ldebug.js index c9c4c1e..d429457 100644 --- a/src/ldebug.js +++ b/src/ldebug.js @@ -183,7 +183,7 @@ const collectvalidlines = function(L, f) { let t = new TValue(CT.LUA_TTABLE, ltable.luaH_new(L)); L.stack[L.top++] = t; assert(L.top <= L.ci.top, "stack overflow"); - let v = new TValue(true, CT.LUA_TBOOLEAN); + let v = new TValue(CT.LUA_TBOOLEAN, true); for (let i = 0; i < f.l.p.length; i++) lobject.table_newindex(t, lineinfo[i], v); } -- cgit v1.2.3-70-g09d2