|
On Sat, Jul 19, 2014 at 11:05 AM, 俞江 <devyujiang@gmail.com> wrote:OK, in that case you'd want to do something like:
> Oh, I just cut it from my code so ... sorry for my mistake.
>
> local num = 1
> function print_num()
> print(num)
> end
> return {print_num = print_num}
>
> and Used as:
>
> A = require('a')
> A.print_num()
>
local i = 0
repeat
local name = debug.getupvalue(A.print_num, i)
if name == 'num' then
debug.setupvalue(A.print_num, i, 100)
break
end
i = i + 1
until not name
Though, the first line might need to start i at 1 rather than 0. I'm
not sure which works. Also, this will fail silently if used on a
function that doesn't have any upvalue named num.
(BTW, list etiquette states that you should type your reply after the
text you're replying to. That makes the conversation easier to read.)
--
Sent from my Game Boy.