From c8d6c4323c62c38a4fad40642cd9db166caa910a Mon Sep 17 00:00:00 2001 From: daurnimator Date: Tue, 28 Nov 2017 00:46:24 +1100 Subject: src/lauxlib.js: Fix missing 'else' in luaL_getmetafield --- src/lauxlib.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') 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 */ } }; -- cgit v1.2.3-70-g09d2