[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: overloading registrations
- From: Diego Nehab <diego@...>
- Date: Wed, 25 Apr 2001 19:53:35 -0300 (EST)
Hi,
> Hmmm, this makes sense. It seems similar to what I have done so far.
>
> I register a series of constants (using lua_setglobal) one for each
> entry point in my interface. I assign them to a bunch of user data's
> which are tagged as ltTestObjectMethod. Then I set the "function" tag
> method for this type of user data. This way I get exactly what I want.
>
> I can write in Lua:
>
> list = anm_listdl()
> append(list,anm_lens())
>
> Now, as long as I have a global named append which is tagged
> appropriately my tag function will get called and more to the point it
> has the following stack:
> "append",<a listdl>,<a lens>
> as long as my user data that I pushed is the string containing append.
>
> Is there a reason why I should do it with upvalues rather than with this
> tag function?
That was a nice workaround. The reason I would use closures is that they
work very well for this problem: having a local constant accessible to a
function without the need to explicitly pass the value as an extra
argument each time the function is called. Besides, Lua does the
alocation and garbage collection for you. And you will probably use less
lines of code. :-)
> Clarify for me please, (I am a lua newbie), if I have a large set of
> access points (around 5000) then I need a stack at least large enough to
> hold all the globals that I will define right?
I believe globals are not stored on the stack. They used to be stored on
a table, the globals table. So, no, you don't need a large stack, though
you will definitely eat up some memory.
Regards,
Diego.