lua-users home
lua-l archive

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


Hi.

Maybe I can do it, too.
Thank you so much for your advice !

> I've done this for an internal debugger project.
>
> * Use loadstring to turn the code string into a function 'f';
> * Create an empty environment table 'e';
> * Create a metatable 'm' with __index and __newindex metamethods that
> use debug.getinfo, debug.getlocal, debug.setlocal, etc to check
> locals, then upvalues, then the environment of the currently executing
> function and get/set the value as appropriate.
> * Set 'm' as the metatable of 'e' and 'e' as the metatable of 'f'.
> * Call f.
>
> Now, when the code is run within your hook, any accesses to variables
> not defined in the debug string ("a = 100") will be trapped and modify
> the appropriate local/upvalue/global in the current execution context
> in which the debug hook was triggered.
>
> Hope this helps!
>