GetMetaReference() public static method

public static GetMetaReference ( IntPtr L, Type t ) : int
L System.IntPtr
t System.Type
return int
示例#1
0
        public static Func <IntPtr, int> GetLuaReference(Type type)
        {
            int metaref = -1;

            return((IntPtr L ) =>
            {
#if MULTI_STATE
                return LuaStatic.GetMetaReference(L, type);
#else
                if (metaref > 0)
                {
                    return metaref;
                }

                metaref = LuaStatic.GetMetaReference(L, type);

                if (metaref > 0)
                {
                    LuaState.Get(L).OnDestroy += () => { metaref = -1; };
                }

                return metaref;
#endif
            });
        }
示例#2
0
        public void Push(IntPtr L, Transform o)
        {
            if (o == null)
            {
                LuaDLL.lua_pushnil(L);
            }
            else
            {
                Type type      = o.GetType();
                int  reference = -1;

                if (type == typeof(Transform))
                {
                    reference = TypeTraits <Transform> .GetLuaReference(L);
                }
                else
                {
                    reference = LuaStatic.GetMetaReference(L, type);
                }

                if (reference <= 0)
                {
                    reference = ToLua.LoadPreType(L, type);
                }

                ToLua.PushUserData(L, o, reference);
            }
        }
示例#3
0
        public static void OpenLibs(IntPtr L)
        {
            LuaDLL.lua_getglobal(L, "tolua");

            LuaDLL.lua_pushstring(L, "isnull");
            LuaDLL.lua_pushcfunction(L, IsNull);
            LuaDLL.lua_rawset(L, -3);

            LuaDLL.lua_pushstring(L, "tolstring");
            LuaDLL.tolua_pushcfunction(L, BufferToString);
            LuaDLL.lua_rawset(L, -3);

            LuaDLL.lua_pushstring(L, "typeof");
            LuaDLL.lua_pushcfunction(L, GetClassType);
            LuaDLL.lua_rawset(L, -3);

            //手动模拟gc
            //LuaDLL.lua_pushstring(L, "collect");
            //LuaDLL.lua_pushcfunction(L, Collect);
            //LuaDLL.lua_rawset(L, -3);

            int meta = LuaStatic.GetMetaReference(L, typeof(NullObject));

            LuaDLL.lua_pushstring(L, "null");
            LuaDLL.tolua_pushnewudata(L, meta, 1);
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pop(L, 1);


            LuaDLL.tolua_pushudata(L, 1);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "null");
            LuaDLL.lua_pop(L, 1);
        }
示例#4
0
        static void PushUserObject(IntPtr L, object o)
        {
            Type type      = o.GetType();
            int  reference = LuaStatic.GetMetaReference(L, type);

            PushUserData(L, o, reference);
        }
示例#5
0
        public static void PushValue(IntPtr L, ValueType v)
        {
            if (v == null)
            {
                LuaDLL.lua_pushnil(L);
                return;
            }
            Type             type             = v.GetType();
            int              metaReference    = LuaStatic.GetMetaReference(L, type);
            ObjectTranslator objectTranslator = ObjectTranslator.Get(L);

            if (metaReference > 0)
            {
                int index = objectTranslator.AddObject(v);
                LuaDLL.tolua_pushnewudata(L, metaReference, index);
            }
            else
            {
                LuaCSFunction preModule = LuaStatic.GetPreModule(L, type);
                if (preModule != null)
                {
                    preModule(L);
                    metaReference = LuaStatic.GetMetaReference(L, type);
                    if (metaReference > 0)
                    {
                        int index2 = objectTranslator.AddObject(v);
                        LuaDLL.tolua_pushnewudata(L, metaReference, index2);
                        return;
                    }
                }
                LuaDLL.lua_pushnil(L);
                Debugger.LogError("Type {0} not wrap to lua", LuaMisc.GetTypeName(type));
            }
        }
示例#6
0
        static public int GetLuaReference(IntPtr L)
        {
            if (metaref > 0)
            {
                return(metaref);
            }

            metaref = LuaStatic.GetMetaReference(L, type);
            return(metaref);
        }
示例#7
0
 public static void Push(IntPtr L, Delegate d)
 {
     if (d == null)
     {
         LuaDLL.lua_pushnil(L);
     }
     else
     {
         int delegateMetaRef = LuaStatic.GetMetaReference(L, typeof(Delegate));
         PushUserData(L, d, delegateMetaRef);
     }
 }
示例#8
0
 public static void Push(IntPtr L, EventObject ev)
 {
     if (ev == null)
     {
         LuaDLL.lua_pushnil(L);
     }
     else
     {
         int eventMetatable = LuaStatic.GetMetaReference(L, typeof(EventObject));
         PushUserData(L, ev, eventMetatable);
     }
 }
示例#9
0
        public static void OpenLibs(IntPtr L)
        {
            if (!SNG_LUA_DEBUG)
            {
                AddLuaLoader(L);
            }

            LuaDLL.tolua_atpanic(L, Panic);
            LuaDLL.tolua_pushcfunction(L, Print);
            LuaDLL.lua_setglobal(L, "print");
            LuaDLL.tolua_pushcfunction(L, DoFile);
            LuaDLL.lua_setglobal(L, "dofile");
            LuaDLL.tolua_pushcfunction(L, LoadFile);
            LuaDLL.lua_setglobal(L, "loadfile");

            LuaDLL.lua_getglobal(L, "tolua");

            LuaDLL.lua_pushstring(L, "isnull");
            LuaDLL.lua_pushcfunction(L, IsNull);
            LuaDLL.lua_rawset(L, -3);

            LuaDLL.lua_pushstring(L, "typeof");
            LuaDLL.lua_pushcfunction(L, GetClassType);
            LuaDLL.lua_rawset(L, -3);

            LuaDLL.lua_pushstring(L, "tolstring");
            LuaDLL.tolua_pushcfunction(L, BufferToString);
            LuaDLL.lua_rawset(L, -3);

            LuaDLL.lua_pushstring(L, "toarray");
            LuaDLL.tolua_pushcfunction(L, TableToArray);
            LuaDLL.lua_rawset(L, -3);

            //手动模拟gc
            //LuaDLL.lua_pushstring(L, "collect");
            //LuaDLL.lua_pushcfunction(L, Collect);
            //LuaDLL.lua_rawset(L, -3);

            int meta = LuaStatic.GetMetaReference(L, typeof(NullObject));

            LuaDLL.lua_pushstring(L, "null");
            LuaDLL.tolua_pushnewudata(L, meta, 1);
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pop(L, 1);

            LuaDLL.tolua_pushudata(L, 1);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "null");

#if UNITY_EDITOR
            GetToLuaInstanceID();
            GetConsoleWindowListView();
#endif
        }
示例#10
0
        //o 不为 null
        static void PushUserObject(IntPtr L, object o)
        {
            Type type      = o.GetType();
            int  reference = LuaStatic.GetMetaReference(L, type);

            if (reference > 0)
            {
                PushUserData(L, o, reference);
            }
            else
            {
                PushPreLoadType(L, o, type);
            }
        }
示例#11
0
        private static void PushUserObject(IntPtr L, object o)
        {
            Type type          = o.GetType();
            int  metaReference = LuaStatic.GetMetaReference(L, type);

            if (metaReference > 0)
            {
                ToLua.PushUserData(L, o, metaReference);
            }
            else
            {
                ToLua.PushPreLoadType(L, o, type);
            }
        }
示例#12
0
        private static void PushPreLoadType(IntPtr L, object o, Type type)
        {
            LuaCSFunction preModule = LuaStatic.GetPreModule(L, type);

            if (preModule != null)
            {
                ToLua.LuaPCall(L, preModule);
                int metaReference = LuaStatic.GetMetaReference(L, type);
                if (metaReference > 0)
                {
                    ToLua.PushUserData(L, o, metaReference);
                    return;
                }
            }
            LuaDLL.lua_pushnil(L);
            Debugger.LogError("Type {0} not wrap to lua", LuaMisc.GetTypeName(type));
        }
示例#13
0
        public static void PushValue(IntPtr L, ValueType v)
        {
            if (v == null)
            {
                LuaDLL.lua_pushnil(L);
                return;
            }

            Type             type       = v.GetType();
            int              reference  = LuaStatic.GetMetaReference(L, type);
            ObjectTranslator translator = ObjectTranslator.Get(L);

            if (reference > 0)
            {
                int index = translator.AddObject(v);
                LuaDLL.tolua_pushnewudata(L, reference, index);
            }
            else
            {
                LuaCSFunction LuaOpenLib = LuaStatic.GetPreModule(L, type);

                if (LuaOpenLib != null)
                {
#if UNITY_EDITOR
                    Debugger.LogWarning("register PreLoad type {0} to lua", LuaMisc.GetTypeName(type));
#endif
                    LuaOpenLib(L);
                    reference = LuaStatic.GetMetaReference(L, type);

                    if (reference > 0)
                    {
                        int index = translator.AddObject(v);
                        LuaDLL.tolua_pushnewudata(L, reference, index);
                        return;
                    }
                }

                //类型未Wrap
                LuaDLL.lua_pushnil(L);
                Debugger.LogError("Type {0} not wrap to lua", LuaMisc.GetTypeName(type));
            }
        }
示例#14
0
        static public int GetLuaReference(IntPtr L)
        {
#if MULTI_STATE
            return(LuaStatic.GetMetaReference(L, type));
#else
            if (metaref > 0)
            {
                return(metaref);
            }

            metaref = LuaStatic.GetMetaReference(L, type);

            if (metaref > 0)
            {
                LuaState.Get(L).OnDestroy += () => { metaref = -1; };
            }

            return(metaref);
#endif
        }
示例#15
0
        public static void OpenLibs(IntPtr L)
        {
            LuaDLL.lua_getglobal(L, "tolua");
            LuaDLL.lua_pushstring(L, "isnull");
            LuaDLL.lua_pushcfunction(L, new LuaCSFunction(ToLua.IsNull));
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pushstring(L, "tolstring");
            LuaDLL.tolua_pushcfunction(L, new LuaCSFunction(ToLua.BufferToString));
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pushstring(L, "typeof");
            LuaDLL.lua_pushcfunction(L, new LuaCSFunction(ToLua.GetClassType));
            LuaDLL.lua_rawset(L, -3);
            int metaReference = LuaStatic.GetMetaReference(L, typeof(NullObject));

            LuaDLL.lua_pushstring(L, "null");
            LuaDLL.tolua_pushnewudata(L, metaReference, 1);
            LuaDLL.lua_rawset(L, -3);
            LuaDLL.lua_pop(L, 1);
            LuaDLL.tolua_pushudata(L, 1);
            LuaDLL.lua_setfield(L, LuaIndexes.LUA_GLOBALSINDEX, "null");
        }
示例#16
0
        static void PushPreLoadType(IntPtr L, object o, Type type)
        {
            LuaCSFunction LuaOpenLib = LuaStatic.GetPreModule(L, type);

            if (LuaOpenLib != null)
            {
#if UNITY_EDITOR
                Debugger.LogWarning("register PreLoad type {0} to lua", LuaMisc.GetTypeName(type));
#endif
                LuaPCall(L, LuaOpenLib);
                int reference = LuaStatic.GetMetaReference(L, type);

                if (reference > 0)
                {
                    PushUserData(L, o, reference);
                    return;
                }
            }

            //类型未Wrap
            LuaDLL.lua_pushnil(L);
            Debugger.LogError("Type {0} not wrap to lua", LuaMisc.GetTypeName(type));
        }