Example #1
0
        // 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);
        }
Example #2
0
 public static int lua_getmetatable(LuaCore.lua_State luaState, int objIndex)
 {
     return(LuaCore.lua_getmetatable(luaState, objIndex));
 }