aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-04-26 22:27:57 +1000
committerdaurnimator <quae@daurnimator.com>2017-04-26 22:27:57 +1000
commit85f41a0bac75376e3abafce5b99aa6a9281bb802 (patch)
tree55032c4c25d22c73c46a61282ed0a6da7be64cbf /src
parente691ea1911cf1d070ad7c6c256ce4558e2846cc9 (diff)
downloadfengari-85f41a0bac75376e3abafce5b99aa6a9281bb802.tar.gz
fengari-85f41a0bac75376e3abafce5b99aa6a9281bb802.tar.bz2
fengari-85f41a0bac75376e3abafce5b99aa6a9281bb802.zip
src/lapi.js: If no size is passed to lua_newuserdata, then create an empty object that isn't an ArrayBuffer
Diffstat (limited to 'src')
-rw-r--r--src/lapi.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 9dbebad..46c7e2b 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -473,7 +473,13 @@ const lua_createtable = function(L, narray, nrec) {
};
const lua_newuserdata = function(L, size) {
- L.stack[L.top++] = new lobject.TValue(CT.LUA_TUSERDATA, new ArrayBuffer(size));
+ let box;
+ if (typeof size == "number")
+ box = new ArrayBuffer(size);
+ else // if size is not passed, create a new empty object
+ box = Object.create(null);
+
+ L.stack[L.top++] = new lobject.TValue(CT.LUA_TUSERDATA, box);
assert(L.top <= L.ci.top, "stack overflow");