lua-users home
lua-l archive

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


>I have been trying to write functions to implement
>namespaces by overriding setglobal and getglobal.

Although this is a detail, you're not "overriding setglobal and getglobal",
but rather writing "setglobal" and "getglobal" tag methods, right?

>For some reason, in my getglobal replacement, the stack has:
>
>1: the string of the name of the variable
>2: nil!?
>3: the upvalue table.
>
>What I am wondering is why in the world this "nil" value is appearing on
>the stack in between the single parameter to getglobal and the upvalue. As
>far as I can tell, getglobal only has one parameter and one result. Is the
>"nil" a placeholder for my result?

A "getglobal" tag method normally receives 2 arguments: the name of the
global variable and the current value. In this case, it's nil because you
have set "setglobal" and "getglobal" tag methods for tga(nil).
The 3rd argument is there because your tag method is a closure.

--lhf