Beispiel #1
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));
            }
        }
Beispiel #2
0
        //基础类型获取需要一个函数
        public static void PushOut <T>(IntPtr L, LuaOut <T> lo)
        {
            ObjectTranslator translator = ObjectTranslator.Get(L);
            int index        = translator.AddObject(lo);
            int outMetatable = LuaStatic.GetOutMetatable(L);

            LuaDLL.tolua_pushnewudata(L, outMetatable, index);
        }
Beispiel #3
0
        //基础类型获取需要一个函数
        public static void PushOut <T>(IntPtr L, LuaOut <T> lo)
        {
            LuaState         state      = LuaState.Get(L);
            ObjectTranslator translator = state.translator;
            int index = translator.AddObject(lo);

            LuaDLL.tolua_pushnewudata(L, state.OutMetatable, index);
        }
Beispiel #4
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));
            }
        }
Beispiel #5
0
        private static void PushUserData(IntPtr L, object o, int reference)
        {
            ObjectTranslator objectTranslator = ObjectTranslator.Get(L);
            int index;

            if (objectTranslator.Getudata(o, out index) && LuaDLL.tolua_pushudata(L, index))
            {
                return;
            }
            index = objectTranslator.AddObject(o);
            LuaDLL.tolua_pushnewudata(L, reference, index);
        }
Beispiel #6
0
        static void PushUserData(IntPtr L, object o, int reference)
        {
            int index;
            ObjectTranslator translator = ObjectTranslator.Get(L);

            if (translator.Getudata(o, out index))
            {
                if (LuaDLL.tolua_pushudata(L, index))
                {
                    return;
                }
            }

            index = translator.AddObject(o);
            LuaDLL.tolua_pushnewudata(L, reference, index);
        }
Beispiel #7
0
        private void PushUserData(object o, int meta)
        {
            int index;

            if (translator.GetUdata(o, out index))
            {
                if (LuaDLL.tolua_pushudata(L, index))
                {
                    return;
                }

                translator.DestroyUdata(index);
            }

            index = translator.AddObject(o);
            LuaDLL.tolua_pushnewudata(L, meta, index);
        }
Beispiel #8
0
        public static void PushValue(IntPtr L, ValueType v)
        {
            if (v == null)
            {
                LuaDLL.lua_pushnil(L);
                return;
            }

            LuaState state     = LuaState.Get(L);
            int      reference = state.GetMetaReference(v.GetType());

            if (reference > 0)
            {
                ObjectTranslator translator = state.translator;
                int index = translator.AddObject(v);
                LuaDLL.tolua_pushnewudata(L, reference, index);
            }
            else
            {
                //可进入反射流程
                LuaDLL.luaL_error(L, string.Format("Type {0} not register to lua", v.GetType()));
            }
        }