コード例 #1
0
        public static object CheckVar(IntPtr ptr, int p)
        {
            LuaTypes type = LuaNativeMethods.lua_type(ptr, p);

            switch (type)
            {
            case LuaTypes.TYPE_NUMBER:
                return(LuaNativeMethods.lua_tonumber(ptr, p));

            case LuaTypes.TYPE_STRING:
                return(LuaNativeMethods.lua_tostring(ptr, p));

            case LuaTypes.TYPE_BOOLEAN:
                return(LuaNativeMethods.lua_toboolean(ptr, p));

            case LuaTypes.TYPE_FUNCTION:
            {
                LuaFunction v;
                CheckType(ptr, p, out v);
                return(v);
            }

            case LuaTypes.TYPE_TABLE:
            {
                if (IsLuaValueType(ptr, p))
                {
                    if (LuaTypeCheck(ptr, p, "Vector2"))
                    {
                        Vector2 v;
                        CheckType(ptr, p, out v);
                        return(v);
                    }
                    else if (LuaTypeCheck(ptr, p, "Vector3"))
                    {
                        Vector3 v;
                        CheckType(ptr, p, out v);
                        return(v);
                    }
                    else if (LuaTypeCheck(ptr, p, "Vector4"))
                    {
                        Vector4 v;
                        CheckType(ptr, p, out v);
                        return(v);
                    }
                    else if (LuaTypeCheck(ptr, p, "Quaternion"))
                    {
                        Quaternion v;
                        CheckType(ptr, p, out v);
                        return(v);
                    }
                    else if (LuaTypeCheck(ptr, p, "Color"))
                    {
                        Color c;
                        CheckType(ptr, p, out c);
                        return(c);
                    }

                    Logger.LogError("unknown lua value type");
                    return(null);
                }
                else if (IsLuaClass(ptr, p))
                {
                    return(CheckObj(ptr, p));
                }
                else
                {
                    LuaTable v;
                    CheckType(ptr, p, out v);
                    return(v);
                }
            }

            case LuaTypes.TYPE_USERDATA:
                return(LuaObject.CheckObj(ptr, p));

            case LuaTypes.TYPE_THREAD:
            {
                LuaThread lt;
                CheckType(ptr, p, out lt);
                return(lt);
            }

            default:
                return(null);
            }
        }