hotcodereloading.nim 972 B

12345678910111213141516171819202122232425262728
  1. when defined(hotcodereloading):
  2. import
  3. macros
  4. template beforeCodeReload*(body: untyped) =
  5. hcrAddEventHandler(true, proc = body) {.executeOnReload.}
  6. template afterCodeReload*(body: untyped) =
  7. hcrAddEventHandler(false, proc = body) {.executeOnReload.}
  8. macro hasModuleChanged*(module: typed): untyped =
  9. if module.kind != nnkSym or module.symKind != nskModule:
  10. error "hasModuleChanged expects a module symbol", module
  11. return newCall(bindSym"hcrHasModuleChanged", newLit(module.signatureHash))
  12. proc hasAnyModuleChanged*(): bool = hcrReloadNeeded()
  13. when not defined(JS):
  14. template performCodeReload* = hcrPerformCodeReload()
  15. else:
  16. template performCodeReload* = discard
  17. else:
  18. template beforeCodeReload*(body: untyped) = discard
  19. template afterCodeReload*(body: untyped) = discard
  20. template hasModuleChanged*(module: typed): bool = false
  21. proc hasAnyModuleChanged*(): bool = false
  22. template performCodeReload*() = discard