[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: How Lua code can be updated at runtime without breaking global state?
- From: Sean Conner <sean@...>
- Date: Tue, 26 Mar 2013 00:36:32 -0400
It was thus said that the Great Nikolay Zapolnov once stated:
> Hi, List!
>
> I periodically find Lua-based projects that do "dynamic update" (one of
> them - Celedev - was announced on this list less than a day ago with a
> great video :)). These projects update code in runtime while application is
> still running.
>
> I am wondering, what techniques are used to dynamically update Lua code
> without breaking normal execution of a program?
>
> There are a lot of caveats, for example what if program stores some
> non-constant data in global variables that are initialized in the beginning
> of the script? Simply reloading the script will reset that global variables
> to initial values...
It depends on the program. I know I have one daemon [1] that allows the
Lua code to be updated on the fly, and I explicitely check the "global"
variables to see if they exist, and if not, create them. The code tends to
look like [2]:
if blocked == nil then
blocked = {}
setmetatable(blocked,{ __index = function(t,k) return 0 end })
os.execute("iptables --table filter -F INPUT")
end
I doubt there's a "one-size-fits-all" solution here.
-spc (Or rather, I haven't bothered to look for one)
[1] https://github.com/spc476/syslogintr
[2] https://github.com/spc476/syslogintr/blob/master/modules/ssh-iptables.lua