123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- ------------------------------------------------------------------------------
- -- This file is registered as reloadable.
- ------------------------------------------------------------------------------
- if not minetest.global_exists("reload") then reload = {} end
- reload.impl = reload.impl or {}
- reload.impl.files = reload.impl.files or {}
- reload.file_registered = function(id)
- assert(type(id) == "string") -- Foolproof us!
- if reload.impl.files[id] then return true else return false end
- end
- reload.register_file = function(id, file, noload)
- -- Foolproof us!
- assert(type(id) == "string")
- assert(type(file) == "string")
-
- -- This file cannot already have been registered.
- assert(reload.impl.files[id] == nil)
-
- -- Execute the file once. Registering the file also executes it, so doing this
- -- is the equivalent of using 'dofile', but with the added benefit of being
- -- able to execute the file again and again as needed.
- if noload == true or noload == nil then dofile(file) end
- reload.impl.files[id] = file
- end
- -- Check if file exists, and register/execute it only if it does.
- reload.register_optional = function(id, path)
- -- Foolproof us!
- assert(type(id) == "string")
- assert(type(path) == "string")
- -- This file cannot already have been registered.
- assert(reload.impl.files[id] == nil)
- local file = io.open(path)
- if file then
- -- File exists, we can execute it.
- reload.impl.files[id] = path
- dofile(path)
- end
- end
|