Beispiel #1
0
        //抄自tolua的print处理
        public static int StaticLuaCallbacks_Print(RealStatePtr L)
        {
            try
            {
                var n = LuaAPI.lua_gettop(L);
                var s = string.Empty;
                if (0 != LuaAPI.xlua_getglobal(L, "tostring"))
                {
                    return(LuaAPI.luaL_error(L, "can not get tostring in print:"));
                }

                for (var 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 */
                }

                s = GetWhere(L, n) + s;
                Debugger.Log(s);
                return(0);
            }
            catch (Exception e)
            {
                return(LuaAPI.luaL_error(L, "c# exception in print:" + e));
            }
        }
Beispiel #2
0
 public static int toluaL_exception(IntPtr L, Exception e)
 {
     return(LuaDLL.luaL_error(L, e.Message));
 }