Advertisement
Guest User

Untitled

a guest
Apr 21st, 2015
217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.58 KB | None | 0 0
  1. l.PushUserData(struct{}{})
  2. l.NewTable()
  3. l.SetUserValue(-2)
  4. l.NewTable()
  5. lua.SetFunctions(l, []lua.RegistryFunction{
  6. {"__newindex", func(l *lua.State) int {
  7. name := lua.CheckString(l, 2)
  8. for _, step := range *steps {
  9. lua.ArgumentCheck(l, step != name, 2, fmt.Sprintf("step %q already exists", name))
  10. }
  11. lua.CheckType(l, 3, lua.TypeFunction)
  12. l.UserValue(1)
  13. l.Replace(1)
  14. l.RawSet(1)
  15. *steps = append(*steps, name)
  16. return 0
  17. }},
  18. {"__index", func(l *lua.State) int {
  19. l.UserValue(1)
  20. l.Replace(1)
  21. l.RawGet(1)
  22. return 1
  23. }},
  24. }, 0)
  25. l.SetMetaTable(-2)
  26. l.SetGlobal("step")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement