fork(2) download
  1. # BASE
  2. type Command = ref object of RootObj
  3. method execute*(c: Command) = discard #{.base.}
  4. # Greet
  5. type CommandGreet = ref object of Command
  6. method execute(c: CommandGreet) = echo "hi!"
  7. # Exit
  8. type CommandExit = ref object of Command
  9. method execute(c: CommandExit) = quit "Bye Bye"
  10. # Triggers
  11. type Trigger = enum
  12. tKEY_W
  13. tMOUSE
  14. # Table
  15. let bindings: array[Trigger, Command] = [
  16. tKEY_W: CommandGreet(),
  17. tMOUSE: CommandExit(),
  18. ]
  19. ########
  20. for t in {tKEY_W, tMOUSE}:
  21. let command = bindings[t]
  22. execute command
  23.  
Runtime error #stdin #stdout 0s 2420KB
stdin
Standard input is empty
stdout
hi!
Bye Bye