// Starting with 5.1 the auxlib version of checkudata throws an exception if the type isn't right // Instead, we want to run our own version that checks the type and just returns null for failure private static IntPtr checkudata_raw(LuaCore.lua_State L, int ud, string tname) { var p = LuaCore.lua_touserdata(L, ud); if (p != IntPtr.Zero) { /* value is a userdata? */ if (LuaCore.lua_getmetatable(L, ud) != 0) { bool isEqual; /* does it have a metatable? */ LuaCore.lua_getfield(L, (int)LuaIndexes.Registry, tname); /* get correct metatable */ isEqual = LuaCore.lua_rawequal(L, -1, -2) != 0; // NASTY - we need our own version of the lua_pop macro // lua_pop(L, 2); /* remove both metatables */ LuaCore.lua_settop(L, -(2) - 1); if (isEqual) /* does it have the correct mt? */ { return(p); } } } return(IntPtr.Zero); }
// steffenj: BEGIN Lua 5.1.1 API change (luaL_getmetatable is now a macro using lua_getfield) public static void lua_getfield(LuaCore.lua_State luaState, int stackPos, string meta) { LuaCore.lua_getfield(luaState, stackPos, meta); }