lua-users home
lua-l archive

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


I'm enumerating local vars with:

    lua_Debug debug_info;
    int level = 0;
    while (lua_getstack(ls, level++, &debug_info) == 1)
    {
        const char* tmp = 0;
        int i = 1;
        while ((tmp = lua_getlocal(ls, &debug_info, i++)) != NULL)
        {
	    //.....

            lua_pop(ls, 1);
        }
    }

my lua-script is:

	local val = nil

	local val = exampleGet()

	print(val)

when enumerating on the 3. line, I get two variables 'val', one nil and one number. why is that?

Am 02.06.2011 13:45, schrieb Luiz Henrique de Figueiredo:
If there was a way to plug into global name lookup in the compiler, we
could accurately describe to the compiler what global variables exist

See a patch in
	http://lua-users.org/lists/lua-l/2006-10/msg00206.html

This has often been mentioned here before. See these threads:
	http://lua-users.org/lists/lua-l/2010-07/msg00512.html
	http://lua-users.org/lists/lua-l/2009-11/msg01020.html
	http://lua-users.org/lists/lua-l/2008-02/msg00814.html
	http://lua-users.org/lists/lua-l/2007-08/msg00409.html

It might even be possible to compile expressions such as string.byte
to a constant reference in the byte code, so that the need for the
"local byte = string.byte" pattern goes away.

This is not hard to do with token filters.