lua-users home
lua-l archive

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


Dmitriy,

My reply was about implementing edit and continue by rewriting the original source code before it's loaded, so no modifications need to be made to the Lua interpreter.  For example, if your original Lua code looked like this:

    print("Hello")
    print("World")

It would be automatically re-written like this:

    if (patch_1) then patch_1() else print("Hello")
    if (patch_2) then patch_2() else print("World")

Say you wanted to replace the first line, then you would just do something like this:

    patch_1 = function() print("Goodbye") end

Arguably this isn't the most elegant solution for edit and continue and it gets a lot more complicated with control statements and declarations.  I created a working prototype of this type of system in our Lua IDE/debugger, but edit and continue is going to need some more work before it's ready to be released.

Max

On 11/13/07, Dmitriy Iassenev <iassenev@gsc-game.kiev.ua> wrote:
hi Max,

first of all, thank you for the reply :-)

> Edit and continue is something I've experimented with a bit for
> Decoda. I had pretty good success (at least to a proof of concept
> stage) by rewriting the Lua source code at run-time to allow
> individual lines to be patched. For a basic statement it's something
> like this:

> if (patch_N) then patch_N() else <original code from line N>

> To replace line N, you just create a new function with the code and
> assign it to patch_N. Of course there is some complexity when dealing
> with local variables, upvalues, etc. and constructions like ifs and
> loops, but I think the Lua API provides the necessary hooks and with
> enough effort it can be done. The additional code will also affect the
> run-time performance, but in my experience this isn't really an issue
> for most applications.
you mean, that it is possible to do this using line hooks, i.e.
remember what line user changed in the compiled chunk and then when
the changed line is executing try to execute another (changed) line?
But then how to suppress original line execution?

Or you mean, that you use compiled chunk structure and insert this
logic into it? Is there any description of the compiled chunk internal
structure?

Do Lua authors have ideas about how to implement Edit and Continue?

> We'll probably include something like this in a future version of
> Decoda. Having direct support in Lua for edit and continue would
> certainly be nice, but I assume this is not a simple thing to add into
> the interpreter.
Direct support in Lua would be great, since custom code may be broken
in the next Lua release.


Yours respectfully,

Dmitriy Iassenev, iassenev@gsc-game.kiev.ua
Phone (mobile): +380958392212
  ICQ: 72752187
   GSC Game World - Ukraine, Kyiv
    http://www.stalker-game.com, http://www.gsc-game.com




--
Technical Director
Unknown Worlds Entertainment
http://www.unknownworlds.com
http://www.unknownworlds.com/decoda