예제 #1
0
            object checkVar(IntPtr l, int p, Type t)
            {
                string tn = t.Name;

                switch (tn)
                {
                case "String":
                {
                    string str;
                    if (checkType(l, p, out str))
                    {
                        return(str);
                    }
                }
                break;

                case "Decimal":
                    return((decimal)LuaDLL.lua_tonumber(l, p));

                case "Int64":
                    return((long)LuaDLL.lua_tonumber(l, p));

                case "UInt64":
                    return((ulong)LuaDLL.lua_tonumber(l, p));

                case "Int32":
                    return((int)LuaDLL.lua_tointeger(l, p));

                case "UInt32":
                    return((uint)LuaDLL.lua_tointeger(l, p));

                case "Single":
                    return((float)LuaDLL.lua_tonumber(l, p));

                case "Double":
                    return((double)LuaDLL.lua_tonumber(l, p));

                case "Boolean":
                    return((bool)LuaDLL.lua_toboolean(l, p));

                case "Byte":
                    return((byte)LuaDLL.lua_tointeger(l, p));

                case "UInt16":
                    return((ushort)LuaDLL.lua_tointeger(l, p));

                case "Int16":
                    return((short)LuaDLL.lua_tointeger(l, p));

                default:
                    // Enum convert
                    if (t.IsEnum)
                    {
                        var num = LuaDLL.lua_tointeger(l, p);
                        return(Enum.ToObject(t, num));
                    }
                    return(LuaObject.checkVar(l, p));
                }
                return(null);
            }
예제 #2
0
        internal object topObjects(int from)
        {
            int top   = LuaDLL.lua_gettop(L);
            int nArgs = top - from;

            if (nArgs == 0)
            {
                return(null);
            }
            else if (nArgs == 1)
            {
                object o = LuaObject.checkVar(L, top);
                LuaDLL.lua_pop(L, 1);
                return(o);
            }
            else
            {
                object[] o = new object[nArgs];
                for (int n = 1; n <= nArgs; n++)
                {
                    o[n - 1] = LuaObject.checkVar(L, from + n);
                }
                LuaDLL.lua_settop(L, from);
                return(o);
            }
        }
예제 #3
0
            object checkVar(IntPtr l, int p, Type t)
            {
                string tn = t.Name;

                switch (tn)
                {
                case "String":
                    return(LuaDLL.lua_tostring(l, p));

                case "Int32":
                    return((int)LuaDLL.lua_tointeger(l, p));

                case "Uint32":
                    return((uint)LuaDLL.lua_tointeger(l, p));

                case "Single":
                    return((float)LuaDLL.lua_tonumber(l, p));

                case "Double":
                    return((double)LuaDLL.lua_tonumber(l, p));

                case "Boolean":
                    return(LuaDLL.lua_toboolean(l, p));

                default:
                    return(LuaObject.checkVar(l, p));
                }
            }
예제 #4
0
파일: LuaThread.cs 프로젝트: bmanGH/slua
        public LuaThreadStatus Resume()
        {
            if (!state.isMainThread())
            {
                Logger.LogError("Can't resume lua thread in bg thread");
                return(LuaThreadStatus.LUA_ERRERR);
            }

            yieldResult = null;

            IntPtr L = state.L;

            push(L);
            IntPtr threadL = LuaDLL.lua_tothread(L, -1);

            LuaDLL.lua_pop(L, 1);

            int ret = LuaDLL.lua_resume(threadL, 0);

            if (ret > (int)LuaThreadStatus.LUA_YIELD)
            {
                LuaObject.pushTry(threadL);
                LuaDLL.lua_pushthread(threadL);
                LuaDLL.lua_pushvalue(threadL, -3);                 // error message
                LuaDLL.lua_call(threadL, 2, 0);

                LuaDLL.lua_settop(threadL, 0);
            }
            else
            {
                int top = LuaDLL.lua_gettop(threadL);
                if (top > 0)
                {
                    if (top == 1)
                    {
                        yieldResult = LuaObject.checkVar(threadL, top);
                        LuaDLL.lua_pop(threadL, 1);
                    }
                    else
                    {
                        object[] o = new object[top];
                        for (int n = 1; n <= top; n++)
                        {
                            o [n - 1] = LuaObject.checkVar(threadL, n);
                        }
                        LuaDLL.lua_settop(L, 0);
                        yieldResult = o;
                    }
                }
            }

            return((LuaThreadStatus)ret);
        }
예제 #5
0
파일: LuaState.cs 프로젝트: lulersoft/slua
        public object call(params object[] args)
        {
            LuaDLL.lua_pushstdcallcfunction(l, LuaState.errorReport);
            int error = LuaDLL.lua_gettop(l);

            if (error != 1)
            {
                Debug.Log("Some function push more value to lua stack");
            }

            LuaDLL.lua_getref(l, valueref);
            if (!LuaDLL.lua_isfunction(l, -1))
            {
                LuaDLL.lua_pop(l, 1);
                throw new Exception("Not a function");
            }

            for (int n = 0; n < args.Length; n++)
            {
                LuaObject.pushVar(l, args[n]);
            }

            if (LuaDLL.lua_pcall(l, args.Length, LuaDLL.LUA_MULTRET, error) != 0)
            {
                LuaDLL.lua_pop(l, 1);
            }

            LuaDLL.lua_remove(l, error); // pop error function

            int top = LuaDLL.lua_gettop(l);

            if (top == 0)
            {
                return(null);
            }
            else if (top == 1)
            {
                object o = LuaObject.checkVar(l, 1);
                LuaDLL.lua_pop(l, 1);
                return(o);
            }
            else
            {
                object[] o = new object[top];
                for (int n = 1; n <= top; n++)
                {
                    o[n - 1] = LuaObject.checkVar(l, n);
                }
                LuaDLL.lua_pop(l, top);
                return(o);
            }
        }
예제 #6
0
파일: LuaState.cs 프로젝트: LuffyPan/slua
 internal object getObject(int reference, int index)
 {
     if (index >= 1)
     {
         int oldTop = LuaDLL.lua_gettop(L);
         LuaDLL.lua_getref(L, reference);
         LuaDLL.lua_rawgeti(L, -1, index);
         object returnValue = LuaObject.checkVar(L, -1);
         LuaDLL.lua_settop(L, oldTop);
         return(returnValue);
     }
     throw new IndexOutOfRangeException();
 }
예제 #7
0
 // Token: 0x060001B9 RID: 441 RVA: 0x0000941C File Offset: 0x0000761C
 private object TopObjects(int nArgs)
 {
     if (nArgs == 0)
     {
         return(null);
     }
     if (nArgs == 1)
     {
         return(LuaObject.checkVar(this._thread, -1));
     }
     object[] array = new object[nArgs];
     for (int i = 1; i <= nArgs; i++)
     {
         array[i - 1] = LuaObject.checkVar(this._thread, i);
     }
     return(array);
 }
예제 #8
0
        // NOTE
        // Beaware of these Call() functions
        // They use [] to access values, causes GC alloc when splitting fields
        // Use OneLevelCall() whenever possible

        // fast lookup one level field, do not try to support path like 'a.b.c.d'
        public static object getOneLevelField(this LuaState luaState, string field)
        {
            IntPtr L = luaState.L;

            LuaDLL.lua_pushglobaltable(L);

            object returnValue = null;

            LuaDLL.lua_pushstring(L, field);
            LuaDLL.lua_gettable(L, -2);
            int p = LuaDLL.lua_absindex(L, -1);

            returnValue = LuaObject.checkVar(L, p);
            LuaDLL.lua_remove(L, -2);

            LuaDLL.lua_pop(L, 1);

            return(returnValue);
        }
예제 #9
0
            object checkVar(IntPtr l, int p, Type t)
            {
                string tn = t.Name;

                switch (tn)
                {
                case "String":
                {
                    string str;
                    if (checkType(l, p, out str))
                    {
                        return(str);
                    }
                }
                break;

                case "Int32":
                    return((int)LuaDLL.lua_tointeger(l, p));

                case "UInt32":
                    return((uint)LuaDLL.lua_tointeger(l, p));

                case "Single":
                    return((float)LuaDLL.lua_tonumber(l, p));

                case "Double":
                    return((double)LuaDLL.lua_tonumber(l, p));

                case "Boolean":
                    return(LuaDLL.lua_toboolean(l, p));

                default:
                    // Enum convert
                    if (t.BaseType == typeof(System.Enum))
                    {
                        var num = LuaDLL.lua_tointeger(l, p);
                        return(Enum.ToObject(t, num));
                    }
                    return(LuaObject.checkVar(l, p));
                }
                return(null);
            }
예제 #10
0
 private object TopObjects(int nArgs)
 {
     if (nArgs == 0)
     {
         return(null);
     }
     else if (nArgs == 1)
     {
         object o = LuaObject.checkVar(_thread, -1);
         return(o);
     }
     else
     {
         object[] o = new object[nArgs];
         for (int n = 1; n <= nArgs; n++)
         {
             o[n - 1] = LuaObject.checkVar(_thread, n);
         }
         return(o);
     }
 }
예제 #11
0
        // fast lookup one level field, do not try to support path like 'a.b.c.d'
        public static object getOneLevelField(this LuaState luaState, int reference, string field)
        {
            IntPtr L = luaState.L;

            // int oldTop = LuaDLL.lua_gettop(L);
            LuaDLL.lua_getref(L, reference);

            object returnValue = null;

            LuaDLL.lua_pushstring(L, field);
            LuaDLL.lua_gettable(L, -2);
            int p = LuaDLL.lua_absindex(L, -1);

            returnValue = LuaObject.checkVar(L, p);
            LuaDLL.lua_remove(L, -2);

            LuaDLL.lua_pop(L, 1);

            // LuaDLL.lua_settop(L, oldTop);
            return(returnValue);
        }
예제 #12
0
            object checkVar(IntPtr l, int p, Type t)
            {
                string tn = t.Name;

                switch (tn)
                {
                case "String":
                {
                    string str;
                    if (checkType(l, p, out str))
                    {
                        return(str);
                    }
                }
                break;

                case "Int32":
                    return((int)LuaDLL.lua_tointeger(l, p));

                case "Uint32":
                    return((uint)LuaDLL.lua_tointeger(l, p));

                case "Single":
                    return((float)LuaDLL.lua_tonumber(l, p));

                case "Double":
                    return((double)LuaDLL.lua_tonumber(l, p));

                case "Boolean":
                    return(LuaDLL.lua_toboolean(l, p));

                default:
                    return(LuaObject.checkVar(l, p));
                }
                return(null);
            }
예제 #13
0
 object getObject(IntPtr l, int p)
 {
     p = LuaDLL.lua_absindex(l, p);
     return(LuaObject.checkVar(l, p));
 }
예제 #14
0
파일: LuaState.cs 프로젝트: LuffyPan/slua
 object getObject(IntPtr l, int p)
 {
     return(LuaObject.checkVar(l, p));
 }