示例#1
0
        public static void CompleteTypeMeta(IntPtr ptr, LuaCSFunction con, Type self)
        {
            LuaNativeMethods.lua_pushstring(ptr, ObjectCache.GetAQName(self));
            LuaNativeMethods.lua_setfield(ptr, -3, "__fullname");

            indexFunction.Push(ptr);
            LuaNativeMethods.lua_setfield(ptr, -2, "__index");

            newIndexFunction.Push(ptr);
            LuaNativeMethods.lua_setfield(ptr, -2, "__newindex");

            if (con == null)
            {
                con = NoConstructor;
            }

            PushValue(ptr, con);
            LuaNativeMethods.lua_setfield(ptr, -2, "__call");

            LuaNativeMethods.lua_pushcfunction(ptr, TypeToString);
            LuaNativeMethods.lua_setfield(ptr, -2, "__tostring");

            LuaNativeMethods.lua_pushvalue(ptr, -1);
            LuaNativeMethods.lua_setmetatable(ptr, -3);

            LuaNativeMethods.lua_setfield(ptr, LuaIndexes.LUARegistryIndex, self.FullName);
        }
示例#2
0
 public ObjectCache(IntPtr ptr)
 {
     LuaNativeMethods.lua_newtable(ptr);
     LuaNativeMethods.lua_newtable(ptr);
     LuaNativeMethods.lua_pushstring(ptr, "v");
     LuaNativeMethods.lua_setfield(ptr, -2, "__mode");
     LuaNativeMethods.lua_setmetatable(ptr, -2);
     cacheRef = LuaNativeMethods.luaL_ref(ptr, LuaIndexes.LUARegistryIndex);
 }
示例#3
0
        public static void GC(IntPtr ptr, int p, UnityEngine.Object o)
        {
            // set ud's metatable is nil avoid gc again
            LuaNativeMethods.lua_pushnil(ptr);
            LuaNativeMethods.lua_setmetatable(ptr, p);

            ObjectCache t = ObjectCache.Get(ptr);

            t.GC(o);
        }
示例#4
0
        public static int As(IntPtr ptr)
        {
            try
            {
                if (!LuaObject.IsTypeTable(ptr, 2))
                {
                    return(Error(ptr, "No matched type of param 2"));
                }

                string meta = LuaNativeMethods.lua_tostring(ptr, -1);
                LuaNativeMethods.luaL_getmetatable(ptr, meta);
                LuaNativeMethods.lua_setmetatable(ptr, 1);
                LuaObject.PushValue(ptr, true);
                LuaNativeMethods.lua_pushvalue(ptr, 1);
                return(2);
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }