Advertisement
Lordeah18

Untitled

Dec 30th, 2019
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 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(script_api)
  8. --Initialize the api
  9. local script = require(script_api)
  10.  
  11. ok, err = pcall(script.run)
  12. if not ok then
  13. if err == "Terminated" then
  14. return true
  15. end
  16. end
  17. return false
  18. end
  19.  
  20.  
  21. function main()
  22. scripts_filenames = fs.list("scripts")
  23.  
  24. --No files in startup directory
  25. if #scripts_filenames == 0 then
  26. return
  27. end
  28.  
  29. scripts_run = {}
  30. for _,v in ipairs(scripts_filenames) do
  31. --Remove .lua from the path because api doesn't like it :(
  32. script_stripped = remove_extension(v)
  33. --Get the api
  34. script_api = require(script_stripped)
  35.  
  36. if type(script_api) == "table" then
  37. if type(script_api.run) == "function" then
  38. table.insert(scripts_run, script_api)
  39. else
  40. print("File: " .. v .. " does not contain run function")
  41. end
  42. else
  43. print("File: " .. v .. " is not an api file, it is: " .. type(script_api))
  44. end
  45.  
  46. end
  47.  
  48. --Require API didn't grab the files correctly
  49. if #scripts_run == 0 then
  50. print("No scripts were loaded correctly")
  51. return
  52. end
  53.  
  54. is_terminated = false
  55. while not is_terminated do
  56. for _,v in ipairs(scripts_run) do
  57. is_terminated = execute(script_api)
  58. end
  59. end
  60. end
  61.  
  62.  
  63.  
  64. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement