Parameters with Upvalue?

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Parameters with Upvalue?

Todd Lipcon
Hi all,
   I'm very new to Lua and evaluating it for use as the server-side
scripting language for a massively multiplayer online role-playing game
(MMOLRPG). It seems to be fast and expandable, which are the two main
requirements I have. I have been trying to write functions to implement
namespaces by overriding setglobal and getglobal. I'm trying to implement
namespaces by sticking everything into a global table of that name. I'm
using pushcclosure with this table on the stack and a count of 1 for this.
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?

Thanks,
-Todd

-- 

"It's not that easy being green;
Having to spend each day the color of the leaves.
When I think it could be nicer being red, or yellow or gold...
or something much more colorful like that." -Kermit the Frog


Reply | Threaded
Open this post in threaded view
|

Re: Parameters with Upvalue?

Luiz Henrique de Figueiredo
>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