Ejemplo n.º 1
0
        public static int PrintError(IntPtr ptr)
        {
            int n = LuaNativeMethods.lua_gettop(ptr);

            s.Length = 0;

            LuaNativeMethods.lua_getglobal(ptr, "tostring");

            for (int i = 1; i <= n; i++)
            {
                if (i > 1)
                {
                    s.Append("    ");
                }

                LuaNativeMethods.lua_pushvalue(ptr, -1);
                LuaNativeMethods.lua_pushvalue(ptr, i);

                LuaNativeMethods.lua_call(ptr, 1, 1);
                s.Append(LuaNativeMethods.lua_tostring(ptr, -1));
                LuaNativeMethods.lua_pop(ptr, 1);
            }

            LuaNativeMethods.lua_settop(ptr, n);

            LuaNativeMethods.lua_getglobal(ptr, "debug");
            LuaNativeMethods.lua_getfield(ptr, -1, "traceback");
            LuaNativeMethods.lua_call(ptr, 0, 1);
            s.Append("\n");
            s.Append(LuaNativeMethods.lua_tostring(ptr, -1));
            LuaNativeMethods.lua_pop(ptr, 1);
            Logger.LogError(s.ToString(), true);

            if (ErrorEvent != null)
            {
                ErrorEvent(s.ToString());
            }

            return(0);
        }
Ejemplo n.º 2
0
        public static int DoFile(IntPtr ptr)
        {
            int n = LuaNativeMethods.lua_gettop(ptr);

            Loader(ptr);
            if (!LuaNativeMethods.lua_toboolean(ptr, -2))
            {
                return(2);
            }
            else
            {
                if (LuaNativeMethods.lua_isnil(ptr, -1))
                {
                    string fileName = LuaNativeMethods.lua_tostring(ptr, 1);
                    return(LuaObject.Error(ptr, "Can't find {0}", fileName));
                }

                int k = LuaNativeMethods.lua_gettop(ptr);
                LuaNativeMethods.lua_call(ptr, 0, LuaNativeMethods.LUAMultRet);
                k = LuaNativeMethods.lua_gettop(ptr);
                return(k - n);
            }
        }
Ejemplo n.º 3
0
        public static int ErrorReport(IntPtr ptr)
        {
            LuaNativeMethods.lua_getglobal(ptr, "debug");
            LuaNativeMethods.lua_getfield(ptr, -1, "traceback");
            LuaNativeMethods.lua_pushvalue(ptr, 1);
            LuaNativeMethods.lua_pushnumber(ptr, 2);
            LuaNativeMethods.lua_call(ptr, 2, 1);
            LuaNativeMethods.lua_remove(ptr, -2);
            string error = LuaNativeMethods.lua_tostring(ptr, -1);

            LuaNativeMethods.lua_pop(ptr, 1);

            Logger.LogError(error, true);
            if (ErrorEvent != null)
            {
                ErrorEvent(error);
            }

            LuaNativeMethods.lua_getglobal(ptr, "dumpstack");
            LuaNativeMethods.lua_call(ptr, 0, 0);

            return(0);
        }
Ejemplo n.º 4
0
 public static void PushCSFunction(IntPtr ptr, LuaCSFunction function)
 {
     LuaNativeMethods.lua_getref(ptr, Get(ptr).callCSFunctionRef);
     LuaNativeMethods.lua_pushcclosure(ptr, function, 0);
     LuaNativeMethods.lua_call(ptr, 1, 1);
 }