lua-users home
lua-l archive

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

Niklas Frykholm wrote:
Now, let's say that I want to do something as nebulously-defined as
"Reload all the scripts from disk, but keep the current mutated State."
What insurmountable problems are going to prevent this from working in
any reasonable fashion?

I use hot script-reloading in all my projects, with the simple rule:

    * To reload: just re-run the script

It is the script's responsibility to know that it might be reloaded in this way and "do the right thing" with respect to the global state. Doing the right thing typically means replacing functions (otherwise there would be no point in reloading) and not touching data. Could be as simple as:

    # Instead of
    MyClass = class()
    MyClass.do_stuff = function ...

    # we write
    MyClass = MyClass or class()
    MyClass.do_stuff = function ...

If you introduce this policy early, make sure that everybody uses it, and that "reload" is used frequently, then any reload-related bugs should be discovered and fixed quickly.

I think this is a lot simpler than creating a system where the scripts "don't know" that they might be reloaded and *you* have to do all the work to make sure that nothing breaks when they are.

a variant (skipping redefinitions) is:

   if MyClass then return end

   MyClass = class()

                                          Hans Hagen | PRAGMA ADE
              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
     tel: 038 477 53 69 | fax: 038 477 53 74 |