Beispiel #1
0
			bool matchType(IntPtr l, int p, LuaTypes lt, Type t)
			{
				string tn = t.Name;

				switch (tn)
				{
					case "String":
						return lt == LuaTypes.LUA_TSTRING;
					case "Int32":
					case "Uint32":
					case "Single":
					case "Double":
						return lt == LuaTypes.LUA_TNUMBER;
					default:
						{
							switch (lt)
							{
								case LuaTypes.LUA_TFUNCTION:
									return tn == "LuaFunction" || t.BaseType == typeof(MulticastDelegate);
								case LuaTypes.LUA_TTABLE:
									return tn == "LuaTable" || LuaObject.luaTypeCheck(l, p, tn);
								default:
									return lt == LuaTypes.LUA_TUSERDATA || tn == "Object";
							}
						}
				}
			}
Beispiel #2
0
			bool matchType(IntPtr l, int p, LuaTypes lt, Type t)
			{
				if (t.IsPrimitive)
					return lt == LuaTypes.LUA_TNUMBER;

				if (t == typeof(string))
					return lt == LuaTypes.LUA_TSTRING;

				switch (lt)
				{
					case LuaTypes.LUA_TFUNCTION:
						return t==typeof(LuaFunction) || t.BaseType == typeof(MulticastDelegate);
					case LuaTypes.LUA_TTABLE:
						return t == typeof(LuaTable) || LuaObject.luaTypeCheck(l, p, t.Name);
					default:
						return lt == LuaTypes.LUA_TUSERDATA || t == typeof(object);
				}
			}
Beispiel #3
0
    static int set_normal(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name normal");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index normal on a nil value");
            }
        }

        RaycastHit2D obj = (RaycastHit2D)o;

        obj.normal = LuaScriptMgr.GetNetObject <Vector2>(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
Beispiel #4
0
    static int set_max(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name max");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index max on a nil value");
            }
        }

        Bounds obj = (Bounds)o;

        obj.max = LuaScriptMgr.GetVector3(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
            bool matchType(IntPtr l, int p, LuaTypes lt, Type t)
            {
                if (t.IsPrimitive)
                {
                    return(lt == LuaTypes.LUA_TNUMBER);
                }

                if (t == typeof(string))
                {
                    return(lt == LuaTypes.LUA_TSTRING);
                }

                switch (lt)
                {
                case LuaTypes.LUA_TFUNCTION:
                    return(t == typeof(LuaFunction) || t.BaseType == typeof(MulticastDelegate));

                case LuaTypes.LUA_TTABLE:
                    return(t == typeof(LuaTable) || LuaObject.luaTypeCheck(l, p, t.Name));

                default:
                    return(lt == LuaTypes.LUA_TUSERDATA || t == typeof(object));
                }
            }
Beispiel #6
0
    static int set_motorSpeed(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name motorSpeed");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index motorSpeed on a nil value");
            }
        }

        JointMotor2D obj = (JointMotor2D)o;

        obj.motorSpeed = (float)LuaScriptMgr.GetNumber(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
Beispiel #7
0
    private static int set_onClick(IntPtr L)
    {
        object          luaObject       = LuaScriptMgr.GetLuaObject(L, 1);
        TestLuaDelegate testLuaDelegate = (TestLuaDelegate)luaObject;

        if (testLuaDelegate == null)
        {
            LuaTypes luaTypes = LuaDLL.lua_type(L, 1);
            if (luaTypes == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name onClick");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index onClick on a nil value");
            }
        }
        LuaTypes luaTypes2 = LuaDLL.lua_type(L, 3);

        if (luaTypes2 != LuaTypes.LUA_TFUNCTION)
        {
            testLuaDelegate.onClick = (TestLuaDelegate.VoidDelegate)LuaScriptMgr.GetNetObject(L, 3, typeof(TestLuaDelegate.VoidDelegate));
        }
        else
        {
            LuaFunction func = LuaScriptMgr.ToLuaFunction(L, 3);
            testLuaDelegate.onClick = delegate(GameObject param0)
            {
                int oldTop = func.BeginPCall();
                LuaScriptMgr.Push(L, param0);
                func.PCall(oldTop, 1);
                func.EndPCall(oldTop);
            };
        }
        return(0);
    }
Beispiel #8
0
        public void Get(RealStatePtr L, int index, out UnityEngine.TouchPhase val)
        {
            LuaTypes type = LuaAPI.lua_type(L, index);

            if (type == LuaTypes.LUA_TUSERDATA)
            {
                if (LuaAPI.xlua_gettypeid(L, index) != UnityEngineTouchPhase_TypeID)
                {
                    throw new Exception("invalid userdata for UnityEngine.TouchPhase");
                }

                IntPtr buff = LuaAPI.lua_touserdata(L, index);
                int    e;
                if (!CopyByValue.UnPack(buff, 0, out e))
                {
                    throw new Exception("unpack fail for UnityEngine.TouchPhase");
                }
                val = (UnityEngine.TouchPhase)e;
            }
            else
            {
                val = (UnityEngine.TouchPhase)objectCasters.GetCaster(typeof(UnityEngine.TouchPhase))(L, index, null);
            }
        }
Beispiel #9
0
    static int set_distance(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name distance");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index distance on a nil value");
            }
        }

        Plane obj = (Plane)o;

        obj.distance = (float)LuaScriptMgr.GetNumber(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
    static int set_onClick(IntPtr L)
    {
        TestEventListener obj = (TestEventListener)ToLua.ToObject(L, 1);

        TestEventListener.OnClick arg0 = null;
        LuaTypes funcType2             = LuaDLL.lua_type(L, 2);

        if (funcType2 != LuaTypes.LUA_TFUNCTION)
        {
            arg0 = (TestEventListener.OnClick)ToLua.CheckObject(L, 2, typeof(TestEventListener.OnClick));
        }
        else
        {
            LuaFunction func = ToLua.ToLuaFunction(L, 2);
            arg0 = DelegateFactory.CreateDelegate(L, typeof(TestEventListener.OnClick), func) as TestEventListener.OnClick;
        }

        try
        {
            obj.onClick = arg0;
        }
        catch (Exception e)
        {
            if (obj == null)
            {
                LuaDLL.luaL_error(L, "attempt to index onClick on a nil value");
            }
            else
            {
                LuaDLL.luaL_error(L, e.Message);
            }
            return(0);
        }

        return(0);
    }
Beispiel #11
0
    static int set_axisLength(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name axisLength");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index axisLength on a nil value");
            }
        }

        HumanLimit obj = (HumanLimit)o;

        obj.axisLength = (float)LuaScriptMgr.GetNumber(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
Beispiel #12
0
    static int set_center(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name center");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index center on a nil value");
            }
        }

        HumanLimit obj = (HumanLimit)o;

        obj.center = LuaScriptMgr.GetNetObject <Vector3>(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
Beispiel #13
0
    static int set_useDefaultValues(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name useDefaultValues");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index useDefaultValues on a nil value");
            }
        }

        HumanLimit obj = (HumanLimit)o;

        obj.useDefaultValues = LuaScriptMgr.GetBoolean(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
Beispiel #14
0
    static int set_forward(IntPtr L)
    {
        object     o   = LuaScriptMgr.GetLuaObject(L, 1);
        GameObject obj = (GameObject)o;

        if (obj == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name forward");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index forward on a nil value");
            }
        }

        Transform transform = GameObjectUtil.GetGameObjTransform(obj);
        var       forward   = transform.forward;

        LuaScriptMgr.SetVector3FromLua(L, 3, ref forward);
        if (!forward.IsZero())
        {
            transform.forward = forward;
        }

//         var forward = obj.transform.forward;
//         LuaScriptMgr.SetVector3FromLua(L, 3, ref forward);
//         if(forward != Vector3.zero)
//             obj.transform.forward = forward;

        //obj.transform.forward = LuaScriptMgr.GetVector3(L, 3);
        return(0);
    }
Beispiel #15
0
    static int set_fraction(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name fraction");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index fraction on a nil value");
            }
        }

        RaycastHit2D obj = (RaycastHit2D)o;

        obj.fraction = (float)LuaScriptMgr.GetNumber(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
Beispiel #16
0
    public static bool GetResult(out Color32 res)
    {
        bool ret = false;

        if (s_ResIndex > s_ResNum)
        {
            res = new Color32();
            return(ret);
        }
        int from = s_From + s_ResIndex;

        ++s_ResIndex;
        var L = s_Func.L;

        LuaTypes type = LuaDLL.lua_type(L, from);

        if (type == LuaTypes.LUA_TTABLE && LuaDLL.luaS_checkluatype(L, from, null) == 1)
        {
            if (LuaObject.luaTypeCheck(L, from, "Color"))
            {
                Color c;
                LuaObject.checkType(L, from, out c);
                res = c;
                ret = true;
            }
            else
            {
                res = new Color32();
            }
        }
        else
        {
            res = new Color32();
        }
        return(ret);
    }
Beispiel #17
0
    static int Yield(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        Timer    obj       = (Timer)LuaScriptMgr.GetUnityObjectSelf(L, 1, "Timer");
        int      arg0      = (int)LuaScriptMgr.GetNumber(L, 2);
        Action   arg1      = null;
        LuaTypes funcType3 = LuaDLL.lua_type(L, 3);

        if (funcType3 != LuaTypes.LUA_TFUNCTION)
        {
            arg1 = (Action)LuaScriptMgr.GetNetObject(L, 3, typeof(Action));
        }
        else
        {
            LuaFunction func = LuaScriptMgr.GetLuaFunction(L, 3);
            arg1 = () =>
            {
                func.Call();
            };
        }

        obj.Yield(arg0, arg1);
        return(0);
    }
Beispiel #18
0
    static int set_size(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name size");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index size on a nil value");
            }
        }

        Rect obj = (Rect)o;

        obj.size = LuaScriptMgr.GetVector2(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
Beispiel #19
0
    public static bool GetResult(out bool res)
    {
        bool ret = false;

        if (s_ResIndex > s_ResNum)
        {
            res = false;
            return(ret);
        }
        int from = s_From + s_ResIndex;

        ++s_ResIndex;
        var L = s_Func.L;

        LuaTypes type = LuaDLL.lua_type(L, from);

        switch (type)
        {
        case LuaTypes.LUA_TBOOLEAN: {
            res = LuaDLL.lua_toboolean(L, from);
            ret = true;
            break;
        }

        case LuaTypes.LUA_TSTRING: {
            res = bool.Parse(LuaDLL.lua_tostring(L, from));
            ret = true;
            break;
        }

        default:
            res = false;
            break;
        }
        return(ret);
    }
Beispiel #20
0
    static int Talk(IntPtr L)
    {
        LuaScriptMgr.CheckArgsCount(L, 3);
        TalkToNPC     obj       = (TalkToNPC)LuaScriptMgr.GetUnityObjectSelf(L, 1, "TalkToNPC");
        List <string> arg0      = (List <string>)LuaScriptMgr.GetNetObject(L, 2, typeof(List <string>));
        OnTalkFinish  arg1      = null;
        LuaTypes      funcType3 = LuaDLL.lua_type(L, 3);

        if (funcType3 != LuaTypes.LUA_TFUNCTION)
        {
            arg1 = (OnTalkFinish)LuaScriptMgr.GetNetObject(L, 3, typeof(OnTalkFinish));
        }
        else
        {
            LuaFunction func = LuaScriptMgr.GetLuaFunction(L, 3);
            arg1 = () =>
            {
                func.Call();
            };
        }

        obj.Talk(arg0, arg1);
        return(0);
    }
Beispiel #21
0
    public static bool GetResult(out double res)
    {
        bool ret = false;

        if (s_ResIndex > s_ResNum)
        {
            res = 0;
            return(ret);
        }
        int from = s_From + s_ResIndex;

        ++s_ResIndex;
        var L = s_Func.L;

        LuaTypes type = LuaDLL.lua_type(L, from);

        switch (type)
        {
        case LuaTypes.LUA_TNUMBER: {
            res = (double)LuaDLL.lua_tonumber(L, from);
            ret = true;
            break;
        }

        case LuaTypes.LUA_TSTRING: {
            res = double.Parse(LuaDLL.lua_tostring(L, from));
            ret = true;
            break;
        }

        default:
            res = 0;
            break;
        }
        return(ret);
    }
Beispiel #22
0
        public void Get(RealStatePtr L, int index, out VVMUI.Script.XLua.XLuaCommandType val)
        {
            LuaTypes type = LuaAPI.lua_type(L, index);

            if (type == LuaTypes.LUA_TUSERDATA)
            {
                if (LuaAPI.xlua_gettypeid(L, index) != VVMUIScriptXLuaXLuaCommandType_TypeID)
                {
                    throw new Exception("invalid userdata for VVMUI.Script.XLua.XLuaCommandType");
                }

                IntPtr buff = LuaAPI.lua_touserdata(L, index);
                int    e;
                if (!CopyByValue.UnPack(buff, 0, out e))
                {
                    throw new Exception("unpack fail for VVMUI.Script.XLua.XLuaCommandType");
                }
                val = (VVMUI.Script.XLua.XLuaCommandType)e;
            }
            else
            {
                val = (VVMUI.Script.XLua.XLuaCommandType)objectCasters.GetCaster(typeof(VVMUI.Script.XLua.XLuaCommandType))(L, index, null);
            }
        }
Beispiel #23
0
    public static bool GetResult(out Vector4 res)
    {
        bool ret = false;

        if (s_ResIndex > s_ResNum)
        {
            res = Vector4.zero;
            return(ret);
        }
        int from = s_From + s_ResIndex;

        ++s_ResIndex;
        var L = s_Func.L;

        LuaTypes type = LuaDLL.lua_type(L, from);

        if (type == LuaTypes.LUA_TTABLE && LuaDLL.luaS_checkluatype(L, from, null) == 1)
        {
            if (LuaObject.luaTypeCheck(L, from, "Vector4"))
            {
                Vector4 v;
                LuaObject.checkType(L, from, out v);
                res = v;
                ret = true;
            }
            else
            {
                res = Vector4.zero;
            }
        }
        else
        {
            res = Vector4.zero;
        }
        return(ret);
    }
Beispiel #24
0
        public void Get(RealStatePtr L, int index, out XLuaTest.MyEnum val)
        {
            LuaTypes type = LuaAPI.lua_type(L, index);

            if (type == LuaTypes.LUA_TUSERDATA)
            {
                if (LuaAPI.xlua_gettypeid(L, index) != XLuaTestMyEnum_TypeID)
                {
                    throw new Exception("invalid userdata for XLuaTest.MyEnum");
                }

                IntPtr buff = LuaAPI.lua_touserdata(L, index);
                int    e;
                if (!CopyByValue.UnPack(buff, 0, out e))
                {
                    throw new Exception("unpack fail for XLuaTest.MyEnum");
                }
                val = (XLuaTest.MyEnum)e;
            }
            else
            {
                val = (XLuaTest.MyEnum)objectCasters.GetCaster(typeof(XLuaTest.MyEnum))(L, index, null);
            }
        }
Beispiel #25
0
        public void Get(RealStatePtr L, int index, out Tutorial.DrivenClass.TestEnumInner val)
        {
            LuaTypes type = LuaAPI.lua_type(L, index);

            if (type == LuaTypes.LUA_TUSERDATA)
            {
                if (LuaAPI.xlua_gettypeid(L, index) != TutorialDrivenClassTestEnumInner_TypeID)
                {
                    throw new Exception("invalid userdata for Tutorial.DrivenClass.TestEnumInner");
                }

                IntPtr buff = LuaAPI.lua_touserdata(L, index);
                int    e;
                if (!CopyByValue.UnPack(buff, 0, out e))
                {
                    throw new Exception("unpack fail for Tutorial.DrivenClass.TestEnumInner");
                }
                val = (Tutorial.DrivenClass.TestEnumInner)e;
            }
            else
            {
                val = (Tutorial.DrivenClass.TestEnumInner)objectCasters.GetCaster(typeof(Tutorial.DrivenClass.TestEnumInner))(L, index, null);
            }
        }
Beispiel #26
0
    static int set_a(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name a");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index a on a nil value");
            }
        }

        Color obj = (Color)o;

        obj.a = (float)LuaScriptMgr.GetNumber(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
Beispiel #27
0
    static int set_m21(IntPtr L)
    {
        object o = LuaScriptMgr.GetLuaObject(L, 1);

        if (o == null)
        {
            LuaTypes types = LuaDLL.lua_type(L, 1);

            if (types == LuaTypes.LUA_TTABLE)
            {
                LuaDLL.luaL_error(L, "unknown member name m21");
            }
            else
            {
                LuaDLL.luaL_error(L, "attempt to index m21 on a nil value");
            }
        }

        Matrix4x4 obj = (Matrix4x4)o;

        obj.m21 = (float)LuaScriptMgr.GetNumber(L, 3);
        LuaScriptMgr.SetValueObject(L, 1, obj);
        return(0);
    }
Beispiel #28
0
        static public int IsNull(IntPtr l)
        {
            try
            {
                LuaTypes t = LuaDLL.lua_type(l, 1);
                pushValue(l, true);

                if (t == LuaTypes.LUA_TNIL)
                {
                    pushValue(l, true);
                }
                // LUA_TUSERDATA or LUA_TTABLE(Class inherited from Unity Native)
                else if (t == LuaTypes.LUA_TUSERDATA || isLuaClass(l, 1))
                {
                    object o = checkObj(l, 1);
                    if (o is UnityEngine.Object)
                    {
                        pushValue(l, (o as UnityEngine.Object) == null);
                    }
                    else
                    {
                        pushValue(l, o == null);
                    }
                }
                else
                {
                    pushValue(l, false);
                }

                return(2);
            }
            catch (Exception e)
            {
                return(error(l, e));
            }
        }
Beispiel #29
0
    public static bool GetResult(out Quaternion res)
    {
        bool ret = false;

        if (s_ResIndex > s_ResNum)
        {
            res = Quaternion.identity;
            return(ret);
        }
        int from = s_From + s_ResIndex;

        ++s_ResIndex;
        var L = s_Func.L;

        LuaTypes type = LuaDLL.lua_type(L, from);

        if (type == LuaTypes.LUA_TTABLE && LuaDLL.luaS_checkluatype(L, from, null) == 1)
        {
            if (LuaObject.luaTypeCheck(L, from, "Quaternion"))
            {
                Quaternion v;
                LuaObject.checkType(L, from, out v);
                res = v;
                ret = true;
            }
            else
            {
                res = Quaternion.identity;
            }
        }
        else
        {
            res = Quaternion.identity;
        }
        return(ret);
    }
Beispiel #30
0
        public static bool lua_isboolean(IntPtr luaState, int n)
        {
            LuaTypes type = lua_type(luaState, n);

            return(type == LuaTypes.LUA_TBOOLEAN || type == LuaTypes.LUA_TNIL);
        }
Beispiel #31
0
		public static string lua_typename(Lua.lua_State luaState, LuaTypes type)
		{
			return Lua.lua_typename(luaState, (int) type).ToString();
		}
Beispiel #32
0
		public static extern string lua_typename(IntPtr luaState, LuaTypes type);
 public static void luaL_checktype(IntPtr L, int narg, LuaTypes t)
 {
     if (lua_type(L, narg) != t)
     {
         luaL_typerror(L, narg, lua_typename(L, t));
     }
 }
Beispiel #34
0
 public static void luaL_checktype(IntPtr luaState, int p, LuaTypes t)
 {
     LuaTypes ct = LuaDLL.lua_type(luaState, p);
     if (ct != t)
     {
         throw new Exception(string.Format("arg {0} expect {1}, got {2}", p, lua_typenamestr(luaState, t), lua_typenamestr(luaState, ct)));
     }
 }
Beispiel #35
0
        /*
        ** ===============================================================
        ** some useful functions
        ** ===============================================================
        */
        public static string luaL_typename(IntPtr luaState, int stackPos)
        {
            LuaTypes type = LuaDLL.lua_type(luaState, stackPos);

            return(lua_typename(luaState, type));
        }
Beispiel #36
0
 public static string lua_typenamestr(IntPtr luaState, LuaTypes type)
 {
     IntPtr p = lua_typename(luaState, (int)type);
     return Marshal.PtrToStringAnsi(p);
 }
Beispiel #37
0
		public static extern void luaL_checktype(IntPtr luaState, int p, LuaTypes t);
        public static bool TryPrimitiveArraySet(Type type, RealStatePtr L, object obj, int array_idx, int obj_idx)
        {
            bool ok = true;

            LuaTypes lua_type = LuaAPI.lua_type(L, obj_idx);

            if (type == typeof(int[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                int[] array = obj as int[];
                array[array_idx] = LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(float[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                float[] array = obj as float[];
                array[array_idx] = (float)LuaAPI.lua_tonumber(L, obj_idx);
            }
            else if (type == typeof(double[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                double[] array = obj as double[];
                array[array_idx] = LuaAPI.lua_tonumber(L, obj_idx);;
            }
            else if (type == typeof(bool[]) && lua_type == LuaTypes.LUA_TBOOLEAN)
            {
                bool[] array = obj as bool[];
                array[array_idx] = LuaAPI.lua_toboolean(L, obj_idx);
            }
            else if (type == typeof(long[]) && LuaAPI.lua_isint64(L, obj_idx))
            {
                long[] array = obj as long[];
                array[array_idx] = LuaAPI.lua_toint64(L, obj_idx);
            }
            else if (type == typeof(ulong[]) && LuaAPI.lua_isuint64(L, obj_idx))
            {
                ulong[] array = obj as ulong[];
                array[array_idx] = LuaAPI.lua_touint64(L, obj_idx);
            }
            else if (type == typeof(sbyte[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                sbyte[] array = obj as sbyte[];
                array[array_idx] = (sbyte)LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(short[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                short[] array = obj as short[];
                array[array_idx] = (short)LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(ushort[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                ushort[] array = obj as ushort[];
                array[array_idx] = (ushort)LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(char[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                char[] array = obj as char[];
                array[array_idx] = (char)LuaAPI.xlua_tointeger(L, obj_idx);
            }
            else if (type == typeof(uint[]) && lua_type == LuaTypes.LUA_TNUMBER)
            {
                uint[] array = obj as uint[];
                array[array_idx] = LuaAPI.xlua_touint(L, obj_idx);
            }
            else if (type == typeof(IntPtr[]) && lua_type == LuaTypes.LUA_TLIGHTUSERDATA)
            {
                IntPtr[] array = obj as IntPtr[];
                array[array_idx] = LuaAPI.lua_touserdata(L, obj_idx);
            }
            else if (type == typeof(decimal[]))
            {
                decimal[] array = obj as decimal[];
                if (lua_type == LuaTypes.LUA_TNUMBER)
                {
                    array[array_idx] = (decimal)LuaAPI.lua_tonumber(L, obj_idx);
                }

                if (lua_type == LuaTypes.LUA_TUSERDATA)
                {
                    ObjectTranslator translator = ObjectTranslatorPool.Instance.Find(L);
                    if (translator.IsDecimal(L, obj_idx))
                    {
                        translator.Get(L, obj_idx, out array[array_idx]);
                    }
                    else
                    {
                        ok = false;
                    }
                }
                else
                {
                    ok = false;
                }
            }
            else if (type == typeof(string[]) && lua_type == LuaTypes.LUA_TSTRING)
            {
                string[] array = obj as string[];
                array[array_idx] = LuaAPI.lua_tostring(L, obj_idx);
            }
            else
            {
                ok = false;
            }
            return(ok);
        }
Beispiel #39
0
 public static string LuaTypeName(LuaState luaState, LuaTypes type)
 {
     return LuaCore.LuaTypeName (luaState, (int)type).ToString ();
 }
 public static string lua_typename(IntPtr luaState, LuaTypes type)
 {
     int t = (int)type;
     return LuaTypeName[t + 1];
 }
 public string LuaTypeName(LuaTypes type)
 {
     return LuaDLL.lua_typename(L, type);
 }