lua-users home
lua-l archive

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


On Mon, Jan 29, 2018 at 1:01 AM, Sean Conner <sean@conman.org> wrote:
> It was thus said that the Great Coda Highland once stated:
>> On Sun, Jan 28, 2018 at 3:39 PM, Sean Conner <sean@conman.org> wrote:
>> > It was thus said that the Great Paige DePol once stated:
>> >>
>> >> So, if you could add any one feature to Lua right now, what would that
>> >> feature be and why would you want to see it added? Please note that this
>> >> discussion is in no way meant to be interpreted as pressuring Team Lua to
>> >> add any features to Lua, I am genuinely curious what features people want
>> >> to see added to Lua and why.
>> >
>> >   Right now---breakpoints.  Every CPU I've programmed has had such a
>> > feature.  The x86 has INT3, the MC68000 has TRAPn, MIPS the BREAK, the 6502
>> > BRK, the 6809 SWI, etc.  I would like to see a Lua VM opcode that does the
>> > same thing, which could be used to avoid the overhead of hooks (the Lua
>> > program can run full speed until the breakpoint is hit).
>> >
>> >   Some API in the debug module would probably have to be made to support
>> > this, but it's something I feel would be nice.  Even something as simple as
>> > tripping on a function call:
>> >
>> >         debug.setbreakpoint(target_function,code_to_run)
>> >
>> > where code_to_run() can then do the full hooks method if further detail was
>> > needed.
>> >
>> >   -spc
>>
>> I mean, Javascript has the debugger; statement.
>>
>> If you want to imitate this behavior, all you need to do is write a
>> trivial C API function and call it. It checks for a suitable debugger
>> hook, calls it if present, and returns. This doesn't require any
>> changes to the VM.
>
>   I'm not sure what you mean.  Yes, Lua can hook into function calls, but
> it's *every* function call.  What I'm talking about is some flag such that
> if function foo() is called, then a hook is called; otherwise the Lua VM
> runs at full speed.
>
>   -spc
>

I mean an artificial hook introduced by the debugger, not a hook built
into the Lua VM. Perhaps the debugger installs a function in the
registry under a specific key that the breakpoint() function looks
for.

If you want to install a breakpoint on a specific function, then you
have to wrap it or monkey-patch it. I've pondered over the possibility
of a parser patch / token filter / whatever for those cases where you
can't modify the code for whatever reason and the function in question
is stashed in a local so you can't monkey-patch it. But just having a
breakpoint() function is a huge step in the right direction and -- as
I said -- requires no change to the parser or the VM.

/s/ Adam

/s/ Adam