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(func)
- --Run the function
- local ok, err = pcall(func)
- if not ok then
- if err == "Terminated" then
- return true
- end
- end
- return false
- end
- function main()
- local scripts_filenames = fs.list("scripts")
- --No files in startup directory
- if #scripts_filenames == 0 then
- return
- end
- --All the function that needs to be ran
- local scripts_run = {}
- --Sanitize each filename and get its' run function
- for _,v in ipairs(scripts_filenames) do
- --Remove .lua from the path because api doesn't like it :(
- local script_stripped = remove_extension(v)
- --Get the api
- local 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
- local is_terminated = false
- while not is_terminated do
- for _,v in ipairs(scripts_run) do
- is_terminated = execute(v)
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement