A way to write code "in the debugger" in Lua?

I played a little with Lua and tried the Koneki eclipse plugin, which is pretty nice. The problem is that when I make changes to the function that I am debugging, at the moment the changes do not take effect when the changes are saved. Therefore, I have to restart the application. It would be so nice if I could make changes to the debugger, and they would be effective on the fly, for example, with Smalltalk or to some extent, as when replacing the hot code with Java. Does anyone know if this is possible?

+6
source share
1 answer

To some extent this is possible with some limitations. I am developing an IDE / debugger that provides this feature. This gives you access to the remote console to execute commands in the context / environment of your running application. The IDE also supports live coding , which reloads the changed code when changes are made to it; see demos here .

The main limitation is that you cannot change the current function (at least without changes in the Lua VM). This means that the effect of your changes on the current work will be displayed only after logging out and re-entering this function. It works well for environments that repeatedly call the same function (for example, the game engine calling draw ), but may not work in your case.

Another problem is with upvalues ​​(values ​​created outside of your function and referenced within it). There are methods to β€œread” the current values ​​of up -ues and recreate them when creating a (new) function, but this requires some code analysis to find which functions will be recreated, request them for upvalues, get the current values, and then create a new one environment with these values ​​and assign them the appropriate values. My current implementation does not do this, which means you need to use global variables as a workaround.

There was also relevant discussion only the next day on the Lua mailing list.

+5
source

Source: https://habr.com/ru/post/943630/


All Articles