Exemple #1
0
        int MyCSharpCallLua.IGetD.add(int numA, int numB)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);


            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "add");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function add");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);
            LuaAPI.xlua_pushinteger(L, numA);
            LuaAPI.xlua_pushinteger(L, numB);

            int __gen_error = LuaAPI.lua_pcall(L, 3, 1, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }


            int __gen_ret = LuaAPI.xlua_tointeger(L, err_func + 1);
            LuaAPI.lua_settop(L, err_func - 1);
            return(__gen_ret);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
Exemple #2
0
        int IFramework.Hotfix.Lua.Luac.ICalc.Add(int a, int b)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);


            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "Add");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function Add");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);
            LuaAPI.xlua_pushinteger(L, a);
            LuaAPI.xlua_pushinteger(L, b);

            int __gen_error = LuaAPI.lua_pcall(L, 3, 1, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }


            int __gen_ret = LuaAPI.xlua_tointeger(L, err_func + 1);
            LuaAPI.lua_settop(L, err_func - 1);
            return(__gen_ret);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
        void CAE.Core.ILuaPanelItem.OnLoopGridValueChanged(CAE.Core.UILoopGrid loopGrid, CAE.Core.ILuaPanelItem item, int index)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
            ObjectTranslator translator = luaEnv.translator;

            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "OnLoopGridValueChanged");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function OnLoopGridValueChanged");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);
            translator.Push(L, loopGrid);
            translator.PushAny(L, item);
            LuaAPI.xlua_pushinteger(L, index);

            int __gen_error = LuaAPI.lua_pcall(L, 4, 0, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }



            LuaAPI.lua_settop(L, err_func - 1);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
Exemple #4
0
        public void Action()
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            var L = luaEnv.L;
            //var translator = luaEnv.translator;
            int oldTop  = LuaAPI.lua_gettop(L);
            int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
            LuaAPI.lua_getref(L, luaReference);
            int error = LuaAPI.lua_pcall(L, 0, 0, errFunc);
            if (error != 0)
            {
                luaEnv.ThrowExceptionFromError(oldTop);
            }
            LuaAPI.lua_settop(L, oldTop);
#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
        void CAE.Core.ILuaPanelMgr.OnLongPressEnd(string prefabPath, UnityEngine.GameObject go)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
            ObjectTranslator translator = luaEnv.translator;

            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "OnLongPressEnd");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function OnLongPressEnd");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);
            LuaAPI.lua_pushstring(L, prefabPath);
            translator.Push(L, go);

            int __gen_error = LuaAPI.lua_pcall(L, 3, 0, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }



            LuaAPI.lua_settop(L, err_func - 1);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
        void CAE.Core.ILuaPanelMgr.OnClickItem(CAE.Core.ILuaPanelItem item, UnityEngine.Component btn)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
            ObjectTranslator translator = luaEnv.translator;

            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "OnClickItem");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function OnClickItem");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);
            translator.PushAny(L, item);
            translator.Push(L, btn);

            int __gen_error = LuaAPI.lua_pcall(L, 3, 0, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }



            LuaAPI.lua_settop(L, err_func - 1);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
        public bool recv(string package)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);


            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "recv");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function recv");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);
            LuaAPI.lua_pushstring(L, package);

            int __gen_error = LuaAPI.lua_pcall(L, 2, 1, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }


            bool __gen_ret = LuaAPI.lua_toboolean(L, err_func + 1);
            LuaAPI.lua_settop(L, err_func - 1);
            return(__gen_ret);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
Exemple #8
0
        internal static int Print(RealStatePtr L)
        {
            try
            {
                int    n = LuaAPI.lua_gettop(L);
                string s = String.Empty;

                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return(LuaAPI.luaL_error(L, "can not get tostring in print:"));
                }

                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return(LuaAPI.lua_error(L));
                    }
                    s += LuaAPI.lua_tostring(L, -1);

                    if (i != n)
                    {
                        s += "\t";
                    }

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
                //add by zhehua
                LuaTable debugTable = GameEntry.XLua.luaGlobal.Get <LuaTable>("debug");
                XLua.VoidReturnString tracebackFunc = debugTable.Get <XLua.VoidReturnString>("traceback");
                UnityEngine.Debug.Log(s + '\n' + tracebackFunc.Invoke());
                return(0);
            }
            catch (System.Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in print:" + e));
            }
        }
Exemple #9
0
        //deprecated
        public object[] Call(object[] args, Type[] returnTypes)
        {
#if THREAD_SAFT || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            int nArgs      = 0;
            var L          = luaEnv.L;
            var translator = luaEnv.translator;
            int oldTop     = LuaAPI.lua_gettop(L);

            int errFunc = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
            LuaAPI.lua_getref(L, luaReference);
            if (args != null)
            {
                nArgs = args.Length;
                for (int i = 0; i < args.Length; i++)
                {
                    translator.PushAny(L, args[i]);
                }
            }
            int error = LuaAPI.lua_pcall(L, nArgs, -1, errFunc);
            if (error != 0)
            {
                luaEnv.ThrowExceptionFromError(oldTop);
            }

            LuaAPI.lua_remove(L, errFunc);
            if (returnTypes != null)
            {
                return(translator.popValues(L, oldTop, returnTypes));
            }
            else
            {
                return(translator.popValues(L, oldTop));
            }
#if THREAD_SAFT || HOTFIX_ENABLE
        }
#endif
        }
Exemple #10
0
        public TResult Func <T1, T2, T3, T4, TResult>(T1 a1, T2 a2, T3 a3, T4 a4)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            var L          = luaEnv.L;
            var translator = luaEnv.translator;
            int oldTop     = LuaAPI.lua_gettop(L);
            int errFunc    = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
            LuaAPI.lua_getref(L, luaReference);
            translator.PushByType(L, a1);
            translator.PushByType(L, a2);
            translator.PushByType(L, a3);
            translator.PushByType(L, a4);
            int error = LuaAPI.lua_pcall(L, 4, 1, errFunc);
            if (error != 0)
            {
                luaEnv.ThrowExceptionFromError(oldTop);
            }
            TResult ret;
            try
            {
                translator.Get(L, -1, out ret);
            }
            catch (Exception e)
            {
                throw e;
            }
            finally
            {
                LuaAPI.lua_settop(L, oldTop);
            }
            return(ret);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
        void IFramework.Lua.IExchanger.exchange(System.Array arr)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
            ObjectTranslator translator = luaEnv.translator;

            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "exchange");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function exchange");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);
            translator.Push(L, arr);

            int __gen_error = LuaAPI.lua_pcall(L, 2, 0, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }



            LuaAPI.lua_settop(L, err_func - 1);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
        void CAE.Core.ILuaPanelMgr.OnClose(string prefabPath)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);


            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "OnClose");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function OnClose");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);
            LuaAPI.lua_pushstring(L, prefabPath);

            int __gen_error = LuaAPI.lua_pcall(L, 2, 0, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }



            LuaAPI.lua_settop(L, err_func - 1);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
        void CAE.Core.ILuaPanelItem.OnOpen(System.Collections.Generic.Dictionary <string, UnityEngine.Component> controls)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
            ObjectTranslator translator = luaEnv.translator;

            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "OnOpen");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function OnOpen");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);
            translator.Push(L, controls);

            int __gen_error = LuaAPI.lua_pcall(L, 2, 0, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }



            LuaAPI.lua_settop(L, err_func - 1);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
Exemple #14
0
        public object[] DoString(string chunk, string chunkName = "chunk", LuaTable env = null)
        {
#if THREAD_SAFT || HOTFIX_ENABLE
            lock (luaEnvLock)
            {
#endif
            var _L      = L;
            int oldTop  = LuaAPI.lua_gettop(_L);
            int errFunc = LuaAPI.load_error_func(_L, errorFuncRef);
            if (LuaAPI.luaL_loadbuffer(_L, chunk, chunkName) == 0)
            {
                if (env != null)
                {
                    env.push(_L);
                    LuaAPI.lua_setfenv(_L, -2);
                }

                //if (LuaAPI.lua_pcall(_L, 0, -1, errFunc) == 0)
                if (LuaAPI.lua_pcall(_L, 0, -1, 0) == 0)
                {
                    LuaAPI.lua_remove(_L, errFunc);
                    return(translator.popValues(_L, oldTop));
                }
                else
                {
                    ThrowExceptionFromError(oldTop);
                }
            }
            else
            {
                ThrowExceptionFromError(oldTop);
            }

            return(null);

#if THREAD_SAFT || HOTFIX_ENABLE
        }
#endif
        }
Exemple #15
0
        public Maria.Controller Peek()
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
            ObjectTranslator translator = luaEnv.translator;

            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "Peek");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function Peek");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);

            int __gen_error = LuaAPI.lua_pcall(L, 1, 1, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }


            Maria.Controller __gen_ret = (Maria.Controller)translator.GetObject(L, err_func + 1, typeof(Maria.Controller));
            LuaAPI.lua_settop(L, err_func - 1);
            return(__gen_ret);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
Exemple #16
0
        public void Push(Maria.Controller controller)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
            ObjectTranslator translator = luaEnv.translator;

            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "Push");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function Push");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);
            translator.Push(L, controller);

            int __gen_error = LuaAPI.lua_pcall(L, 2, 0, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }



            LuaAPI.lua_settop(L, err_func - 1);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
Exemple #17
0
        public void Update(float delta)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);


            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "Update");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function Update");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);
            LuaAPI.lua_pushnumber(L, delta);

            int __gen_error = LuaAPI.lua_pcall(L, 2, 0, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }



            LuaAPI.lua_settop(L, err_func - 1);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
Exemple #18
0
        void System.Collections.IEnumerator.Reset()
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);


            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "Reset");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function Reset");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);

            int __gen_error = LuaAPI.lua_pcall(L, 1, 0, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }



            LuaAPI.lua_settop(L, err_func - 1);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
Exemple #19
0
        internal static int Print(RealStatePtr L)
        {
            try
            {
                int    n = LuaAPI.lua_gettop(L);
                string s = String.Empty;

                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return(LuaAPI.luaL_error(L, "can not get tostring in print:"));
                }

                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return(LuaAPI.lua_error(L));
                    }
                    s += LuaAPI.lua_tostring(L, -1);

                    if (i != n)
                    {
                        s += "\t";
                    }

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
                //UnityEngine.Debug.Log("LUA: " + s);
                JW.Lua.LuaInteraction.Log(0, s);
                return(0);
            }
            catch (System.Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in print:" + e));
            }
        }
Exemple #20
0
        internal static int Print(RealStatePtr L)
        {
            try
            {
                int n = LuaAPI.lua_gettop(L);
                System.Text.StringBuilder s = new System.Text.StringBuilder();
                s.AppendFormat("[Lua] {0} ", LuaWhere(L));

                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return(LuaAPI.luaL_error(L, "can not get tostring in print:"));
                }

                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return(LuaAPI.lua_error(L));
                    }
                    s.Append(LuaAPI.lua_tostring(L, -1));

                    if (i != n)
                    {
                        s.Append("\t");
                    }

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
                LoggerHelper.Debug(s.ToString());
                return(0);
            }
            catch (System.Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in print:" + e));
            }
        }
        void CSharpCallTable_3.IGameUser.Speak()
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.L;
            int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);


            LuaAPI.lua_getref(L, luaReference);
            LuaAPI.xlua_pushasciistring(L, "Speak");
            if (0 != LuaAPI.xlua_pgettable(L, -2))
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            if (!LuaAPI.lua_isfunction(L, -1))
            {
                LuaAPI.xlua_pushasciistring(L, "no such function Speak");
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }
            LuaAPI.lua_pushvalue(L, -2);
            LuaAPI.lua_remove(L, -3);

            int __gen_error = LuaAPI.lua_pcall(L, 1, 0, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }



            LuaAPI.lua_settop(L, err_func - 1);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
Exemple #22
0
        public void Action <T1, T2>(T1 a1, T2 a2)
        {
#if THREAD_SAFT || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            var L          = luaEnv.L;
            var translator = luaEnv.translator;
            int oldTop     = LuaAPI.lua_gettop(L);
            int errFunc    = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
            LuaAPI.lua_getref(L, luaReference);
            translator.PushByType(L, a1);
            translator.PushByType(L, a2);
            int error = LuaAPI.lua_pcall(L, 2, 0, errFunc);
            if (error != 0)
            {
                luaEnv.ThrowExceptionFromError(oldTop);
            }
            LuaAPI.lua_settop(L, oldTop);
#if THREAD_SAFT || HOTFIX_ENABLE
        }
#endif
        }
Exemple #23
0
        public InvokeLua.ICalc __Gen_Delegate_Imp5(int p0, string[] p1)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.rawL;
            int err_func   = LuaAPI.load_error_func(L, errorFuncRef);
            ObjectTranslator translator = luaEnv.translator;

            LuaAPI.lua_getref(L, luaReference);

            LuaAPI.xlua_pushinteger(L, p0);
            if (p1 != null)
            {
                for (int __gen_i = 0; __gen_i < p1.Length; ++__gen_i)
                {
                    LuaAPI.lua_pushstring(L, p1[__gen_i]);
                }
            }
            ;

            int __gen_error = LuaAPI.lua_pcall(L, 1 + (p1 == null ? 0 : p1.Length), 1, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }


            InvokeLua.ICalc __gen_ret = (InvokeLua.ICalc)translator.GetObject(L, err_func + 1, typeof(InvokeLua.ICalc));
            LuaAPI.lua_settop(L, err_func - 1);
            return(__gen_ret);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
        public void __Gen_Delegate_Imp17(object p0, object p1, object[] p2)
        {
#if THREAD_SAFE || HOTFIX_ENABLE
            lock (luaEnv.luaEnvLock)
            {
#endif
            RealStatePtr L = luaEnv.rawL;
            int err_func   = LuaAPI.load_error_func(L, errorFuncRef);
            ObjectTranslator translator = luaEnv.translator;

            LuaAPI.lua_getref(L, luaReference);

            translator.PushAny(L, p0);
            translator.PushAny(L, p1);
            if (p2 != null)
            {
                for (int __gen_i = 0; __gen_i < p2.Length; ++__gen_i)
                {
                    translator.PushAny(L, p2[__gen_i]);
                }
            }
            ;

            int __gen_error = LuaAPI.lua_pcall(L, 2 + (p2 == null ? 0 : p2.Length), 0, err_func);
            if (__gen_error != 0)
            {
                luaEnv.ThrowExceptionFromError(err_func - 1);
            }



            LuaAPI.lua_settop(L, err_func - 1);

#if THREAD_SAFE || HOTFIX_ENABLE
        }
#endif
        }
        internal static int CollectLog(RealStatePtr L, out string s)
        {
            s = String.Empty;
            try
            {
                int n = LuaAPI.lua_gettop(L);

                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return(LuaAPI.luaL_error(L, "can not get tostring in print:"));
                }

                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return(LuaAPI.lua_error(L));
                    }
                    s += LuaAPI.lua_tostring(L, -1);

                    if (i != n)
                    {
                        s += "    ";
                    }

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
                return(0);
            }
            catch (System.Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in print:" + e));
            }
        }
        object IFramework.Lua.Luac.ICalc.this[int index]
        {
            get
            {
#if THREAD_SAFE || HOTFIX_ENABLE
                lock (luaEnv.luaEnvLock)
                {
#endif
                RealStatePtr L = luaEnv.L;
                int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
                ObjectTranslator translator = luaEnv.translator;

                LuaAPI.lua_getref(L, luaReference);
                LuaAPI.xlua_pushasciistring(L, "get_Item");
                if (0 != LuaAPI.xlua_pgettable(L, -2))
                {
                    luaEnv.ThrowExceptionFromError(err_func - 1);
                }
                if (!LuaAPI.lua_isfunction(L, -1))
                {
                    LuaAPI.xlua_pushasciistring(L, "no such function get_Item");
                    luaEnv.ThrowExceptionFromError(err_func - 1);
                }
                LuaAPI.lua_pushvalue(L, -2);
                LuaAPI.lua_remove(L, -3);
                LuaAPI.xlua_pushinteger(L, index);

                int __gen_error = LuaAPI.lua_pcall(L, 2, 1, err_func);
                if (__gen_error != 0)
                {
                    luaEnv.ThrowExceptionFromError(err_func - 1);
                }


                object __gen_ret = translator.GetObject(L, err_func + 1, typeof(object));
                LuaAPI.lua_settop(L, err_func - 1);
                return(__gen_ret);

#if THREAD_SAFE || HOTFIX_ENABLE
            }
#endif
            }


            set
            {
#if THREAD_SAFE || HOTFIX_ENABLE
                lock (luaEnv.luaEnvLock)
                {
#endif
                RealStatePtr L = luaEnv.L;
                int err_func   = LuaAPI.load_error_func(L, luaEnv.errorFuncRef);
                ObjectTranslator translator = luaEnv.translator;

                LuaAPI.lua_getref(L, luaReference);
                LuaAPI.xlua_pushasciistring(L, "set_Item");
                if (0 != LuaAPI.xlua_pgettable(L, -2))
                {
                    luaEnv.ThrowExceptionFromError(err_func - 1);
                }
                if (!LuaAPI.lua_isfunction(L, -1))
                {
                    LuaAPI.xlua_pushasciistring(L, "no such function set_Item");
                    luaEnv.ThrowExceptionFromError(err_func - 1);
                }
                LuaAPI.lua_pushvalue(L, -2);
                LuaAPI.lua_remove(L, -3);
                LuaAPI.xlua_pushinteger(L, index);
                translator.PushAny(L, value);

                int __gen_error = LuaAPI.lua_pcall(L, 3, 0, err_func);
                if (__gen_error != 0)
                {
                    luaEnv.ThrowExceptionFromError(err_func - 1);
                }



                LuaAPI.lua_settop(L, err_func - 1);

#if THREAD_SAFE || HOTFIX_ENABLE
            }
#endif
            }
        }
        internal static int Print(RealStatePtr L)
        {
            try
            {
                int n = LuaAPI.lua_gettop(L);

                string s = string.Empty;
                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return(LuaAPI.luaL_error(L, "can not get tostring in print:"));
                }
#if UNITY_EDITOR
                LuaAPI.luaL_where(L, 1);
                string filenameAndLine = LuaAPI.lua_tostring(L, -1);
                LuaAPI.lua_settop(L, n);
                string filename = filenameAndLine.Split(':')[0];
                filename = filename.Replace(".", "/");
                int line = int.Parse(filenameAndLine.Split(':')[1]);
                s = string.Format("[{0}.lua:{1}]:", filename, line);

                for (int i = 1; i <= n; i++)
                {
                    s += LuaAPI.lua_tostring(L, i);
                    if (i != n)
                    {
                        s += "\t";
                    }

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
#else
                for (int i = 1; i <= n; i++)
                {
                    LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                    LuaAPI.lua_pushvalue(L, i);   /* value to print */
                    if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                    {
                        return(LuaAPI.lua_error(L));
                    }
                    s += LuaAPI.lua_tostring(L, i);
                    if (i != n)
                    {
                        s += "\t";
                    }

                    LuaAPI.lua_pop(L, 1);  /* pop result */
                }
#endif
                //                 for (int i = 1; i <= n; i++)
                //                 {
                //                     LuaAPI.lua_pushvalue(L, -1);  /* function to be called */
                //                     LuaAPI.lua_pushvalue(L, i);   /* value to print */
                //                     if (0 != LuaAPI.lua_pcall(L, 1, 1, 0))
                //                     {
                //                         return LuaAPI.lua_error(L);
                //                     }
                //                     s += LuaAPI.lua_tostring(L, i);
                //                     if (i != n) s += "\t";
                //
                //                     LuaAPI.lua_pop(L, 1);  /* pop result */
                //                 }



                Debugger.Log(s);
                return(0);
            }
            catch (System.Exception e)
            {
                Debugger.LogError(e);
                return(LuaAPI.luaL_error(L, "c# exception in print:" + e));
            }
        }