예제 #1
0
        static public object checkVar(IntPtr l, int p)
        {
            LuaTypes type = LuaDLL.lua_type(l, p);

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

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

            case LuaTypes.LUA_TBOOLEAN:
            {
                return(LuaDLL.lua_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);
                    }
                    else if (luaTypeCheck(l, p, "Rect"))
                    {
                        Rect rect;
                        checkType(l, p, out rect);
                        return(rect);
                    }
                    else if (luaTypeCheck(l, p, "Bounds"))
                    {
                        Bounds bound;
                        checkType(l, p, out bound);
                        return(bound);
                    }
#endif
                    Logger.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);
            }
        }
예제 #2
0
 object getObject(IntPtr l, int p)
 {
     p = LuaDLL.lua_absindex(l, p);
     return(LuaObject.checkVar(l, p));
 }
예제 #3
0
 public T cast <T>() where T : class
 {
     return(LuaObject.delegateCast(this, typeof(T)) as T);
 }
예제 #4
0
        void setupPushVar()
        {
            typePushMap[typeof(float)] = (IntPtr L, object o) =>
            {
                LuaDLL.lua_pushnumber(L, (float)o);
            };
            typePushMap[typeof(double)] = (IntPtr L, object o) =>
            {
                LuaDLL.lua_pushnumber(L, (double)o);
            };

            typePushMap[typeof(int)] =
                (IntPtr L, object o) =>
            {
                LuaDLL.lua_pushinteger(L, (int)o);
            };

            typePushMap[typeof(uint)] =
                (IntPtr L, object o) =>
            {
                LuaDLL.lua_pushnumber(L, Convert.ToUInt32(o));
            };

            typePushMap[typeof(short)] =
                (IntPtr L, object o) =>
            {
                LuaDLL.lua_pushinteger(L, (short)o);
            };

            typePushMap[typeof(ushort)] =
                (IntPtr L, object o) =>
            {
                LuaDLL.lua_pushinteger(L, (ushort)o);
            };

            typePushMap[typeof(sbyte)] =
                (IntPtr L, object o) =>
            {
                LuaDLL.lua_pushinteger(L, (sbyte)o);
            };

            typePushMap[typeof(byte)] =
                (IntPtr L, object o) =>
            {
                LuaDLL.lua_pushinteger(L, (byte)o);
            };


            typePushMap[typeof(Int64)]      =
                typePushMap[typeof(UInt64)] =
                    (IntPtr L, object o) =>
            {
#if LUA_5_3
                LuaDLL.lua_pushinteger(L, (long)o);
#else
                LuaDLL.lua_pushnumber(L, System.Convert.ToDouble(o));
#endif
            };

            typePushMap[typeof(string)] = (IntPtr L, object o) =>
            {
                LuaDLL.lua_pushstring(L, (string)o);
            };

            typePushMap[typeof(bool)] = (IntPtr L, object o) =>
            {
                LuaDLL.lua_pushboolean(L, (bool)o);
            };

            typePushMap[typeof(LuaTable)]          =
                typePushMap[typeof(LuaFunction)]   =
                    typePushMap[typeof(LuaThread)] =
                        (IntPtr L, object o) =>
            {
                ((LuaVar)o).push(L);
            };

            typePushMap[typeof(LuaCSFunction)] = (IntPtr L, object o) =>
            {
                LuaObject.pushValue(L, (LuaCSFunction)o);
            };
        }
예제 #5
0
        public static int Add(IntPtr l)
        {
            try{
                int top = LuaDLL.lua_gettop(l);
                if (top == 2)
                {
                    int delay;
                    checkType(l, 1, out delay);
                    LuaDelegate ld;
                    checkType(l, 2, out ld);
                    Action <int> ua;
                    if (ld.d != null)
                    {
                        ua = (Action <int>)ld.d;
                    }
                    else
                    {
                        IntPtr ml = LuaState.get(l).L;
                        ua = (int id) =>
                        {
                            int error = pushTry(ml);
                            pushValue(ml, id);
                            ld.pcall(1, error);
                            LuaDLL.lua_settop(ml, error - 1);
                        };
                    }
                    ld.d = ua;
                    pushValue(l, true);
                    pushValue(l, add(l, delay, ua));
                    return(2);
                }
                else if (top == 3)
                {
                    int delay, cycle;
                    checkType(l, 1, out delay);
                    checkType(l, 2, out cycle);
                    LuaDelegate ld;
                    checkType(l, 3, out ld);
                    Func <int, bool> ua;

                    if (ld.d != null)
                    {
                        ua = (Func <int, bool>)ld.d;
                    }
                    else
                    {
                        IntPtr ml = LuaState.get(l).L;
                        ua = (int id) =>
                        {
                            int error = pushTry(ml);
                            pushValue(ml, id);
                            ld.pcall(1, error);
                            bool ret = LuaDLL.lua_toboolean(ml, -1);
                            LuaDLL.lua_settop(ml, error - 1);
                            return(ret);
                        };
                    }
                    ld.d = ua;
                    pushValue(l, true);
                    pushValue(l, add(l, delay, cycle, ua));
                    return(2);
                }
                return(LuaObject.error(l, "Argument error"));
            }catch (Exception e)
            {
                return(LuaObject.error(l, e));
            }
        }
예제 #6
0
        public static void Register(IntPtr ptr)
        {
#if !LUA_5_3
            // lua implemented valuetype isn't faster than raw under non-jit.
            LuaState ls = LuaState.Get(ptr);
            ls.RegisterPushVar(typeof(UnityEngine.Vector2), (IntPtr _ptr, object o) => { LuaObject.PushValue(_ptr, (UnityEngine.Vector2)o); });
            ls.RegisterPushVar(typeof(UnityEngine.Vector3), (IntPtr _ptr, object o) => { LuaObject.PushValue(_ptr, (UnityEngine.Vector3)o); });
            ls.RegisterPushVar(typeof(UnityEngine.Vector4), (IntPtr _ptr, object o) => { LuaObject.PushValue(_ptr, (UnityEngine.Vector4)o); });
            ls.RegisterPushVar(typeof(UnityEngine.Quaternion), (IntPtr _ptr, object o) => { LuaObject.PushValue(_ptr, (UnityEngine.Quaternion)o); });
            ls.RegisterPushVar(typeof(UnityEngine.Color), (IntPtr _ptr, object o) => { LuaObject.PushValue(_ptr, (UnityEngine.Color)o); });
            ls.DoString(Script, "ValueTypeScript");
#endif
        }