[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: About lua_State's clone and dostring that can change a local variable
- From: cielacanth <cielacanth@...>
- Date: Sat, 09 Feb 2008 10:54:53 +0900
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!
>