Advertisement
Lordeah18

Untitled

Jan 2nd, 2020
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. --Remove the extension from the file name
  2. function remove_extension(path)
  3. return path:match("(%a+)%.?.-")
  4. end
  5.  
  6.  
  7. function execute(func)
  8. --Run the function
  9. local ok, err = pcall(func)
  10. if not ok then
  11. if err == "Terminated" then
  12. return true
  13. end
  14. end
  15. return false
  16. end
  17.  
  18.  
  19. function main()
  20. local scripts_filenames = fs.list("scripts")
  21.  
  22. --No files in startup directory
  23. if #scripts_filenames == 0 then
  24. return
  25. end
  26.  
  27. --All the function that needs to be ran
  28. local scripts_run = {}
  29.  
  30. --Sanitize each filename and get its' run function
  31. for _,v in ipairs(scripts_filenames) do
  32. --Remove .lua from the path because api doesn't like it :(
  33. local script_stripped = remove_extension(v)
  34. --Get the api
  35. local script_api = require(script_stripped)
  36.  
  37. if type(script_api) == "table" then
  38. if type(script_api.run) == "function" then
  39. table.insert(scripts_run, script_api)
  40. else
  41. print("File: " .. v .. " does not contain run function")
  42. end
  43. else
  44. print("File: " .. v .. " is not an api file, it is: " .. type(script_api))
  45. end
  46.  
  47. end
  48.  
  49. --Require API didn't grab the files correctly
  50. if #scripts_run == 0 then
  51. print("No scripts were loaded correctly")
  52. return
  53. end
  54.  
  55. local is_terminated = false
  56. while not is_terminated do
  57. for _,v in ipairs(scripts_run) do
  58. is_terminated = execute(v)
  59. end
  60. end
  61. end
  62.  
  63.  
  64.  
  65. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement