Exemplo n.º 1
0
        public static void Enumeration <T>(Lua lua)
        {
            if (lua == null)
            {
                throw new ArgumentNullException(nameof(lua));
            }

            Type type = typeof(T);

            if (!type.IsEnum)
            {
                throw new ArgumentException("The type must be an enumeration!");
            }


            string[] names  = Enum.GetNames(type);
            var      values = (T[])Enum.GetValues(type);

            lua.NewTable(type.Name);

            for (int i = 0; i < names.Length; i++)
            {
                string path = type.Name + "." + names[i];
                lua.SetObjectToPath(path, values[i]);
            }
        }