lua-users home
lua-l archive

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


于 2012-4-24 23:16, Rodrigo Dias Arruda Senra 写道:
Hello,

...

My question is: How to change local variables (from C code) ?
I read several threads about merging upvalues, and did some experiments
but  my current understanding is that it will not work because
local variables are registers and are not stored in _ENV.

Is this possible ? How ?

Any pointers would be appreciated.
best regards,
Rod Senra

http://rodrigo.senra.nom.br



if I understand correctly, your debugger takes control as a Debug Hook, right ?
if so, the local variable still lives on the stack.
just refer to the debug information of the Proto to see which stack slot it lives in.

however, by only using the public API, this can be done, but not very efficiently.
see the documents of lua_getinfo, lua_getlocal, lua_setlocal, etc.

yet since you are writing some kind of debugger, you may be able to use some inernal APIs,
i.e. the functions annotated with LUAI_FUNC. see luaF_getlocalname in lfunc.c for such examples.