lua-users home
lua-l archive

Re: Locals in Lua Environments

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


Luís Santos wrote:
Hello, People
Hi,
Your problem is that local variables are not accessed via function's environment. You have to use the debug library to do so:
function foo( a, b )
 local z = a + b
 bar()
end
function bar( )
 print( debug.getlocal( 2, 1 ) ) --> a	4
 print( debug.getlocal( 2, 2 ) ) --> b	5
 print( debug.getlocal( 2, 3 ) ) --> z	9
 print( debug.getlocal( 2, 4 ) ) --> nil
end
foo( 4, 5 )
Please refer to Lua's documentation about debug.getlocal (and it's friends: debug.setlocal and debug.getinfo)
--rb

AltStyle によって変換されたページ (->オリジナル) /