Esempio n. 1
0
        public int Set(IntPtr L)
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 4 && TypeChecker.CheckTypes <object, object[]>(L, 3))
            {
                object   arg0 = ToLua.CheckVarObject(L, 2, kclass);
                object   arg1 = ToLua.ToVarObject(L, 3);
                object[] arg2 = ToLua.CheckObjectArray(L, 4);
                arg1 = TypeChecker.ChangeType(arg1, property.PropertyType);
                property.SetValue(arg0, arg1, arg2);
                return(0);
            }
            else if (count == 7 && TypeChecker.CheckTypes <object, uint, Binder, object[], CultureInfo>(L, 3))
            {
                object       arg0 = ToLua.CheckVarObject(L, 2, kclass);
                object       arg1 = ToLua.ToVarObject(L, 3);
                BindingFlags arg2 = (BindingFlags)LuaDLL.lua_tonumber(L, 4);
                Binder       arg3 = (Binder)ToLua.ToObject(L, 5);
                object[]     arg4 = ToLua.CheckObjectArray(L, 6);
                CultureInfo  arg5 = (CultureInfo)ToLua.ToObject(L, 7);
                arg1 = TypeChecker.ChangeType(arg1, property.PropertyType);
                property.SetValue(arg0, arg1, arg2, arg3, arg4, arg5);
                return(0);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: LuaInterface.LuaProperty.Set"));
            }
        }
Esempio n. 2
0
        public int Set(IntPtr L)
        {
            try
            {
                int count = LuaDLL.lua_gettop(L);

                if (count == 3 && TypeChecker.CheckTypes <object>(L, 3))
                {
                    object arg0 = ToLua.CheckVarObject(L, 2, kclass);
                    object arg1 = ToLua.ToVarObject(L, 3);
                    arg1 = TypeChecker.ChangeType(arg1, field.FieldType);
                    field.SetValue(arg0, arg1);
                    return(0);
                }
                else if (count == 6 && TypeChecker.CheckTypes <object, uint, Binder, CultureInfo>(L, 3))
                {
                    object       arg0 = ToLua.CheckVarObject(L, 2, kclass);
                    object       arg1 = ToLua.ToVarObject(L, 3);
                    BindingFlags arg2 = (BindingFlags)LuaDLL.lua_tonumber(L, 4);
                    Binder       arg3 = (Binder)ToLua.ToObject(L, 5);
                    CultureInfo  arg4 = (CultureInfo)ToLua.ToObject(L, 6);
                    arg1 = TypeChecker.ChangeType(arg1, field.FieldType);
                    field.SetValue(arg0, arg1, arg2, arg3, arg4);
                    return(0);
                }
                else
                {
                    return(LuaDLL.luaL_throw(L, "invalid arguments to method: LuaField.Set"));
                }
            }
            catch (Exception e)
            {
                return(LuaDLL.toluaL_exception(L, e));
            }
        }
Esempio n. 3
0
        public int Get(IntPtr L)
        {
            int count = LuaDLL.lua_gettop(L);

            if (count == 3 && TypeChecker.CheckTypes <object[]>(L, 3))
            {
                object   arg0 = ToLua.CheckVarObject(L, 2, kclass);
                object[] arg1 = ToLua.CheckObjectArray(L, 3);
                object   o    = property.GetValue(arg0, arg1);
                ToLua.Push(L, o);
                return(1);
            }
            else if (count == 6 && TypeChecker.CheckTypes <uint, Binder, object[], CultureInfo>(L, 3))
            {
                object       arg0 = ToLua.CheckVarObject(L, 2, kclass);
                BindingFlags arg1 = (BindingFlags)LuaDLL.lua_tonumber(L, 3);
                Binder       arg2 = (Binder)ToLua.ToObject(L, 4);
                object[]     arg3 = ToLua.CheckObjectArray(L, 5);
                CultureInfo  arg4 = (CultureInfo)ToLua.ToObject(L, 6);
                object       o    = property.GetValue(arg0, arg1, arg2, arg3, arg4);
                ToLua.Push(L, o);
                return(1);
            }
            else
            {
                return(LuaDLL.luaL_throw(L, "invalid arguments to method: LuaInterface.LuaProperty.Get"));
            }
        }
Esempio n. 4
0
        public int Call(IntPtr L)
        {
            object[] args = null;
            ToLua.CheckArgsCount(L, list.Count + 1);

            if (list.Count > 0)
            {
                args = new object[list.Count];

                for (int i = 0; i < list.Count; i++)
                {
                    bool   isRef = list[i].IsByRef;
                    Type   t0    = isRef ? list[i].GetElementType() : list[i];
                    object o     = ToLua.CheckVarObject(L, i + 2, t0);
                    args[i] = o;
                }
            }

            object ret   = method.Invoke(args);
            int    count = 1;

            ToLua.Push(L, ret);

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].IsByRef)
                {
                    ++count;
                    ToLua.Push(L, args[i]);
                }
            }

            return(count);
        }
Esempio n. 5
0
        public int Call(IntPtr L)
        {
            object[] array = null;
            ToLua.CheckArgsCount(L, this.list.Count + 1);
            if (this.list.Count > 0)
            {
                array = new object[this.list.Count];
                for (int i = 0; i < this.list.Count; i++)
                {
                    bool   isByRef = this.list[i].IsByRef;
                    Type   type    = (!isByRef) ? this.list[i] : this.list[i].GetElementType();
                    object temp    = ToLua.CheckVarObject(L, i + 2, type);
                    array[i] = TypeChecker.ChangeType(temp, type);
                }
            }
            object obj = this.method.Invoke(array);
            int    num = 1;

            ToLua.Push(L, obj);
            for (int j = 0; j < this.list.Count; j++)
            {
                if (this.list[j].IsByRef)
                {
                    num++;
                    ToLua.Push(L, array[j]);
                }
            }
            return(num);
        }
Esempio n. 6
0
        public int Call(IntPtr L)
        {
            object[] args   = null;
            object   obj    = null;
            int      offset = 1;

            if (!method.IsStatic)
            {
                offset += 1;
                obj     = ToLua.CheckObject(L, 2, kclass);
            }

            ToLua.CheckArgsCount(L, list.Count + offset);

            if (list.Count > 0)
            {
                // 会有GC:如果参数是值类型
                args    = new object[list.Count];
                offset += 1;

                for (int i = 0; i < list.Count; i++)
                {
                    bool isRef = list[i].IsByRef;
                    // ref传递得到的是地址,所以需要GetElementType得到具体元素类型
                    Type   t0 = isRef ? list[i].GetElementType() : list[i];
                    object o  = ToLua.CheckVarObject(L, i + offset, t0);
                    args[i] = o;
                }
            }

            object ret   = method.Invoke(obj, args);
            int    count = 0;

            // 是否有返回值
            if (method.ReturnType != typeof(void))
            {
                ++count;
                ToLua.Push(L, ret);
            }

            // 引用值当做返回值返回
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].IsByRef)
                {
                    ++count;
                    ToLua.Push(L, args[i]);
                }
            }

            return(count);
        }
Esempio n. 7
0
        public int Call(IntPtr L)
        {
            object[] args   = null;
            object   obj    = null;
            int      offset = 1;

            if (!method.IsStatic)
            {
                offset += 1;
                obj     = ToLua.CheckObject(L, 2, kclass);
            }

            ToLua.CheckArgsCount(L, list.Count + offset);

            if (list.Count > 0)
            {
                args    = new object[list.Count];
                offset += 1;

                for (int i = 0; i < list.Count; i++)
                {
                    bool   isRef = list[i].IsByRef;
                    Type   t0    = isRef ? list[i].GetElementType() : list[i];
                    object o     = ToLua.CheckVarObject(L, i + offset, t0);
                    args[i] = TypeChecker.ChangeType(o, t0);
                }
            }

            object ret   = method.Invoke(obj, args);
            int    count = 0;

            if (method.ReturnType != typeof(void))
            {
                ++count;
                ToLua.Push(L, ret);
            }

            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].IsByRef)
                {
                    ++count;
                    ToLua.Push(L, args[i]);
                }
            }

            return(count);
        }
Esempio n. 8
0
        public int Call(IntPtr L)
        {
            object[] array = null;
            object   obj   = null;
            int      num   = 1;

            if (!this.method.IsStatic)
            {
                num++;
                obj = ToLua.CheckObject(L, 2, this.kclass);
            }
            ToLua.CheckArgsCount(L, this.list.Count + num);
            if (this.list.Count > 0)
            {
                array = new object[this.list.Count];
                num++;
                for (int i = 0; i < this.list.Count; i++)
                {
                    bool   isByRef = this.list[i].IsByRef;
                    Type   type    = (!isByRef) ? this.list[i] : this.list[i].GetElementType();
                    object temp    = ToLua.CheckVarObject(L, i + num, type);
                    array[i] = TypeChecker.ChangeType(temp, type);
                }
            }
            object obj2 = this.method.Invoke(obj, array);
            int    num2 = 0;

            if (this.method.ReturnType != typeof(void))
            {
                num2++;
                ToLua.Push(L, obj2);
            }
            for (int j = 0; j < this.list.Count; j++)
            {
                if (this.list[j].IsByRef)
                {
                    num2++;
                    ToLua.Push(L, array[j]);
                }
            }
            return(num2);
        }