lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi, List!

On Tue, Mar 26, 2013 at 8:36 AM, Sean Conner <sean@conman.org> wrote:
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



The task is simple if you write your Lua code with some limitations in mind (i.e. do not re-initialize global state).

But the question is to how to make it work with any lua program...
Because if you write an IDE like the Celedev you can not make any assumptions about the code.

I was wondering maybe there are some libraries (or at least a description of techniques) that allow such dynamic update of Lua programs.
Maybe there is some "hack" in the Lua VM that allows to update only bytecode but do not touch global state?