Prevent crash when attepting to reload an invalid module (#128)

* Prevent crash when attepting to reload an invalid module

720: for key, value in pairs(package.loaded[scriptName]) do

- package.loaded[scriptName] is expected to be a table, not all lua scripts return one
- if lua script does not provide a return value, true is implicitly returned instead, this results in an attempt to iterate over boolean value

reference: reference: https://www.lua.org/manual/5.1/manual.html#:~:text=Once%20a%20loader%20is%20found,of%20package.loaded%5Bmodname%5D.

* Fix formatting
This commit is contained in:
Nkfree
2023-03-23 16:44:42 +02:00
committed by GitHub
parent e3615a6d4c
commit 00a8ec35cc
+6
View File
@@ -689,6 +689,12 @@ function commandHandler.ProcessCommand(pid, cmd)
local wasLoaded = false
if package.loaded[scriptName] then
if type(package.loaded[scriptName]) ~= "table" then
Players[pid]:Message(scriptName .. " was already loaded but it is not a valid lua module and thus cannot be properly reloaded.\n")
return
end
Players[pid]:Message(scriptName .. " was already loaded, so it is being reloaded.\n")
wasLoaded = true
end