diff options
author | Benoit Giannangeli <giann008@gmail.com> | 2017-02-11 22:22:38 +0100 |
---|---|---|
committer | Benoit Giannangeli <giann008@gmail.com> | 2017-02-12 17:00:20 +0100 |
commit | 4bf190d1b51c8c2d3f5ab0b6355ecd971b735adc (patch) | |
tree | 2d3bb5d29f60d12db379933273d654683c539cf4 /src/lobject.js | |
parent | 3c5cf1687c2da09f56ca1de340e5ada2119efca9 (diff) | |
download | fengari-4bf190d1b51c8c2d3f5ab0b6355ecd971b735adc.tar.gz fengari-4bf190d1b51c8c2d3f5ab0b6355ecd971b735adc.tar.bz2 fengari-4bf190d1b51c8c2d3f5ab0b6355ecd971b735adc.zip |
TFORCALL, TFORLOOP, luaD_call, tag methods
Diffstat (limited to 'src/lobject.js')
-rw-r--r-- | src/lobject.js | 85 |
1 files changed, 49 insertions, 36 deletions
diff --git a/src/lobject.js b/src/lobject.js index 4c3290d..713a734 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -104,6 +104,7 @@ class TValue { } +const nil = new TValue(CT.LUA_TNIL, null); class LClosure extends TValue { @@ -138,6 +139,17 @@ class TString extends TValue { } +class Userdata extends TValue { + + constructor(jsObject) { + super(CT.LUA_TUSERDATA, jsObject); + + this.metatable = null; + } + +} + + class Table extends TValue { constructor(array, hash) { @@ -146,43 +158,44 @@ class Table extends TValue { hash: new Map(hash) }); - this.usermetatable = null; - - this.metatable = { - __newindex: function (table, key, value) { - if (key instanceof TValue) { - // Those lua values are used by value, tables and functions by reference - if ([CT.LUA_TNUMBER, CT.LUA_TSTRING, CT.LUA_TSHRSTR, CT.LUA_TLNGSTR, CT.LUA_TNUMFLT, CT.LUA_TNUMINT].indexOf(key.type) > -1) { - key = key.value; - } - } - - if (typeof key === 'number') { - table.value.array[key] = value; - } else { - table.value.hash.set(key, value); - } - }, - - __index: function (table, key) { - if (key instanceof TValue) { - // Those lua values are used by value, tables and functions by reference - if ([CT.LUA_TNUMBER, CT.LUA_TSTRING, CT.LUA_TSHRSTR, CT.LUA_TLNGSTR, CT.LUA_TNUMFLT, CT.LUA_TNUMINT].indexOf(key.type) > -1) { - key = key.value; - } - } - - if (typeof key === 'number') { - return table.value.array[key]; - } else { - return table.value.hash.get(key); - } - }, - - __len: function (table) { - return t.value.array.length; + this.metatable = null; + } + + __newindex(table, key, value) { + if (key instanceof TValue) { + // Those lua values are used by value, tables and functions by reference + if ([CT.LUA_TNUMBER, CT.LUA_TSTRING, CT.LUA_TSHRSTR, CT.LUA_TLNGSTR, CT.LUA_TNUMFLT, CT.LUA_TNUMINT].indexOf(key.type) > -1) { + key = key.value; + } + } + + if (typeof key === 'number') { + table.value.array[key] = value; + } else { + table.value.hash.set(key, value); + } + } + + __index(table, key) { + if (key instanceof TValue) { + // Those lua values are used by value, tables and functions by reference + if ([CT.LUA_TNUMBER, CT.LUA_TSTRING, CT.LUA_TSHRSTR, CT.LUA_TLNGSTR, CT.LUA_TNUMFLT, CT.LUA_TNUMINT].indexOf(key.type) > -1) { + key = key.value; } - }; + } + + let v = nil; + if (typeof key === 'number') { + v = table.value.array[key]; + } else { + v = table.value.hash.get(key); + } + + return v ? v : nil; + } + + __len(table) { + return t.value.array.length; } } |