Exemplo n.º 1
0
 public object start(string main, int state = 0)
 {
     if (main != null)
     {
         object o = luaState[state].doFile(main);
         Helper.Release(o);
         LuaFunction func = (LuaFunction)luaState[state]["main"];
         if (func != null)
         {
             object result = null;
             try
             {
                 result = func.call();
             }
             catch (Exception e)
             {
                 SLogger.LogError(e.Message);
                 throw;
             }
             finally
             {
                 func.Dispose();
             }
             return(result);
         }
     }
     return(null);
 }
Exemplo n.º 2
0
 void checkTop(IntPtr L)
 {
     if (LuaDLL.pua_gettop(L) != errorReported)
     {
         SLogger.LogError("Some function not remove temp value from lua stack. You should fix it.");
         errorReported = LuaDLL.pua_gettop(L);
     }
 }
Exemplo n.º 3
0
        static void checkMethodValid(LuaCSFunction f)
        {
#if UNITY_EDITOR
            if (f != null && !Attribute.IsDefined(f.Method, typeof(MonoPInvokeCallbackAttribute)))
            {
                SLogger.LogError(string.Format("MonoPInvokeCallbackAttribute not defined for LuaCSFunction {0}.", f.Method));
            }
#endif
        }
Exemplo n.º 4
0
        public static int pushTry(IntPtr l)
        {
            if (!LuaState.get(l).isMainThread())
            {
                SLogger.LogError("Can't call lua function in bg thread");
                return(0);
            }

            LuaDLL.pua_pushcfunction(l, LuaState.errorFunc);
            return(LuaDLL.pua_gettop(l));
        }
Exemplo n.º 5
0
        public object doFile(string fn)
        {
            byte[] array = LuaState.loadFile(fn);
            if (array == null)
            {
                SLogger.LogError(string.Format("Can't find {0}", fn));
                return(null);
            }
            object result;

            if (this.doBuffer(array, "@" + fn, out result))
            {
                return(result);
            }
            return(null);
        }
Exemplo n.º 6
0
 public static int errorReport(IntPtr L)
 {
     LuaDLL.pua_getglobal(L, "debug");
     LuaDLL.pua_getfield(L, -1, "traceback");
     LuaDLL.pua_pushvalue(L, 1);
     LuaDLL.pua_pushnumber(L, 2.0);
     LuaDLL.pua_call(L, 2, 1);
     LuaDLL.pua_remove(L, -2);
     SLogger.LogError(LuaDLL.pua_tostring(L, -1));
     if (LuaState.errorDelegate != null)
     {
         LuaState.errorDelegate(LuaDLL.pua_tostring(L, -1));
     }
     LuaDLL.pua_pop(L, 1);
     return(0);
 }
Exemplo n.º 7
0
        public object doFile(string fn)
        {
            byte[] bytes = loadFile(fn);
            if (bytes == null)
            {
                SLogger.LogError(string.Format("Can't find {0}", fn));
                return(null);
            }

            object obj;

            if (doBuffer(bytes, "@" + fn, out obj))
            {
                return(obj);
            }
            return(null);
        }
Exemplo n.º 8
0
        void tick(LuaState ls)
        {
            if (!inited)
            {
                return;
            }

            if (LuaDLL.pua_gettop(ls.L) != errorReported)
            {
                errorReported = LuaDLL.pua_gettop(ls.L);
                SLogger.LogError(string.Format("Some function not remove temp value({0}) from lua stack. You should fix it.", LuaDLL.puaL_typename(ls.L, errorReported)));
            }

            ls.checkRef();
            // only tick once even if has multi state
            if ((timerTick++) % luaState.Length == 0)
            {
                LuaTimer.tick(Time.deltaTime);
            }
        }
Exemplo n.º 9
0
 public bool pcall(int nArgs, int errfunc)
 {
     if (!this.state.isMainThread())
     {
         SLogger.LogError("Can't call lua function in bg thread");
         return(false);
     }
     LuaDLL.pua_getref(base.L, this.valueref);
     if (!LuaDLL.pua_isfunction(base.L, -1))
     {
         LuaDLL.pua_pop(base.L, 1);
         throw new Exception("Call invalid function.");
     }
     LuaDLL.pua_insert(base.L, -nArgs - 1);
     if (LuaDLL.pua_pcall(base.L, nArgs, -1, errfunc) != 0)
     {
         LuaDLL.pua_pop(base.L, 1);
         return(false);
     }
     return(true);
 }
Exemplo n.º 10
0
        public object invoke(string func, params object[] args)
        {
            LuaFunction f = (LuaFunction)this[func];

            if (f != null)
            {
                object result = null;
                try
                {
                    result = f.call(args);
                }
                catch (Exception e)
                {
                    SLogger.LogError(e.Message);
                    throw;
                }
                finally
                {
                    f.Dispose();
                }
                return(result);
            }
            throw new Exception(string.Format("Can't find {0} function", func));
        }
Exemplo n.º 11
0
        static public object checkVar(IntPtr l, int p)
        {
            LuaTypes type = LuaDLL.pua_type(l, p);

            switch (type)
            {
            case LuaTypes.LUA_TNUMBER:
            {
                return(LuaDLL.pua_tonumber(l, p));
            }

            case LuaTypes.LUA_TSTRING:
            {
                return(LuaDLL.pua_tostring(l, p));
            }

            case LuaTypes.LUA_TBOOLEAN:
            {
                return(LuaDLL.pua_toboolean(l, p));
            }

            case LuaTypes.LUA_TFUNCTION:
            {
                LuaFunction v;
                LuaObject.checkType(l, p, out v);
                return(v);
            }

            case LuaTypes.LUA_TTABLE:
            {
                if (isLuaValueType(l, p))
                {
#if !SLUA_STANDALONE
                    if (luaTypeCheck(l, p, "Vector2"))
                    {
                        Vector2 v;
                        checkType(l, p, out v);
                        return(v);
                    }
                    else if (luaTypeCheck(l, p, "Vector3"))
                    {
                        Vector3 v;
                        checkType(l, p, out v);
                        return(v);
                    }
                    else if (luaTypeCheck(l, p, "Vector4"))
                    {
                        Vector4 v;
                        checkType(l, p, out v);
                        return(v);
                    }
                    else if (luaTypeCheck(l, p, "Quaternion"))
                    {
                        Quaternion v;
                        checkType(l, p, out v);
                        return(v);
                    }
                    else if (luaTypeCheck(l, p, "Color"))
                    {
                        Color c;
                        checkType(l, p, out c);
                        return(c);
                    }
#endif
                    SLogger.LogError("unknown lua value type");
                    return(null);
                }
                else if (isLuaClass(l, p))
                {
                    return(checkObj(l, p));
                }
                else
                {
                    LuaTable v;
                    checkType(l, p, out v);
                    return(v);
                }
            }

            case LuaTypes.LUA_TUSERDATA:
                return(LuaObject.checkObj(l, p));

            case LuaTypes.LUA_TTHREAD:
            {
                LuaThread lt;
                LuaObject.checkType(l, p, out lt);
                return(lt);
            }

            default:
                return(null);
            }
        }