lua-users home
lua-l archive

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


On Mon, Aug 27, 2012 at 2:09 PM, Jay Carlson <nop@nop.com> wrote:
> 2a) Interactive development of modules. Single-module reload is hopeless.

I'd also like to hear what others do about hot swapping code.  Has it
already been discussed before?  Some options include

(O1) Disable caching in `require`.  For possible problems with this,
consider the example of a module dependency chain like (A ->B, A->C,
B->D, C->D).  The require 'A' would load two instances of D in memory,
so any objects instantiated from classes defined in those two D's
could get different metatables (unless the programmer explicitly
caches them somewhere in the global state), and __eq checks for
metatable equality.

(O2) Pass a special version of `require` to A and any modules A
transitively loads via that `require`.   This special `require`
maintains a private module cache (separate from package.loaded).  If
you edit any file in that private cache, reload all those files.
Alternately, record the module dependency chain (inferred by
executions of nested require calls) and their checksums or timestamps
for more selective reloading, like makefiles.  We assume here that
modules behave nicely: they don't introduce dependencies other than
expressed with require.  Optionally add some type of data persistence
API to modules to allow transferring state between old and new
modules.

(O3) Do something like Jay said where modules themselves say how they
should react when their dependencies change.  Even if this could be
practical, I don't think it will be so for novice users.

(O4) Do something on the VM level by walking Lua's internal GC memory
(and likewise LuaJIT's :/ ).

> 1) It fails "Don't Repeat Yourself",

I'm not so bothered with this syntactic point.  Sure, we may do `local
ml = require 'ml'`, but `local ml = require 'foo.bar.bar.ml'` and can
reduce repetition too, and one can think of other variants (e.g.
`local _ENV = requireunion("_G", "ml", "lfs"` returning a table that
is the union of the given modules, sort of how _G is itself the union
of math, string, etc.).