lua_tonumber() public static method

public static lua_tonumber ( IntPtr luaState, int index ) : double
luaState IntPtr
index int
return double
示例#1
0
        /*
         * __newindex metafunction of CLR objects. Receives the object,
         * the member name and the value to be stored as arguments. Throws
         * and error if the assignment is invalid.
         */
        private int setFieldOrProperty(KopiLua.Lua.lua_State luaState)
        {
            object target = translator.getRawNetObject(luaState, 1);

            if (target == null)
            {
                translator.throwError(luaState, "trying to index and invalid object reference");
                return(0);
            }
            Type type = target.GetType();

            // First try to look up the parameter as a property name
            string detailMessage;
            bool   didMember = trySetMember(luaState, type, target, BindingFlags.Instance | BindingFlags.IgnoreCase, out detailMessage);

            if (didMember)
            {
                return(0);       // Must have found the property name
            }
            // We didn't find a property name, now see if we can use a [] style this accessor to set array contents
            try
            {
                if (type.IsArray && LuaDLL.lua_isnumber(luaState, 2))
                {
                    int index = (int)LuaDLL.lua_tonumber(luaState, 2);

                    Array  arr = (Array)target;
                    object val = translator.getAsType(luaState, 3, arr.GetType().GetElementType());
                    arr.SetValue(val, index);
                }
                else
                {
                    // Try to see if we have a this[] accessor
                    MethodInfo setter = type.GetMethod("set_Item");
                    if (setter != null)
                    {
                        ParameterInfo[] args      = setter.GetParameters();
                        Type            valueType = args[1].ParameterType;

                        // The new val ue the user specified
                        object val = translator.getAsType(luaState, 3, valueType);

                        Type   indexType = args[0].ParameterType;
                        object index     = translator.getAsType(luaState, 2, indexType);

                        object[] methodArgs = new object[2];

                        // Just call the indexer - if out of bounds an exception will happen
                        methodArgs[0] = index;
                        methodArgs[1] = val;

                        setter.Invoke(target, methodArgs);
                    }
                    else
                    {
                        translator.throwError(luaState, detailMessage); // Pass the original message from trySetMember because it is probably best
                    }
                }
            }
            catch (SEHException)
            {
                // If we are seeing a C++ exception - this must actually be for Lua's private use.  Let it handle it
                throw;
            }
            catch (Exception e)
            {
                ThrowError(luaState, e);
            }
            return(0);
        }
示例#2
0
        public decimal ToDecimal(IntPtr L, int stackPos)
        {
            double ret = LuaDLL.lua_tonumber(L, stackPos);

            return(Convert.ToDecimal(ret));
        }
示例#3
0
        public float ToFloat(IntPtr L, int stackPos)
        {
            double ret = LuaDLL.lua_tonumber(L, stackPos);

            return(Convert.ToSingle(ret));
        }
示例#4
0
        public char ToChar(IntPtr L, int stackPos)
        {
            double ret = LuaDLL.lua_tonumber(L, stackPos);

            return(Convert.ToChar(ret));
        }
示例#5
0
        public uint ToUInt32(IntPtr L, int stackPos)
        {
            double ret = LuaDLL.lua_tonumber(L, stackPos);

            return(Convert.ToUInt32(ret));
        }
示例#6
0
        public byte ToByte(IntPtr L, int stackPos)
        {
            double ret = LuaDLL.lua_tonumber(L, stackPos);

            return(Convert.ToByte(ret));
        }
示例#7
0
        public short ToInt16(IntPtr L, int stackPos)
        {
            double ret = LuaDLL.lua_tonumber(L, stackPos);

            return(Convert.ToInt16(ret));
        }
示例#8
0
        private static int GetProperty(IntPtr L)
        {
            int result;

            try
            {
                int num = LuaDLL.lua_gettop(L);
                if (num == 2 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string)))
                {
                    Type         type     = (Type)ToLua.ToObject(L, 1);
                    string       name     = ToLua.ToString(L, 2);
                    PropertyInfo property = type.GetProperty(name);
                    LuaReflection.PushLuaProperty(L, property, type);
                    result = 1;
                }
                else if (num == 3 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(Type[])))
                {
                    Type         type2     = (Type)ToLua.ToObject(L, 1);
                    string       name2     = ToLua.ToString(L, 2);
                    Type[]       types     = ToLua.CheckObjectArray <Type>(L, 3);
                    PropertyInfo property2 = type2.GetProperty(name2, types);
                    LuaReflection.PushLuaProperty(L, property2, type2);
                    result = 1;
                }
                else if (num == 3 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(Type)))
                {
                    Type         type3      = (Type)ToLua.ToObject(L, 1);
                    string       name3      = ToLua.ToString(L, 2);
                    Type         returnType = (Type)ToLua.ToObject(L, 3);
                    PropertyInfo property3  = type3.GetProperty(name3, returnType);
                    LuaReflection.PushLuaProperty(L, property3, type3);
                    result = 1;
                }
                else if (num == 3 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(uint)))
                {
                    Type         type4       = (Type)ToLua.ToObject(L, 1);
                    string       name4       = ToLua.ToString(L, 2);
                    BindingFlags bindingAttr = (BindingFlags)LuaDLL.lua_tonumber(L, 3);
                    PropertyInfo property4   = type4.GetProperty(name4, bindingAttr);
                    LuaReflection.PushLuaProperty(L, property4, type4);
                    result = 1;
                }
                else if (num == 4 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(Type), typeof(Type[])))
                {
                    Type         type5       = (Type)ToLua.ToObject(L, 1);
                    string       name5       = ToLua.ToString(L, 2);
                    Type         returnType2 = (Type)ToLua.ToObject(L, 3);
                    Type[]       types2      = ToLua.CheckObjectArray <Type>(L, 4);
                    PropertyInfo property5   = type5.GetProperty(name5, returnType2, types2);
                    LuaReflection.PushLuaProperty(L, property5, type5);
                    result = 1;
                }
                else if (num == 5 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(Type), typeof(Type[]), typeof(ParameterModifier[])))
                {
                    Type   type6                  = (Type)ToLua.ToObject(L, 1);
                    string name6                  = ToLua.ToString(L, 2);
                    Type   returnType3            = (Type)ToLua.ToObject(L, 3);
                    Type[] types3                 = ToLua.CheckObjectArray <Type>(L, 4);
                    ParameterModifier[] modifiers = ToLua.CheckObjectArray <ParameterModifier>(L, 5);
                    PropertyInfo        property6 = type6.GetProperty(name6, returnType3, types3, modifiers);
                    LuaReflection.PushLuaProperty(L, property6, type6);
                    result = 1;
                }
                else if (num == 7 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(uint), typeof(Binder), typeof(Type), typeof(Type[]), typeof(ParameterModifier[])))
                {
                    Type                type7        = (Type)ToLua.ToObject(L, 1);
                    string              name7        = ToLua.ToString(L, 2);
                    BindingFlags        bindingAttr2 = (BindingFlags)LuaDLL.lua_tonumber(L, 3);
                    Binder              binder       = (Binder)ToLua.ToObject(L, 4);
                    Type                returnType4  = (Type)ToLua.ToObject(L, 5);
                    Type[]              types4       = ToLua.CheckObjectArray <Type>(L, 6);
                    ParameterModifier[] modifiers2   = ToLua.CheckObjectArray <ParameterModifier>(L, 7);
                    PropertyInfo        property7    = type7.GetProperty(name7, bindingAttr2, binder, returnType4, types4, modifiers2);
                    LuaReflection.PushLuaProperty(L, property7, type7);
                    result = 1;
                }
                else
                {
                    result = LuaDLL.luaL_throw(L, "invalid arguments to method: tolua.getproperty");
                }
            }
            catch (Exception e)
            {
                result = LuaDLL.toluaL_exception(L, e, null);
            }
            return(result);
        }
示例#9
0
        private static int GetTypeMethod(IntPtr L)
        {
            int result;

            try
            {
                int num = LuaDLL.lua_gettop(L);
                if (num == 2 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string)))
                {
                    Type       type   = (Type)ToLua.ToObject(L, 1);
                    string     name   = ToLua.ToString(L, 2);
                    MethodInfo method = type.GetMethod(name);
                    LuaReflection.PushLuaMethod(L, method, type, null);
                    result = 1;
                }
                else if (num == 3 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(Type[])))
                {
                    Type       type2   = (Type)ToLua.ToObject(L, 1);
                    string     name2   = ToLua.ToString(L, 2);
                    Type[]     types   = ToLua.CheckObjectArray <Type>(L, 3);
                    MethodInfo method2 = type2.GetMethod(name2, types);
                    LuaReflection.PushLuaMethod(L, method2, type2, types);
                    result = 1;
                }
                else if (num == 3 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(uint)))
                {
                    Type         type3       = (Type)ToLua.ToObject(L, 1);
                    string       name3       = ToLua.ToString(L, 2);
                    BindingFlags bindingAttr = (BindingFlags)LuaDLL.lua_tonumber(L, 3);
                    MethodInfo   method3     = type3.GetMethod(name3, bindingAttr);
                    LuaReflection.PushLuaMethod(L, method3, type3, null);
                    result = 1;
                }
                else if (num == 4 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(Type[]), typeof(ParameterModifier[])))
                {
                    Type   type4  = (Type)ToLua.ToObject(L, 1);
                    string name4  = ToLua.ToString(L, 2);
                    Type[] types2 = ToLua.CheckObjectArray <Type>(L, 3);
                    ParameterModifier[] modifiers = ToLua.CheckObjectArray <ParameterModifier>(L, 4);
                    MethodInfo          method4   = type4.GetMethod(name4, types2, modifiers);
                    LuaReflection.PushLuaMethod(L, method4, type4, types2);
                    result = 1;
                }
                else if (num == 6 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(uint), typeof(Binder), typeof(Type[]), typeof(ParameterModifier[])))
                {
                    Type                type5        = (Type)ToLua.ToObject(L, 1);
                    string              name5        = ToLua.ToString(L, 2);
                    BindingFlags        bindingAttr2 = (BindingFlags)LuaDLL.lua_tonumber(L, 3);
                    Binder              binder       = (Binder)ToLua.ToObject(L, 4);
                    Type[]              types3       = ToLua.CheckObjectArray <Type>(L, 5);
                    ParameterModifier[] modifiers2   = ToLua.CheckObjectArray <ParameterModifier>(L, 6);
                    MethodInfo          method5      = type5.GetMethod(name5, bindingAttr2, binder, types3, modifiers2);
                    LuaReflection.PushLuaMethod(L, method5, type5, types3);
                    result = 1;
                }
                else if (num == 7 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(uint), typeof(Binder), typeof(CallingConventions), typeof(Type[]), typeof(ParameterModifier[])))
                {
                    Type                type6          = (Type)ToLua.ToObject(L, 1);
                    string              name6          = ToLua.ToString(L, 2);
                    BindingFlags        bindingAttr3   = (BindingFlags)LuaDLL.lua_tonumber(L, 3);
                    Binder              binder2        = (Binder)ToLua.ToObject(L, 4);
                    CallingConventions  callConvention = (CallingConventions)((int)ToLua.ToObject(L, 5));
                    Type[]              types4         = ToLua.CheckObjectArray <Type>(L, 6);
                    ParameterModifier[] modifiers3     = ToLua.CheckObjectArray <ParameterModifier>(L, 7);
                    MethodInfo          method6        = type6.GetMethod(name6, bindingAttr3, binder2, callConvention, types4, modifiers3);
                    LuaReflection.PushLuaMethod(L, method6, type6, types4);
                    result = 1;
                }
                else
                {
                    result = LuaDLL.luaL_throw(L, "invalid arguments to method: tolua.gettypemethod");
                }
            }
            catch (Exception e)
            {
                result = LuaDLL.toluaL_exception(L, e, null);
            }
            return(result);
        }
示例#10
0
 public double LuaToNumber(int idx)
 {
     return(LuaDLL.lua_tonumber(L, idx));
 }
示例#11
0
        static int GetProperty(IntPtr L)
        {
            try
            {
                int count = LuaDLL.lua_gettop(L);

                if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string)))
                {
                    Type         obj  = (Type)ToLua.ToObject(L, 1);
                    string       arg0 = ToLua.ToString(L, 2);
                    PropertyInfo o    = obj.GetProperty(arg0);
                    PushLuaProperty(L, o, obj);
                    return(1);
                }
                else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(Type[])))
                {
                    Type         obj  = (Type)ToLua.ToObject(L, 1);
                    string       arg0 = ToLua.ToString(L, 2);
                    Type[]       arg1 = ToLua.CheckObjectArray <Type>(L, 3);
                    PropertyInfo o    = obj.GetProperty(arg0, arg1);
                    PushLuaProperty(L, o, obj);
                    return(1);
                }
                else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(Type)))
                {
                    Type         obj  = (Type)ToLua.ToObject(L, 1);
                    string       arg0 = ToLua.ToString(L, 2);
                    Type         arg1 = (Type)ToLua.ToObject(L, 3);
                    PropertyInfo o    = obj.GetProperty(arg0, arg1);
                    PushLuaProperty(L, o, obj);
                    return(1);
                }
                else if (count == 3 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(uint)))
                {
                    Type         obj  = (Type)ToLua.ToObject(L, 1);
                    string       arg0 = ToLua.ToString(L, 2);
                    BindingFlags arg1 = (BindingFlags)LuaDLL.lua_tonumber(L, 3);
                    PropertyInfo o    = obj.GetProperty(arg0, arg1);
                    PushLuaProperty(L, o, obj);
                    return(1);
                }
                else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(Type), typeof(Type[])))
                {
                    Type         obj  = (Type)ToLua.ToObject(L, 1);
                    string       arg0 = ToLua.ToString(L, 2);
                    Type         arg1 = (Type)ToLua.ToObject(L, 3);
                    Type[]       arg2 = ToLua.CheckObjectArray <Type>(L, 4);
                    PropertyInfo o    = obj.GetProperty(arg0, arg1, arg2);
                    PushLuaProperty(L, o, obj);
                    return(1);
                }
                else if (count == 5 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(Type), typeof(Type[]), typeof(ParameterModifier[])))
                {
                    Type   obj  = (Type)ToLua.ToObject(L, 1);
                    string arg0 = ToLua.ToString(L, 2);
                    Type   arg1 = (Type)ToLua.ToObject(L, 3);
                    Type[] arg2 = ToLua.CheckObjectArray <Type>(L, 4);
                    ParameterModifier[] arg3 = ToLua.CheckObjectArray <ParameterModifier>(L, 5);
                    PropertyInfo        o    = obj.GetProperty(arg0, arg1, arg2, arg3);
                    PushLuaProperty(L, o, obj);
                    return(1);
                }
                else if (count == 7 && TypeChecker.CheckTypes(L, 1, typeof(Type), typeof(string), typeof(uint), typeof(Binder), typeof(Type), typeof(Type[]), typeof(ParameterModifier[])))
                {
                    Type                obj  = (Type)ToLua.ToObject(L, 1);
                    string              arg0 = ToLua.ToString(L, 2);
                    BindingFlags        arg1 = (BindingFlags)LuaDLL.lua_tonumber(L, 3);
                    Binder              arg2 = (Binder)ToLua.ToObject(L, 4);
                    Type                arg3 = (Type)ToLua.ToObject(L, 5);
                    Type[]              arg4 = ToLua.CheckObjectArray <Type>(L, 6);
                    ParameterModifier[] arg5 = ToLua.CheckObjectArray <ParameterModifier>(L, 7);
                    PropertyInfo        o    = obj.GetProperty(arg0, arg1, arg2, arg3, arg4, arg5);
                    PushLuaProperty(L, o, obj);
                    return(1);
                }
                else
                {
                    return(LuaDLL.luaL_throw(L, "invalid arguments to method: tolua.getproperty"));
                }
            }
            catch (Exception e)
            {
                return(LuaDLL.toluaL_exception(L, e));
            }
        }
 internal int ToInt32(IntPtr arg1, int arg2)
 {
     return((int)LuaDLL.lua_tonumber(arg1, arg2));
 }