diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-22 12:16:46 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-22 14:06:14 +1000 |
commit | 70e485206d08913cf9709db8e6b589b3df34711e (patch) | |
tree | 2bacd5cbae20fb267288605cf2feb03007253657 /src/ltm.js | |
parent | 9bd1b0764105305c67aaf083804aa1e75911d74b (diff) | |
download | fengari-70e485206d08913cf9709db8e6b589b3df34711e.tar.gz fengari-70e485206d08913cf9709db8e6b589b3df34711e.tar.bz2 fengari-70e485206d08913cf9709db8e6b589b3df34711e.zip |
Add TMcache
Diffstat (limited to 'src/ltm.js')
-rw-r--r-- | src/ltm.js | 17 |
1 files changed, 17 insertions, 0 deletions
@@ -166,6 +166,21 @@ const luaT_callorderTM = function(L, p1, p2, event) { return !L.stack[L.top].l_isfalse() ? 1 : 0; }; +const fasttm = function(l, et, e) { + return et === null ? null : + (et.flags & (1 << e)) ? null : luaT_gettm(et, e, l.l_G.tmname[e]); +}; + +const luaT_gettm = function(events, event, ename) { + const tm = ltable.luaH_getstr(events, ename); + assert(event <= TMS.TM_EQ); + if (tm.ttisnil()) { /* no tag method? */ + events.flags |= 1<<event; /* cache this fact */ + return null; + } + else return tm; +}; + const luaT_gettmbyobj = function(L, o, event) { let mt; switch(o.ttnov()) { @@ -180,11 +195,13 @@ const luaT_gettmbyobj = function(L, o, event) { return mt ? ltable.luaH_getstr(mt, L.l_G.tmname[event]) : lobject.luaO_nilobject; }; +module.exports.fasttm = fasttm; module.exports.TMS = TMS; module.exports.luaT_callTM = luaT_callTM; module.exports.luaT_callbinTM = luaT_callbinTM; module.exports.luaT_trybinTM = luaT_trybinTM; module.exports.luaT_callorderTM = luaT_callorderTM; +module.exports.luaT_gettm = luaT_gettm; module.exports.luaT_gettmbyobj = luaT_gettmbyobj; module.exports.luaT_init = luaT_init; module.exports.luaT_objtypename = luaT_objtypename; |