<commit_before>package reflect

import (
	"sort"

	. "github.com/anaminus/rbxmk"
	"github.com/anaminus/rbxmk/rtypes"
	"github.com/robloxapi/rbxdump"
	"github.com/robloxapi/types"
	lua "github.com/yuin/gopher-lua"
)

func init() { register(RootDesc) }
func RootDesc() Reflector {
	return Reflector{
		Name:     "RootDesc",
		PushTo:   PushTypeTo,
		PullFrom: PullTypeFrom,
		Metatable: Metatable{
			"__eq": func(s State) int {
				v := s.Pull(1, "RootDesc").(*rtypes.RootDesc)
				op := s.Pull(2, "RootDesc").(*rtypes.RootDesc)
				s.L.Push(lua.LBool(v == op))
				return 1
			},
		},
		Members: Members{
			"Class": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				name := string(s.Pull(2, "string").(types.String))
				class, ok := desc.Classes[name]
				if !ok {
					return s.Push(rtypes.Nil)
				}
				return s.Push(rtypes.ClassDesc{Class: class})
			}},
			"Classes": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				classes := make(rtypes.Array, 0, len(desc.Classes))
				for _, class := range desc.Classes {
					classes = append(classes, rtypes.ClassDesc{Class: class})
				}
				sort.Slice(classes, func(i, j int) bool {
					return classes[i].(rtypes.ClassDesc).Name < classes[j].(rtypes.ClassDesc).Name
				})
				return s.Push(classes)
			}},
			"AddClass": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				class := s.Pull(2, "ClassDesc").(rtypes.ClassDesc)
				if _, ok := desc.Classes[class.Name]; ok {
					return s.Push(types.False)
				}
				if desc.Classes == nil {
					desc.Classes = map[string]*rbxdump.Class{}
				}
				desc.Classes[class.Name] = class.Class
				return s.Push(types.True)
			}},
			"RemoveClass": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				name := string(s.Pull(2, "string").(types.String))
				if _, ok := desc.Classes[name]; !ok {
					return s.Push(types.False)
				}
				delete(desc.Classes, name)
				return s.Push(types.True)
			}},
			"Enum": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				name := string(s.Pull(2, "string").(types.String))
				enum, ok := desc.Enums[name]
				if !ok {
					return s.Push(rtypes.Nil)
				}
				return s.Push(rtypes.EnumDesc{Enum: enum})
			}},
			"Enums": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				enums := make(rtypes.Array, 0, len(desc.Enums))
				for _, enum := range desc.Enums {
					enums = append(enums, rtypes.EnumDesc{Enum: enum})
				}
				sort.Slice(enums, func(i, j int) bool {
					return enums[i].(rtypes.EnumDesc).Name < enums[j].(rtypes.EnumDesc).Name
				})
				return s.Push(enums)
			}},
			"AddEnum": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				enum := s.Pull(2, "ClassDesc").(rtypes.EnumDesc)
				if _, ok := desc.Enums[enum.Name]; ok {
					return s.Push(types.False)
				}
				if desc.Enums == nil {
					desc.Enums = map[string]*rbxdump.Enum{}
				}
				desc.Enums[enum.Name] = enum.Enum
				return s.Push(types.True)
			}},
			"RemoveEnum": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				name := string(s.Pull(2, "string").(types.String))
				if _, ok := desc.Enums[name]; !ok {
					return s.Push(types.False)
				}
				delete(desc.Enums, name)
				return s.Push(types.True)
			}},
			"EnumTypes": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				desc.GenerateEnumTypes()
				return s.Push(desc.EnumTypes)<commit_msg>Fix RootDesc.AddEnum pulling incorrect type.<commit_after>package reflect

import (
	"sort"

	. "github.com/anaminus/rbxmk"
	"github.com/anaminus/rbxmk/rtypes"
	"github.com/robloxapi/rbxdump"
	"github.com/robloxapi/types"
	lua "github.com/yuin/gopher-lua"
)

func init() { register(RootDesc) }
func RootDesc() Reflector {
	return Reflector{
		Name:     "RootDesc",
		PushTo:   PushTypeTo,
		PullFrom: PullTypeFrom,
		Metatable: Metatable{
			"__eq": func(s State) int {
				v := s.Pull(1, "RootDesc").(*rtypes.RootDesc)
				op := s.Pull(2, "RootDesc").(*rtypes.RootDesc)
				s.L.Push(lua.LBool(v == op))
				return 1
			},
		},
		Members: Members{
			"Class": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				name := string(s.Pull(2, "string").(types.String))
				class, ok := desc.Classes[name]
				if !ok {
					return s.Push(rtypes.Nil)
				}
				return s.Push(rtypes.ClassDesc{Class: class})
			}},
			"Classes": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				classes := make(rtypes.Array, 0, len(desc.Classes))
				for _, class := range desc.Classes {
					classes = append(classes, rtypes.ClassDesc{Class: class})
				}
				sort.Slice(classes, func(i, j int) bool {
					return classes[i].(rtypes.ClassDesc).Name < classes[j].(rtypes.ClassDesc).Name
				})
				return s.Push(classes)
			}},
			"AddClass": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				class := s.Pull(2, "ClassDesc").(rtypes.ClassDesc)
				if _, ok := desc.Classes[class.Name]; ok {
					return s.Push(types.False)
				}
				if desc.Classes == nil {
					desc.Classes = map[string]*rbxdump.Class{}
				}
				desc.Classes[class.Name] = class.Class
				return s.Push(types.True)
			}},
			"RemoveClass": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				name := string(s.Pull(2, "string").(types.String))
				if _, ok := desc.Classes[name]; !ok {
					return s.Push(types.False)
				}
				delete(desc.Classes, name)
				return s.Push(types.True)
			}},
			"Enum": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				name := string(s.Pull(2, "string").(types.String))
				enum, ok := desc.Enums[name]
				if !ok {
					return s.Push(rtypes.Nil)
				}
				return s.Push(rtypes.EnumDesc{Enum: enum})
			}},
			"Enums": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				enums := make(rtypes.Array, 0, len(desc.Enums))
				for _, enum := range desc.Enums {
					enums = append(enums, rtypes.EnumDesc{Enum: enum})
				}
				sort.Slice(enums, func(i, j int) bool {
					return enums[i].(rtypes.EnumDesc).Name < enums[j].(rtypes.EnumDesc).Name
				})
				return s.Push(enums)
			}},
			"AddEnum": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				enum := s.Pull(2, "EnumDesc").(rtypes.EnumDesc)
				if _, ok := desc.Enums[enum.Name]; ok {
					return s.Push(types.False)
				}
				if desc.Enums == nil {
					desc.Enums = map[string]*rbxdump.Enum{}
				}
				desc.Enums[enum.Name] = enum.Enum
				return s.Push(types.True)
			}},
			"RemoveEnum": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				name := string(s.Pull(2, "string").(types.String))
				if _, ok := desc.Enums[name]; !ok {
					return s.Push(types.False)
				}
				delete(desc.Enums, name)
				return s.Push(types.True)
			}},
			"EnumTypes": Member{Method: true, Get: func(s State, v types.Value) int {
				desc := v.(*rtypes.RootDesc)
				desc.GenerateEnumTypes()
				return s.Push(desc.EnumTypes)
{'fraction_non_alphanumeric': 0.17423014586709887, 'fraction_numerical': 0.002971366828741221, 'mean_word_length': 3.0843905129619413, 'pattern_counts': {'":': 20, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5737931', 'n_tokens_mistral': 3315, 'n_tokens_neox': 2733, 'n_words': 555}