コード例 #1
0
ファイル: LuaUtil.cs プロジェクト: OlympusServers/Oxide
        public object BitwiseOr(LuaTable table)
        {
            // First of all, check it's actually an array
            int size;
            if (!table.IsArray(out size) || size == 0)
            {
                throw new InvalidOperationException("Specified table is not an array");
            }

            // Get the length
            int result = -1;
            Type type = null;

            // Create the array
            foreach (object key in table.Keys)
            {
                if (result < 0)
                {
                    result = (int)table[key];
                    type = table[key].GetType();
                    continue;
                }
                result |= (int)table[key];
            }

            // Return it
            return Enum.ToObject(type, result);
        }
コード例 #2
0
ファイル: LuaUtil.cs プロジェクト: yas-online/Oxide
        public object[] TableToArray(LuaTable table)
        {
            // First of all, check it's actually an array
            int size;
            if (!table.IsArray(out size))
            {
                throw new InvalidOperationException("Specified table is not an array");
            }

            // Get the length
            var arr = new object[size];

            // Create the array
            foreach (var key in table.Keys)
            {
                var index = Convert.ToInt32(key) - 1;
                arr[index] = table[key];
            }

            // Return it
            return arr;
        }
コード例 #3
0
ファイル: LuaUtil.cs プロジェクト: romgerman/Oxide
 public Type SpecializeType(Type baseType, LuaTable argTable)
 {
     int cnt;
     if (!argTable.IsArray(out cnt)) throw new ArgumentException("Table is not an array", "argTable");
     Type[] typeArgs = new Type[cnt];
     for (int i = 0; i < cnt; i++)
     {
         object obj = argTable[i + 1];
         if (obj is LuaTable) obj = (obj as LuaTable)["_type"];
         if (!(obj is Type)) throw new ArgumentException("Item in table is not a Type", $"argTable[{i + 1}]");
         typeArgs[i] = obj as Type;
     }
     return baseType.MakeGenericType(typeArgs);
 }