From 85f41a0bac75376e3abafce5b99aa6a9281bb802 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Wed, 26 Apr 2017 22:27:57 +1000 Subject: src/lapi.js: If no size is passed to lua_newuserdata, then create an empty object that isn't an ArrayBuffer --- src/lapi.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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"); -- cgit v1.2.3-70-g09d2