api.lua 989 B

12345678910111213141516171819202122232425262728293031323334
  1. ------------------------------------------------------------------------------
  2. -- This file is registered as reloadable.
  3. ------------------------------------------------------------------------------
  4. reload = reload or {}
  5. reload.impl = reload.impl or {}
  6. reload.impl.files = reload.impl.files or {}
  7. reload.file_registered = function(id)
  8. assert(type(id) == "string") -- Foolproof us!
  9. if reload.impl.files[id] then return true else return false end
  10. end
  11. reload.register_file = function(id, file, noload)
  12. -- Foolproof us!
  13. assert(type(id) == "string")
  14. assert(type(file) == "string")
  15. -- This file cannot already have been registered.
  16. assert(reload.impl.files[id] == nil)
  17. -- Execute the file once.
  18. -- Registering the file also executes it, so doing this is the equivalent of using 'dofile',
  19. -- but with the added benefit of being able to execute the file again and again as needed.
  20. if noload == true or noload == nil then dofile(file) end
  21. reload.impl.files[id] = file
  22. end