tderef.nim 418 B

123456789101112131415161718192021
  1. discard """
  2. output: '''true
  3. '''
  4. """
  5. import tables
  6. type EventStore = Table[string, seq[proc ()]]
  7. proc newEventStore(): EventStore =
  8. initTable[string, seq[proc ()]]()
  9. proc register(store: var EventStore, name: string, callback: proc ()) =
  10. if not store.hasKey(name):
  11. store[name] = @[]
  12. store[name].add(callback)
  13. var store = newEventStore()
  14. store.register("test", proc () = echo "true")
  15. store["test"][0]()