Exemple #1
0
 private bool decimalCheck(RealStatePtr L, int idx)
 {
     return(LuaAPI.lua_type(L, idx) == LuaTypes.LUA_TNUMBER || translator.IsDecimal(L, idx));
 }
        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);
        }
Exemple #3
0
        int SystemIOBinaryWriter_m_Write(RealStatePtr L, int gen_param_count)
        {
            ObjectTranslator translator = this;


            System.IO.BinaryWriter gen_to_be_invoked = (System.IO.BinaryWriter)translator.FastGetCSObj(L, 1);

            if (gen_param_count == 2 && LuaTypes.LUA_TBOOLEAN == LuaAPI.lua_type(L, 2))
            {
                bool _value = LuaAPI.lua_toboolean(L, 2);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 2 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2))
            {
                byte _value = (byte)LuaAPI.xlua_tointeger(L, 2);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 2 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2))
            {
                sbyte _value = (sbyte)LuaAPI.xlua_tointeger(L, 2);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 2 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2))
            {
                char _ch = (char)LuaAPI.xlua_tointeger(L, 2);

                gen_to_be_invoked.Write(_ch);



                return(0);
            }
            if (gen_param_count == 2 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2))
            {
                double _value = LuaAPI.lua_tonumber(L, 2);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 2 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2))
            {
                short _value = (short)LuaAPI.xlua_tointeger(L, 2);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 2 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2))
            {
                ushort _value = (ushort)LuaAPI.xlua_tointeger(L, 2);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 2 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2))
            {
                int _value = LuaAPI.xlua_tointeger(L, 2);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 2 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2))
            {
                uint _value = LuaAPI.xlua_touint(L, 2);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 2 && (LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) || LuaAPI.lua_isint64(L, 2)))
            {
                long _value = LuaAPI.lua_toint64(L, 2);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 2 && (LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) || LuaAPI.lua_isuint64(L, 2)))
            {
                ulong _value = LuaAPI.lua_touint64(L, 2);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 2 && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2))
            {
                float _value = (float)LuaAPI.lua_tonumber(L, 2);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING))
            {
                byte[] _buffer = LuaAPI.lua_tobytes(L, 2);

                gen_to_be_invoked.Write(_buffer);



                return(0);
            }
            if (gen_param_count == 2 && translator.Assignable <char[]>(L, 2))
            {
                char[] _chars = (char[])translator.GetObject(L, 2, typeof(char[]));

                gen_to_be_invoked.Write(_chars);



                return(0);
            }
            if (gen_param_count == 2 && (LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 2) || translator.IsDecimal(L, 2)))
            {
                decimal _value; translator.Get(L, 2, out _value);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 2 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING))
            {
                string _value = LuaAPI.lua_tostring(L, 2);

                gen_to_be_invoked.Write(_value);



                return(0);
            }
            if (gen_param_count == 4 && (LuaAPI.lua_isnil(L, 2) || LuaAPI.lua_type(L, 2) == LuaTypes.LUA_TSTRING) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4))
            {
                byte[] _buffer = LuaAPI.lua_tobytes(L, 2);
                int    _index  = LuaAPI.xlua_tointeger(L, 3);
                int    _count  = LuaAPI.xlua_tointeger(L, 4);

                gen_to_be_invoked.Write(_buffer, _index, _count);



                return(0);
            }
            if (gen_param_count == 4 && translator.Assignable <char[]>(L, 2) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 3) && LuaTypes.LUA_TNUMBER == LuaAPI.lua_type(L, 4))
            {
                char[] _chars = (char[])translator.GetObject(L, 2, typeof(char[]));
                int    _index = LuaAPI.xlua_tointeger(L, 3);
                int    _count = LuaAPI.xlua_tointeger(L, 4);

                gen_to_be_invoked.Write(_chars, _index, _count);



                return(0);
            }


            return(LuaAPI.luaL_error(L, "invalid arguments to System.IO.BinaryWriter.Write!"));
        }