Guest User

loadfile.lua

a guest
Sep 17th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. --[[
  2. author: Aussiemon
  3.  
  4. -----
  5.  
  6. Copyright 2017 Aussiemon
  7.  
  8. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  9.  
  10. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  11.  
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  13.  
  14. -----
  15.  
  16. Allows the user to load arbitrary .lua files in the mods\loadfile folder
  17. --]]
  18.  
  19. local command_name = "loadfile"
  20.  
  21. -- Process arguments.
  22. local args = {...}
  23. if #args > 0 then
  24.  
  25. -- Process/format arguments into a new message
  26. local new_file_name = ""
  27. for key, value in pairs(args) do
  28. if type(value) == "string" then
  29. new_file_name = new_file_name .. value
  30. elseif type(value) == "table" then
  31. for value_key, value_value in pairs(value) do
  32. if type(value_value) == "string" then
  33. new_file_name = new_file_name .. value_value
  34. end
  35. end
  36. end
  37. end
  38.  
  39. -- Check for .lua extension
  40. trim_point = string.find(new_file_name, ".lua")
  41. if trim_point then
  42. new_file_name = string.sub(new_file_name, 1, (trim_point-1)) -- Cut off extension
  43. end
  44.  
  45. -- Attempt to load file
  46. Mods.exec("loadfile", new_file_name)
  47. else
  48. EchoConsole("No filename given!")
  49. end
Advertisement
Add Comment
Please, Sign In to add comment