lua-users home
lua-l archive

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


Thank you for your reply, and so fast, I had thought 'load' can solved it ,  and gone to a wrong way.
I know top post is not right, but Gmail somehow change it. 

2014-07-19 23:15 GMT+08:00 Rena <hyperhacker@gmail.com>:
On Sat, Jul 19, 2014 at 11:05 AM, 俞江 <devyujiang@gmail.com> wrote:
> 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()
>

OK, in that case you'd want to do something like:

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.