diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-24 14:32:35 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-24 14:38:40 +1000 |
commit | e980731dbddb46260d7287373a2cb3a835e30e5a (patch) | |
tree | 293aaf74a8299aa2b667a262cfc9767773c4befd | |
parent | 9f43d27b4377b1d3e166657a608dad91668c7909 (diff) | |
download | fengari-e980731dbddb46260d7287373a2cb3a835e30e5a.tar.gz fengari-e980731dbddb46260d7287373a2cb3a835e30e5a.tar.bz2 fengari-e980731dbddb46260d7287373a2cb3a835e30e5a.zip |
Give userdata objects a class
This way their type can be checked via `instanceof`
-rw-r--r-- | src/lapi.js | 8 | ||||
-rw-r--r-- | src/lobject.js | 14 |
2 files changed, 15 insertions, 7 deletions
diff --git a/src/lapi.js b/src/lapi.js index 8e0c491..ae9fa89 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -511,13 +511,7 @@ const lua_createtable = function(L, narray, nrec) { }; const luaS_newudata = function(L, size) { - return { - id: L.l_G.id_counter++, - metatable: null, - uservalue: new lobject.TValue(CT.LUA_TNIL, null), - len: size, - data: Object.create(null) // ignores size argument - }; + return new lobject.Udata(L, size); }; const lua_newuserdata = function(L, size) { diff --git a/src/lobject.js b/src/lobject.js index 8c70985..119e20e 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -214,6 +214,19 @@ class CClosure { } +class Udata { + + constructor(L, size) { + this.id = L.l_G.id_counter++; + + this.metatable = null; + this.uservalue = new TValue(CT.LUA_TNIL, null); + this.len = size; + this.data = Object.create(null); // ignores size argument + } + +} + /* ** Description of a local variable for function prototypes ** (used for debug information) @@ -630,6 +643,7 @@ module.exports.LUA_TDEADKEY = LUA_TDEADKEY; module.exports.LUA_TPROTO = LUA_TPROTO; module.exports.LocVar = LocVar; module.exports.TValue = TValue; +module.exports.Udata = Udata; module.exports.UTF8BUFFSZ = UTF8BUFFSZ; module.exports.luaO_arith = luaO_arith; module.exports.luaO_chunkid = luaO_chunkid; |