summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-11-28 00:46:24 +1100
committerdaurnimator <quae@daurnimator.com>2017-11-28 00:46:24 +1100
commitc8d6c4323c62c38a4fad40642cd9db166caa910a (patch)
tree8ce53569ec9823948a94024e340847f50d8668e0
parentaa1a44c84f11f97f6614b9c2fd252fddec4067eb (diff)
downloadfengari-c8d6c4323c62c38a4fad40642cd9db166caa910a.tar.gz
fengari-c8d6c4323c62c38a4fad40642cd9db166caa910a.tar.bz2
fengari-c8d6c4323c62c38a4fad40642cd9db166caa910a.zip
src/lauxlib.js: Fix missing 'else' in luaL_getmetafield
-rw-r--r--src/lauxlib.js10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lauxlib.js b/src/lauxlib.js
index 62fc6f3..518190f 100644
--- a/src/lauxlib.js
+++ b/src/lauxlib.js
@@ -437,14 +437,16 @@ const luaL_dostring = function(L, s) {
};
const luaL_getmetafield = function(L, obj, event) {
- if (!lua.lua_getmetatable(L, obj))
+ if (!lua.lua_getmetatable(L, obj)) /* no metatable? */
return lua.LUA_TNIL;
else {
lua.lua_pushstring(L, event);
let tt = lua.lua_rawget(L, -2);
- if (tt === lua.LUA_TNIL)
- lua.lua_pop(L, 2);
- return tt;
+ if (tt === lua.LUA_TNIL) /* is metafield nil? */
+ lua.lua_pop(L, 2); /* remove metatable and metafield */
+ else
+ lua.lua_remove(L, -2); /* remove only metatable */
+ return tt; /* return metafield type */
}
};