lua_istable() public static method

public static lua_istable ( IntPtr luaState, int stackPos ) : bool
luaState System.IntPtr
stackPos int
return bool
示例#1
0
        public static int msgHandler(IntPtr L)
        {
            if (!LuaDLL.lua_isstring(L, 1))
            {
                return(1);
            }
            LuaDLL.wlua_getglobal(L, "debug");            //msg,debug
            if (!LuaDLL.lua_istable(L, -1))
            {
                LuaDLL.lua_pop(L, 1);
                return(1);
            }
            LuaDLL.wlua_getfield(L, -1, "traceback");             //msg,debug,traceback
            if (!LuaDLL.lua_isfunction(L, -1))
            {
                LuaDLL.lua_pop(L, 2);
                return(1);
            }
            LuaStateCache cache = LuaStateCacheMan.GetLuaStateCache(L);

            LuaDLL.lua_pushvalue(L, 1);                                   //msg,debug,traceback,msg
            LuaDLL.lua_pushinteger(L, 2 + (cache.isException() ? 2 : 0)); //msg,debug,traceback,msg,level
            LuaDLL.lua_pcall(L, 2, 1, 0);                                 //msg,debug,tracebackstring
            cache.clearException();
            return(1);
        }
示例#2
0
 public static int errorFunc_traceback(IntPtr L)
 {
     if (!LuaDLL.lua_isstring(L, 1)) /* 'message' not a string? */
     {
         return(1);                  /* keep it intact */
     }
     LuaDLL.lua_getfield(L, LuaIndexes.LUA_GLOBALSINDEX, "debug");
     if (LuaDLL.lua_istable(L, -1))
     {
         LuaDLL.lua_pop(L, 1);
         return(1);
     }
     LuaDLL.lua_getfield(L, -1, "traceback");
     if (LuaDLL.lua_isfunction(L, -1))
     {
         LuaDLL.lua_pop(L, 2);
         return(1);
     }
     LuaDLL.lua_pushvalue(L, 1);   /* pass error message */
     LuaDLL.lua_pushinteger(L, 2); /* skip this function and traceback */
     LuaDLL.lua_call(L, 2, 1);     /* call debug.traceback */
     return(1);
 }
示例#3
0
        //L:  [namespace Table]
        public bool AddObject(IntPtr L, System.Object obj, string metatable /* nullable */)
        {
            IntPtr userdata = IntPtr.Zero;

            if (luaObjs.TryGetValue(obj, out userdata))
            {
                LuaDLL.lua_rawgeti(L, LuaDLL.LUA_REGISTRYINDEX, weakRefForUserData); //namespace,reftable
                LuaDLL.lua_pushlightuserdata(L, userdata);                           //namespace,reftable,userdataKey
                LuaDLL.lua_rawget(L, -2);                                            //namespace,reftable,userdata
                LuaDLL.lua_remove(L, -2);                                            //namespace,userdata
                if (LuaDLL.lua_isuserdata(L, -1))
                {
                    return(true);
                }
                else
                {
                    LuaDLL.lua_pop(L, 1);                     //namespace
                }
            }

            userdata = LuaDLL.lua_newuserdata(L, 1);             //namespace,obj

            if (metatable == null)
            {
                Type type = obj.GetType();
                while (type != null)
                {
                    LuaDLL.wlua_getfield(L, -2, type.Name);                    //namespace,obj,typet
                    if (LuaDLL.lua_isnil(L, -1))
                    {
                        LuaDLL.lua_pop(L, 1);                         //namespace,obj
                        type = type.BaseType;
                        continue;
                    }
                    if (LuaDLL.lua_istable(L, -1))
                    {
                        metatable = type.Name;
                        break;
                    }
                    else
                    {
                        LuaDLL.lua_pop(L, 2);                         //namespace
                        throw new LuaException(L, "metatable must be a table:" + type.Name);
                    }
                }
            }
            else
            {
                LuaDLL.wlua_getfield(L, -2, metatable);                //namespace,obj,typet
                if (LuaDLL.lua_isnil(L, -1))
                {
                    LuaDLL.lua_pop(L, 2);                     //namespace
                    throw new LuaException(L, "failed to find metatable:" + metatable);
                }
            }

            //namespace,obj,typet
            LuaDLL.lua_setmetatable(L, -2);             //namespace,obj
            objs[userdata.ToInt64()] = obj;
            luaObjs[obj]             = userdata;

            LuaDLL.lua_rawgeti(L, LuaDLL.LUA_REGISTRYINDEX, weakRefForUserData); //namespace,obj,reftable
            LuaDLL.lua_pushlightuserdata(L, userdata);                           //namespace,obj,reftable,userdatakey
            LuaDLL.lua_pushvalue(L, -3);                                         //namespace,obj,reftable,userdatakey,obj
            LuaDLL.lua_rawset(L, -3);                                            //namespace,obj,reftable
            LuaDLL.lua_pop(L, 1);                                                //namespace,obj

            return(true);
        }