Comparing version 0.1.3 to 0.1.4
{ | ||
"name": "fengari", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"description": "A Lua VM written in JS ES6 targeting the browser", | ||
@@ -33,3 +33,3 @@ "main": "src/fengari.js", | ||
"devDependencies": { | ||
"eslint": "^5.8.0", | ||
"eslint": "^5.9.0", | ||
"jest": "^23.6.0" | ||
@@ -36,0 +36,0 @@ }, |
@@ -14,3 +14,3 @@ /* Fengari specific functions | ||
const FENGARI_VERSION_NUM = 1; | ||
const FENGARI_VERSION_RELEASE = "3"; | ||
const FENGARI_VERSION_RELEASE = "4"; | ||
const FENGARI_VERSION = "Fengari " + FENGARI_VERSION_MAJOR + "." + FENGARI_VERSION_MINOR; | ||
@@ -17,0 +17,0 @@ const FENGARI_RELEASE = FENGARI_VERSION + "." + FENGARI_VERSION_RELEASE; |
@@ -455,8 +455,3 @@ "use strict"; | ||
let v = L.stack[L.top - 1]; | ||
if (v.ttisnil()) { | ||
ltable.luaH_delete(L, o.value, k); | ||
} else { | ||
let slot = ltable.luaH_set(L, o.value, k); | ||
slot.setfrom(v); | ||
} | ||
ltable.luaH_setfrom(L, o.value, k, v); | ||
ltable.invalidateTMcache(o.value); | ||
@@ -482,8 +477,3 @@ delete L.stack[--L.top]; | ||
let v = L.stack[L.top - 1]; | ||
if (v.ttisnil()) { | ||
ltable.luaH_delete(L, o.value, k); | ||
} else { | ||
let slot = ltable.luaH_set(L, o.value, k); | ||
slot.setfrom(v); | ||
} | ||
ltable.luaH_setfrom(L, o.value, k, v); | ||
delete L.stack[--L.top]; | ||
@@ -490,0 +480,0 @@ }; |
@@ -463,3 +463,3 @@ "use strict"; | ||
let f = fs.f; | ||
let idx = ltable.luaH_set(fs.L, fs.ls.h, key); /* index scanner table */ | ||
let idx = ltable.luaH_get(fs.L, fs.ls.h, key); /* index scanner table */ | ||
if (idx.ttisinteger()) { /* is there an index there? */ | ||
@@ -473,3 +473,3 @@ let k = idx.value; | ||
let k = fs.nk; | ||
idx.setivalue(k); | ||
ltable.luaH_setfrom(fs.L, fs.ls.h, key, new lobject.TValue(LUA_TNUMINT, k)); | ||
f.k[k] = v; | ||
@@ -476,0 +476,0 @@ fs.nk++; |
"use strict"; | ||
const { | ||
constant_types: { LUA_TLNGSTR }, | ||
constant_types: { LUA_TBOOLEAN, LUA_TLNGSTR }, | ||
thread_status: { LUA_ERRSYNTAX }, | ||
@@ -208,12 +208,12 @@ to_luastring | ||
*/ | ||
const TVtrue = new lobject.TValue(LUA_TBOOLEAN, true); | ||
const luaX_newstring = function(ls, str) { | ||
let L = ls.L; | ||
let ts = luaS_new(L, str); | ||
let o = ltable.luaH_set(L, ls.h, new lobject.TValue(LUA_TLNGSTR, ts)); | ||
if (o.ttisnil()) { /* not in use yet? */ | ||
o.setbvalue(true); | ||
/* HACK: Workaround lack of ltable 'keyfromval' */ | ||
let tpair = ls.h.strong.get(luaS_hashlongstr(ts)); | ||
if (!tpair) { /* not in use yet? */ | ||
let key = new lobject.TValue(LUA_TLNGSTR, ts); | ||
ltable.luaH_setfrom(L, ls.h, key, TVtrue); | ||
} else { /* string already present */ | ||
/* HACK: Workaround lack of ltable 'keyfromval' */ | ||
let tpair = ls.h.strong.get(luaS_hashlongstr(ts)); | ||
lua_assert(tpair.value == o); /* fengari addition */ | ||
ts = tpair.key.tsvalue(); /* re-use value previously stored */ | ||
@@ -220,0 +220,0 @@ } |
@@ -188,19 +188,2 @@ "use strict"; | ||
const setgeneric = function(t, hash, key) { | ||
let v = t.strong.get(hash); | ||
if (v) | ||
return v.value; | ||
let kv = key.value; | ||
if ((key.ttisfloat() && (kv|0) === kv)) { /* does index fit in an integer? */ | ||
/* insert it as an integer */ | ||
key = new lobject.TValue(LUA_TNUMINT, kv); | ||
} else { | ||
key = new lobject.TValue(key.type, kv); | ||
} | ||
let tv = new lobject.TValue(LUA_TNIL, null); | ||
add(t, hash, key, tv); | ||
return tv; | ||
}; | ||
const luaH_setint = function(t, key, value) { | ||
@@ -213,5 +196,5 @@ lua_assert(typeof key == "number" && (key|0) === key && value instanceof lobject.TValue); | ||
} | ||
let v = t.strong.get(hash); | ||
if (v) { | ||
let tv = v.value; | ||
let e = t.strong.get(hash); | ||
if (e) { | ||
let tv = e.value; | ||
tv.setfrom(value); | ||
@@ -225,12 +208,25 @@ } else { | ||
const luaH_set = function(L, t, key) { | ||
const luaH_setfrom = function(L, t, key, value) { | ||
lua_assert(key instanceof lobject.TValue); | ||
let hash = table_hash(L, key); | ||
return setgeneric(t, hash, key); | ||
}; | ||
if (value.ttisnil()) { /* delete */ | ||
mark_dead(t, hash); | ||
return; | ||
} | ||
const luaH_delete = function(L, t, key) { | ||
lua_assert(key instanceof lobject.TValue); | ||
let hash = table_hash(L, key); | ||
return mark_dead(t, hash); | ||
let e = t.strong.get(hash); | ||
if (e) { | ||
e.value.setfrom(value); | ||
} else { | ||
let k; | ||
let kv = key.value; | ||
if ((key.ttisfloat() && (kv|0) === kv)) { /* does index fit in an integer? */ | ||
/* insert it as an integer */ | ||
k = new lobject.TValue(LUA_TNUMINT, kv); | ||
} else { | ||
k = new lobject.TValue(key.type, kv); | ||
} | ||
let v = new lobject.TValue(value.type, value.value); | ||
add(t, hash, k, v); | ||
} | ||
}; | ||
@@ -291,3 +287,2 @@ | ||
module.exports.invalidateTMcache = invalidateTMcache; | ||
module.exports.luaH_delete = luaH_delete; | ||
module.exports.luaH_get = luaH_get; | ||
@@ -297,3 +292,3 @@ module.exports.luaH_getint = luaH_getint; | ||
module.exports.luaH_getstr = luaH_getstr; | ||
module.exports.luaH_set = luaH_set; | ||
module.exports.luaH_setfrom = luaH_setfrom; | ||
module.exports.luaH_setint = luaH_setint; | ||
@@ -300,0 +295,0 @@ module.exports.luaH_new = luaH_new; |
@@ -1116,8 +1116,5 @@ "use strict"; | ||
let h = t.value; /* save 't' table */ | ||
let slot = ltable.luaH_set(L, h, key); | ||
let slot = ltable.luaH_get(L, h, key); | ||
if (!slot.ttisnil() || (tm = ltm.fasttm(L, h.metatable, ltm.TMS.TM_NEWINDEX)) === null) { | ||
if (val.ttisnil()) | ||
ltable.luaH_delete(L, h, key); | ||
else | ||
slot.setfrom(val); | ||
ltable.luaH_setfrom(L, h, key, val); | ||
ltable.invalidateTMcache(h); | ||
@@ -1124,0 +1121,0 @@ return; |
@@ -56,1 +56,24 @@ "use strict"; | ||
}); | ||
test('__newindex leaves nils', () => { | ||
let L = lauxlib.luaL_newstate(); | ||
if (!L) throw Error("failed to create lua state"); | ||
let luaCode = ` | ||
local x = setmetatable({}, { | ||
__newindex = function(t,k,v) | ||
rawset(t,'_'..k,v) | ||
end | ||
}) | ||
x.test = 4 | ||
for k,v in pairs(x) do | ||
assert(k ~= "test", "found phantom key") | ||
end | ||
`; | ||
{ | ||
lualib.luaL_openlibs(L); | ||
expect(lauxlib.luaL_loadstring(L, to_luastring(luaCode))).toBe(lua.LUA_OK); | ||
lua.lua_call(L, 0, -1); | ||
} | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96
32147
1794810