Exemplo n.º 1
0
        public static int IsNull(IntPtr ptr)
        {
            try
            {
                LuaTypes t = LuaNativeMethods.lua_type(ptr, 1);
                LuaObject.PushValue(ptr, true);

                if (t == LuaTypes.TYPE_NIL)
                {
                    LuaObject.PushValue(ptr, true);
                }
                else if (t == LuaTypes.TYPE_USERDATA || LuaObject.IsLuaClass(ptr, 1))
                {
                    // LUA_TUSERDATA or LUA_TTABLE(Class inherited from Unity Native)
                    object o = LuaObject.CheckObj(ptr, 1);
                    if (o is UnityEngine.Object)
                    {
                        LuaObject.PushValue(ptr, ((UnityEngine.Object)o) == null);
                    }
                    else
                    {
                        LuaObject.PushValue(ptr, o.Equals(null));
                    }
                }
                else
                {
                    LuaObject.PushValue(ptr, false);
                }

                return(2);
            }
            catch (Exception e)
            {
                return(Error(ptr, e));
            }
        }
Exemplo n.º 2
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);
            }
        }