Fixed issue with reloadable libraries
This commit is contained in:
parent
a491765d59
commit
34a24fad4e
19
main.lua
19
main.lua
|
@ -331,17 +331,30 @@ local function init_memebot ()
|
|||
shutdown_memebot()
|
||||
os.exit(128 + signum)
|
||||
end)
|
||||
---
|
||||
local RELOADABLE_LIBS = { 'config', 'internet', 'memes', 'curb_your_enthusiasm' }
|
||||
local ORIG_TABLES = {}
|
||||
for _, module_name in ipairs(RELOADABLE_LIBS) do
|
||||
ORIG_TABLES[module_name] = require(module_name)
|
||||
end
|
||||
--
|
||||
signal.signal(signal.SIGUSR1, function (signum)
|
||||
io.write ' !! Received SIGUSR1, will reload modules...\n'
|
||||
for _, module_name in ipairs { 'internet', 'memes', 'curb_your_enthusiasm' } do
|
||||
local old_module = require(module_name)
|
||||
for _, module_name in ipairs(RELOADABLE_LIBS) do
|
||||
io.write(' - '..module_name)
|
||||
package.loaded[module_name] = nil
|
||||
local new_module = require(module_name)
|
||||
if type(new_module) == 'table' then
|
||||
local old_module = ORIG_TABLES[module_name]
|
||||
for k, v in pairs(new_module) do
|
||||
old_module[k] = v
|
||||
end
|
||||
io.write(' - '..module_name..'\n')
|
||||
else
|
||||
io.write(' SKIP: Got '..tostring(new_module)..' but expected table.')
|
||||
end
|
||||
io.write '\n'
|
||||
end
|
||||
io.write ' Done\n'
|
||||
end)
|
||||
else
|
||||
io.write ' !! Module "posix.signal" was missing, so CTRL+C will hard-crash.\n'
|
||||
|
|
Loading…
Reference in New Issue
Block a user