Exemplo n.º 1
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.º 2
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.º 3
0
 public void Close()
 {
     if (this.L != IntPtr.Zero && LuaState.main == this)
     {
         SLogger.Log("Finalizing Lua State.");
         LuaDLL.pua_close(this.L);
         ObjectCache.del(this.L);
         ObjectCache.clear();
         LuaState.statemap.Clear();
         LuaState.oldptr   = IntPtr.Zero;
         LuaState.oldstate = null;
         this.L            = IntPtr.Zero;
         LuaState.main     = null;
     }
 }
Exemplo n.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
0
        public void Close()
        {
            if (L != IntPtr.Zero)
            {
                if (LuaState.main == this)
                {
                    SLogger.Log("Finalizing Lua State.");
                    // be careful, if you close lua vm, make sure you don't use lua state again,
                    // comment this line as default for avoid unexpected crash.
                    LuaDLL.pua_close(L);

                    ObjectCache.del(L);
                    ObjectCache.clear();

                    statemap.Clear();
                    oldptr   = IntPtr.Zero;
                    oldstate = null;
                    L        = IntPtr.Zero;

                    LuaState.main = null;
                }
            }
        }
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);
            }
        }