diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-04-18 15:20:37 +0200 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-04-18 15:20:37 +0200 |
commit | a02f4e93b92e7ebb7ef038ad151e51652b0ce84d (patch) | |
tree | 2b83cacef266ff88ca3ed8cf3f19c1a1cbea7b38 /src/lobject.js | |
parent | 924ca09e8e9ec765301868d90dd3eba98058cafb (diff) | |
download | fengari-a02f4e93b92e7ebb7ef038ad151e51652b0ce84d.tar.gz fengari-a02f4e93b92e7ebb7ef038ad151e51652b0ce84d.tar.bz2 fengari-a02f4e93b92e7ebb7ef038ad151e51652b0ce84d.zip |
No more Table, just TValue with table type and Map value
Diffstat (limited to 'src/lobject.js')
-rw-r--r-- | src/lobject.js | 66 |
1 files changed, 29 insertions, 37 deletions
diff --git a/src/lobject.js b/src/lobject.js index adec0ba..9a79c95 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -176,49 +176,39 @@ const jsstring = function(value, from, to) { return str; }; -class Table extends TValue { - - constructor(array, hash) { - super(CT.LUA_TTABLE, new Map(hash)); - - this.metatable = null; - } - - static keyValue(key) { - // Those lua values are used by value, others by reference - if (key instanceof TValue) { - if ([CT.LUA_TNIL, - CT.LUA_TBOOLEAN, - CT.LUA_TSTRING, - CT.LUA_TNUMINT].indexOf(key.type) > -1) { - key = key.value; - } else if ([CT.LUA_TSHRSTR, CT.LUA_TLNGSTR].indexOf(key.type) > -1) { - key = key.value.map(e => `${e}|`).join(''); - } - } else if (typeof key === "string") { // To avoid - key = lua.to_luastring(key).map(e => `${e}|`).join(''); - } else if (Array.isArray(key)) { - key = key.map(e => `${e}|`).join(''); +const table_keyValue = function(key) { + // Those lua values are used by value, others by reference + if (key instanceof TValue) { + if ([CT.LUA_TNIL, + CT.LUA_TBOOLEAN, + CT.LUA_TSTRING, + CT.LUA_TNUMINT].indexOf(key.type) > -1) { + key = key.value; + } else if ([CT.LUA_TSHRSTR, CT.LUA_TLNGSTR].indexOf(key.type) > -1) { + key = key.value.map(e => `${e}|`).join(''); } - - return key; + } else if (typeof key === "string") { // To avoid + key = lua.to_luastring(key).map(e => `${e}|`).join(''); + } else if (Array.isArray(key)) { + key = key.map(e => `${e}|`).join(''); } - __newindex(table, key, value) { - key = Table.keyValue(key); + return key; +}; - table.value.set(key, value); - } +const table_newindex = function(table, key, value) { + key = table_keyValue(key); - __index(table, key) { - key = Table.keyValue(key); + table.value.set(key, value); +}; - let v = table.value.get(key); +const table_index = function(table, key) { + key = table_keyValue(key); - return v ? v : luaO_nilobject; - } + let v = table.value.get(key); -} + return v ? v : luaO_nilobject; +}; class LClosure extends TValue { @@ -233,7 +223,7 @@ class LClosure extends TValue { _ENV.v = null; _ENV.u.open.next = null; _ENV.u.open.touched = true; - _ENV.u.value = new Table(); + _ENV.u.value = new TValue(CT.LUA_TTABLE, new Map()); this.upvals = [ _ENV @@ -566,7 +556,6 @@ module.exports.CClosure = CClosure; module.exports.LClosure = LClosure; module.exports.LocVar = LocVar; module.exports.TValue = TValue; -module.exports.Table = Table; module.exports.UTF8BUFFSZ = UTF8BUFFSZ; module.exports.frexp = frexp; module.exports.intarith = intarith; @@ -579,3 +568,6 @@ module.exports.luaO_str2num = luaO_str2num; module.exports.luaO_utf8desc = luaO_utf8desc; module.exports.luaO_utf8esc = luaO_utf8esc; module.exports.numarith = numarith; +module.exports.table_index = table_index; +module.exports.table_keyValue = table_keyValue; +module.exports.table_newindex = table_newindex; |