Beispiel #1
0
        static public bool checkEnum <T>(IntPtr l, int p, out T o) where T : struct
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TNUMBER);
            int i = LuaDLL.lua_tointeger(l, p);

            o = (T)Enum.ToObject(typeof(T), i);

            return(true);
        }
Beispiel #2
0
        static public bool checkType(IntPtr l, int p, out LuaTable t)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TTABLE);
            LuaDLL.lua_pushvalue(l, p);
            int fref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX);

            t = new LuaTable(l, fref);
            return(true);
        }
Beispiel #3
0
        static public bool checkType(IntPtr l, int p, out char[] pars)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TSTRING);
            string s;

            checkType(l, p, out s);
            pars = s.ToCharArray();
            return(true);
        }
Beispiel #4
0
        static public bool checkType(IntPtr l, int p, out LuaFunction f)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TFUNCTION);
            LuaDLL.lua_pushvalue(l, p);
            int fref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX);

            f = new LuaFunction(l, fref);
            return(true);
        }
Beispiel #5
0
 static public void checkLuaObject(IntPtr l, int p)
 {
     LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TUSERDATA);
     LuaDLL.lua_getmetatable(l, p);
     if (LuaDLL.lua_isnil(l, -1))
     {
         LuaDLL.lua_pop(l, 1);
         LuaDLL.luaL_error(l, "expect luaobject as first argument");
     }
 }
Beispiel #6
0
        internal static int pcall(IntPtr L)
        {
            int status;

            LuaDLL.luaL_checktype(L, 1, LuaTypes.LUA_TFUNCTION);
            status = LuaDLL.lua_pcall(L, LuaDLL.lua_gettop(L) - 1, LuaDLL.LUA_MULTRET, 0);
            LuaDLL.lua_pushboolean(L, (status == 0));
            LuaDLL.lua_insert(L, 1);
            return(LuaDLL.lua_gettop(L));  /* return status + all results */
        }
Beispiel #7
0
        public static bool checkType(IntPtr l, int p, out System.Int32[] t)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TTABLE);
            int n = LuaDLL.lua_rawlen(l, p);

            t = new System.Int32[n];
            for (int k = 0; k < n; k++)
            {
                LuaDLL.lua_rawgeti(l, p, k + 1);
                checkType(l, -1, out t[k]);
                LuaDLL.lua_pop(l, 1);
            }
            return(true);
        }
Beispiel #8
0
        static public bool checkType(IntPtr l, int p, out UnityEngine.Vector2[] pars)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TTABLE);
            int n = LuaDLL.lua_rawlen(l, p);

            pars = new UnityEngine.Vector2[n];
            for (int k = 0; k < n; k++)
            {
                LuaDLL.lua_rawgeti(l, p, k + 1);
                checkType(l, -1, out pars[k]);
                LuaDLL.lua_pop(l, 1);
            }
            return(true);
        }
Beispiel #9
0
        internal static int pcall(IntPtr L)
        {
            int status;

            if (LuaDLL.lua_type(L, 1) != LuaTypes.LUA_TFUNCTION)
            {
                return(LuaObject.error(L, "arg 1 expect function"));
            }
            LuaDLL.luaL_checktype(L, 1, LuaTypes.LUA_TFUNCTION);
            status = LuaDLL.lua_pcall(L, LuaDLL.lua_gettop(L) - 1, LuaDLL.LUA_MULTRET, 0);
            LuaDLL.lua_pushboolean(L, (status == 0));
            LuaDLL.lua_insert(L, 1);
            return(LuaDLL.lua_gettop(L));  /* return status + all results */
        }
Beispiel #10
0
        static public bool checkType(IntPtr l, int p, out LuaThread lt)
        {
            if (LuaDLL.lua_isnil(l, p))
            {
                lt = null;
                return(true);
            }
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TTHREAD);
            LuaDLL.lua_pushvalue(l, p);
            int fref = LuaDLL.luaL_ref(l, LuaIndexes.LUA_REGISTRYINDEX);

            lt = new LuaThread(l, fref);
            return(true);
        }
Beispiel #11
0
        static public bool checkType(IntPtr l, int p, out object[] t)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TTABLE);
            int n = LuaDLL.lua_rawlen(l, p);

            t = new object[n];
            for (int k = 0; k < n; k++)
            {
                LuaDLL.lua_rawgeti(l, p, k + 1);
                t[k] = checkVar(l, -1);
                LuaDLL.lua_pop(l, 1);
            }
            return(true);
        }
Beispiel #12
0
        internal static int import(IntPtr l)
        {
            try
            {
                LuaDLL.luaL_checktype(l, 1, LuaTypes.LUA_TSTRING);
                string str = LuaDLL.lua_tostring(l, 1);

                string[] ns = str.Split('.');

                //start from global table, find the latest part of the name
                //the later is included in the former
                LuaDLL.lua_pushglobaltable(l);

                for (int n = 0; n < ns.Length; n++)
                {
                    LuaDLL.lua_getfield(l, -1, ns[n]);
                    if (!LuaDLL.lua_istable(l, -1))
                    {
                        return(LuaObject.error(l, "expect {0} is type table", ns));
                    }
                    LuaDLL.lua_remove(l, -2);
                }

                //travers the table and check whether the key is exit in the global table
                //if not, set the key associate the vaue in the global table
                LuaDLL.lua_pushnil(l);
                while (LuaDLL.lua_next(l, -2) != 0)
                {
                    string key = LuaDLL.lua_tostring(l, -2);
                    LuaDLL.lua_getglobal(l, key);
                    if (!LuaDLL.lua_isnil(l, -1))
                    {
                        LuaDLL.lua_pop(l, 1);
                        return(LuaObject.error(l, "{0} had existed, import can't overload it.", key));
                    }
                    LuaDLL.lua_pop(l, 1);
                    LuaDLL.lua_setglobal(l, key);
                }

                LuaDLL.lua_pop(l, 1);

                LuaObject.pushValue(l, true);
                return(1);
            }
            catch (Exception e)
            {
                return(LuaObject.error(l, e));
            }
        }
Beispiel #13
0
        static internal bool checkType(IntPtr l, int p, out float[] v)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TTABLE);
            int n = LuaDLL.lua_rawlen(l, p);

            v = new float[n];
            for (int k = 0; k < n; k++)
            {
                LuaDLL.lua_rawgeti(l, p, k + 1);
                float f;
                checkType(l, -1, out f);
                v[k] = f;
                LuaDLL.lua_pop(l, 1);
            }
            return(true);
        }
Beispiel #14
0
        static internal bool checkType(IntPtr l, int p, out string[] t)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TTABLE);
            int n = LuaDLL.lua_rawlen(l, p);

            t = new string[n];
            for (int k = 0; k < n; k++)
            {
                LuaDLL.lua_rawgeti(l, p, k + 1);
                string f;
                checkType(l, -1, out f);
                t[k] = f;
                LuaDLL.lua_pop(l, 1);
            }
            return(true);
        }
Beispiel #15
0
        public static int import(IntPtr l)
        {
            try
            {
                LuaDLL.luaL_checktype(l, 1, LuaTypes.LUA_TSTRING);
                string str = LuaDLL.lua_tostring(l, 1);

                string[] ns = str.Split('.');

                LuaDLL.lua_pushglobaltable(l);

                for (int n = 0; n < ns.Length; n++)
                {
                    LuaDLL.lua_getfield(l, -1, ns[n]);
                    if (!LuaDLL.lua_istable(l, -1))
                    {
                        return(LuaObject.error(l, "expect {0} is type table", ns));
                    }
                    LuaDLL.lua_remove(l, -2);
                }

                LuaDLL.lua_pushnil(l);
                while (LuaDLL.lua_next(l, -2) != 0)
                {
                    string key = LuaDLL.lua_tostring(l, -2);
                    LuaDLL.lua_getglobal(l, key);
                    if (!LuaDLL.lua_isnil(l, -1))
                    {
                        LuaDLL.lua_pop(l, 1);
                        return(LuaObject.error(l, "{0} had existed, import can't overload it.", key));
                    }
                    LuaDLL.lua_pop(l, 1);
                    LuaDLL.lua_setglobal(l, key);
                }

                LuaDLL.lua_pop(l, 1);

                // LuaObject.pushValue(l, true);
                // return 1;
                return(0);
            }
            catch (Exception e)
            {
                return(LuaObject.error(l, e));
            }
        }
Beispiel #16
0
        static public bool checkArray(IntPtr l, int p, out byte[] v)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TSTRING);
            int    strLen;
            IntPtr str = LuaDLL.luaS_tolstring32(l, p, out strLen);

            if (strLen > 0)
            {
                v = new byte[strLen];
                Marshal.Copy(str, v, 0, strLen);
            }
            else
            {
                v = null;
            }
            return(true);
        }
Beispiel #17
0
        static bool checkType(IntPtr l, int p, out UnityEngine.Events.UnityAction <String> ua)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TFUNCTION);
            int r = LuaDLL.luaS_checkcallback(l, p);

            ua = (String v) =>
            {
                int error = pushTry(l);
                LuaDLL.lua_getref(l, r);
                pushValue(l, v);
                if (LuaDLL.lua_pcall(l, 1, 0, error) != 0)
                {
                    LuaDLL.lua_pop(l, 1); // pop error msg
                }
                LuaDLL.lua_pop(l, 1);     // pop error function
            };
            return(true);
        }
Beispiel #18
0
        static public bool checkParams(IntPtr l, int p, out char[] pars)
        {
            int top = LuaDLL.lua_gettop(l);

            if (top == p)
            {
                if (LuaDLL.lua_type(l, p) == LuaTypes.LUA_TTABLE)
                {
                    int n = LuaDLL.lua_rawlen(l, p);
                    pars = new char[n];
                    for (int k = 0; k < n; k++)
                    {
                        LuaDLL.lua_rawgeti(l, p, k + 1);
                        checkType(l, -1, out pars[k]);
                        LuaDLL.lua_pop(l, 1);
                    }
                }
                else if (LuaDLL.lua_isnumber(l, p))
                {
                    char c;
                    checkType(l, p, out c);
                    pars = new char[] { c };
                }
                else
                {
                    LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TSTRING);
                    string s;
                    checkType(l, p, out s);
                    pars = s.ToCharArray();
                }
                return(true);
            }
            else if (top - p > 0)
            {
                pars = new char[top - p + 1];
                for (int n = p, k = 0; n <= top; n++, k++)
                {
                    checkType(l, n, out pars[k]);
                }
                return(true);
            }
            pars = new char[0];
            return(true);
        }
        static bool checkType(IntPtr l,int p,out UnityEngine.Events.UnityAction<UnityEngine.Vector2> ua) {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TFUNCTION);
            LuaDelegate ld;
            checkType(l, p, out ld);
            if (ld.d != null)
            {
                ua = (UnityEngine.Events.UnityAction<UnityEngine.Vector2>)ld.d;
                return true;
            }
			l = LuaState.get(l).L;
            ua = (UnityEngine.Vector2 v0) =>
            {
                int error = pushTry(l);
                pushValue(l,v0);
                ld.pcall(1, error);
                LuaDLL.lua_settop(l,error - 1);
            };
            ld.d = ua;
            return true;
        }
        // Token: 0x06024488 RID: 148616 RVA: 0x00CC1F90 File Offset: 0x00CC0190
        private static bool checkType(IntPtr l, int p, out UnityAction <bool> ua)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TFUNCTION);
            LuaDelegate ld;

            LuaObject.checkType(l, p, out ld);
            if (ld.d != null)
            {
                ua = (UnityAction <bool>)ld.d;
                return(true);
            }
            l  = LuaState.get(l).L;
            ua = delegate(bool v0)
            {
                int num = LuaObject.pushTry(l);
                LuaObject.pushValue(l, v0);
                ld.pcall(1, num);
                LuaDLL.lua_settop(l, num - 1);
            };
            ld.d = ua;
            return(true);
        }
        static bool checkType(IntPtr l, int p, out UnityEngine.Events.UnityAction <UnityEngine.UI.Extensions.ReorderableList.ReorderableListEventStruct> ua)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TFUNCTION);
            LuaDelegate ld;

            checkType(l, p, out ld);
            if (ld.d != null)
            {
                ua = (UnityEngine.Events.UnityAction <UnityEngine.UI.Extensions.ReorderableList.ReorderableListEventStruct>)ld.d;
                return(true);
            }
            l  = LuaState.get(l).L;
            ua = (UnityEngine.UI.Extensions.ReorderableList.ReorderableListEventStruct v) =>
            {
                int error = pushTry(l);
                pushValue(l, v);
                ld.pcall(1, error);
                LuaDLL.lua_settop(l, error - 1);
            };
            ld.d = ua;
            return(true);
        }
 static public bool checkArray(IntPtr l, int p, out char[] pars)
 {
     if (LuaDLL.lua_type(l, p) == LuaTypes.LUA_TTABLE)
     {
         int n = LuaDLL.lua_rawlen(l, p);
         pars = new char[n];
         for (int k = 0; k < n; k++)
         {
             LuaDLL.lua_rawgeti(l, p, k + 1);
             checkType(l, -1, out pars[k]);
             LuaDLL.lua_pop(l, 1);
         }
     }
     else
     {
         LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TSTRING);
         string s;
         checkType(l, p, out s);
         pars = s.ToCharArray();
     }
     return(true);
 }
Beispiel #23
0
        static bool checkType(IntPtr l, int p, out UnityEngine.Events.UnityAction <UnityEngine.EventSystems.PointerEventData.InputButton> ua)
        {
            LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TFUNCTION);
            LuaDelegate ld;

            checkType(l, p, out ld);
            if (ld.d != null)
            {
                ua = (UnityEngine.Events.UnityAction <UnityEngine.EventSystems.PointerEventData.InputButton>)ld.d;
                return(true);
            }
            l  = LuaState.get(l).L;
            ua = (UnityEngine.EventSystems.PointerEventData.InputButton v) =>
            {
                int error = pushTry(l);
                pushValue(l, v);
                ld.pcall(1, error);
                LuaDLL.lua_settop(l, error - 1);
            };
            ld.d = ua;
            return(true);
        }
Beispiel #24
0
        internal static int import(IntPtr l)
        {
            LuaDLL.luaL_checktype(l, 1, LuaTypes.LUA_TSTRING);
            string str = LuaDLL.lua_tostring(l, 1);

            string[] ns = str.Split('.');

            LuaDLL.lua_pushglobaltable(l);

            for (int n = 0; n < ns.Length; n++)
            {
                LuaDLL.lua_getfield(l, -1, ns[n]);
                if (!LuaDLL.lua_istable(l, -1))
                {
                    LuaDLL.luaL_error(l, "expect {0} is type table", ns);
                    return(0);
                }
                LuaDLL.lua_remove(l, -2);
            }

            LuaDLL.lua_pushnil(l);
            while (LuaDLL.lua_next(l, -2) != 0)
            {
                string key = LuaDLL.lua_tostring(l, -2);
                LuaDLL.lua_getglobal(l, key);
                if (!LuaDLL.lua_isnil(l, -1))
                {
                    LuaDLL.lua_pop(l, 1);
                    LuaDLL.luaL_error(l, "{0} had existed, import can't overload it.", key);
                    return(0);
                }
                LuaDLL.lua_pop(l, 1);
                LuaDLL.lua_setglobal(l, key);
            }

            LuaDLL.lua_pop(l, 1);

            return(0);
        }
Beispiel #25
0
 static public int MakeArray(IntPtr l)
 {
     try {
         Type t;
         checkType(l, 1, out t);
         LuaDLL.luaL_checktype(l, 2, LuaTypes.LUA_TTABLE);
         int   n     = LuaDLL.lua_rawlen(l, 2);
         Array array = Array.CreateInstance(t, n);
         for (int k = 0; k < n; k++)
         {
             LuaDLL.lua_rawgeti(l, 2, k + 1);
             var obj = checkVar(l, -1);
             array.SetValue(changeType(obj, t), k);
             LuaDLL.lua_pop(l, 1);
         }
         pushValue(l, true);
         pushValue(l, array);
         return(2);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }
Beispiel #26
0
 static public bool checkType(IntPtr l, int p, out uint v)
 {
     LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TNUMBER);
     v = (uint)LuaDLL.lua_tonumber(l, p);
     return(true);
 }
Beispiel #27
0
 static internal bool checkType(IntPtr l, int p, out bool v)
 {
     LuaDLL.luaL_checktype(l, p, LuaTypes.LUA_TBOOLEAN);
     v = LuaDLL.lua_toboolean(l, p);
     return(true);
 }