Esempio n. 1
0
        public static LuaTable ToLuaTable(object o)
        {
            LuaTable ret = new LuaTable();

            // check if Dictionary...
            System.Collections.IDictionary dict = o as System.Collections.IDictionary;
            if (dict != null)
            {
                foreach (object obj in dict.Keys)
                {
                    ret.SetKeyValue(ToLuaValue(obj), ToLuaValue(dict[obj]));
                }
                return(ret);
            }

            System.Collections.IEnumerable ie = (o as System.Collections.IEnumerable);
            if (ie != null)
            {
                foreach (object obj in ie)
                {
                    ret.AddValue(ToLuaValue(obj));
                }
                return(ret);
            }

            // check if <type>...
            // not an array type
            ret.AddValue(ToLuaValue(o));
            return(ret);
        }
Esempio n. 2
0
        public static LuaTable Vector3dToTable(Vector3d v)
        {
            LuaTable t = new LuaTable();

            t.AddValue(new LuaNumber(v.x));
            t.AddValue(new LuaNumber(v.y));
            t.AddValue(new LuaNumber(v.z));

            return(t);
        }
Esempio n. 3
0
        public static LuaTable QuaternionToTable(Quaternion q)
        {
            LuaTable t = new LuaTable();

            t.AddValue(new LuaNumber(q.x));
            t.AddValue(new LuaNumber(q.y));
            t.AddValue(new LuaNumber(q.z));
            t.AddValue(new LuaNumber(q.w));

            return(t);
        }
Esempio n. 4
0
 public static LuaValue ToLuaValue(object value)
 {
     if ((value as LuaValue) != null)
     {
         return(value as LuaValue);
     }
     if (value is int || value is double || value is float)
     {
         return(new LuaNumber(Convert.ToDouble(value)));
     }
     else if (value is MuMech.MovingAverage)
     {
         return(new LuaNumber(((MuMech.MovingAverage)value).value));
     }
     else if (value is string)
     {
         return(new LuaString((string)value));
     }
     else if (value is bool)
     {
         return(LuaBoolean.From((bool)value));
     }
     else if (value == null)
     {
         return(LuaNil.Nil);
     }
     else if (value.GetType().IsEnum)
     {
         return(new LuaString(value.ToString()));
     }
     else if (value.GetType().IsArray)
     {
         LuaTable table = new LuaTable();
         foreach (var item in (value as Array))
         {
             table.AddValue(ToLuaValue(item));
         }
         return(table);
     }
     else if (value is LuaValue)
     {
         return((LuaValue)value);
     }
     else
     {
         LuaUserdata data = new LuaUserdata(value);
         data.MetaTable = GetControlMetaTable();
         return(data);
     }
 }