Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- l.PushUserData(struct{}{})
- l.NewTable()
- l.SetUserValue(-2)
- l.NewTable()
- lua.SetFunctions(l, []lua.RegistryFunction{
- {"__newindex", func(l *lua.State) int {
- name := lua.CheckString(l, 2)
- for _, step := range *steps {
- lua.ArgumentCheck(l, step != name, 2, fmt.Sprintf("step %q already exists", name))
- }
- lua.CheckType(l, 3, lua.TypeFunction)
- l.UserValue(1)
- l.Replace(1)
- l.RawSet(1)
- *steps = append(*steps, name)
- return 0
- }},
- {"__index", func(l *lua.State) int {
- l.UserValue(1)
- l.Replace(1)
- l.RawGet(1)
- return 1
- }},
- }, 0)
- l.SetMetaTable(-2)
- l.SetGlobal("step")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement