summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBenoit Giannangeli <giann008@gmail.com>2017-05-02 11:06:38 +0200
committerBenoit Giannangeli <giann008@gmail.com>2017-05-02 11:06:38 +0200
commitf2bb5dee9b90197185dd0367cee98b61b066ae70 (patch)
treeb3222d28e409053e6c6e1036de25c8e5701c9d7d /src
parentd35f4e1dcec1494483a9257b7a2cacb172047c1f (diff)
parent59d5ff59e3b9eacc2b2aa8e92e71f31914d09545 (diff)
downloadfengari-f2bb5dee9b90197185dd0367cee98b61b066ae70.tar.gz
fengari-f2bb5dee9b90197185dd0367cee98b61b066ae70.tar.bz2
fengari-f2bb5dee9b90197185dd0367cee98b61b066ae70.zip
Merge remote-tracking branch 'daurnimator/fix-errors'
Diffstat (limited to 'src')
-rw-r--r--src/lauxlib.js10
-rw-r--r--src/ldebug.js2
-rw-r--r--src/lfunc.js5
-rw-r--r--src/lobject.js19
-rw-r--r--src/lundump.js18
5 files changed, 27 insertions, 27 deletions
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;
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);
}
diff --git a/src/lfunc.js b/src/lfunc.js
index 3f8fe2d..69c7581 100644
--- a/src/lfunc.js
+++ b/src/lfunc.js
@@ -56,10 +56,7 @@ class UpVal {
}
const luaF_newLclosure = function(L, n) {
- let c = new lobject.LClosure();
- c.p = null;
- c.nupvalues = n;
- while (n--) c.upvals[n] = null;
+ let c = new lobject.LClosure(L, n);
return c;
};
diff --git a/src/lobject.js b/src/lobject.js
index 5a202d4..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;
@@ -147,6 +145,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;
@@ -201,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);