Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Remove the extension from the file name
- function remove_extension(path)
- return path:match("(%a+)%.?.-")
- end
- function execute(script_api)
- --Initialize the api
- local script = require(script_api)
- ok, err = pcall(script.run)
- if not ok then
- if err == "Terminated" then
- return true
- end
- end
- return false
- end
- function main()
- scripts_filenames = fs.list("scripts")
- --No files in startup directory
- if #scripts_filenames == 0 then
- return
- end
- scripts_run = {}
- for _,v in ipairs(scripts_filenames) do
- --Remove .lua from the path because api doesn't like it :(
- script_stripped = remove_extension(v)
- --Get the api
- script_api = require(script_stripped)
- if type(script_api) == "table" then
- if type(script_api.run) == "function" then
- table.insert(scripts_run, script_api)
- else
- print("File: " .. v .. " does not contain run function")
- end
- else
- print("File: " .. v .. " is not an api file, it is: " .. type(script_api))
- end
- end
- --Require API didn't grab the files correctly
- if #scripts_run == 0 then
- print("No scripts were loaded correctly")
- return
- end
- is_terminated = false
- while not is_terminated do
- for _,v in ipairs(scripts_run) do
- is_terminated = execute(script_api)
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement