[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Integration of a new library in the Lua interpreter
- From: Philippe Lhoste <PhiLho@...>
- Date: Wed, 10 Jul 2002 16:45:23 +0200 (MEST)
Reuben Thomas wrote:
> There are a couple of potential problems. First, when there may be
> different Lua states assigning different values to the tag (because they
> start up loading different libraries, or in a different order). Secondly,
> if you want to build the Lua library as a DLL, it may not be possible
> (e.g. on EPOC) to use globals at all, or unsafe (if globals are shared
> between processes).
>
> It doesn't sound like it's a problem for you, but still since you already
> have a safe implementation using upvalues to copy, it seems silly not to
> use it. I did the same thing for my rexlib.
Good reasons, thank you. I will stick with my global variables (easier to
manage, pure lazyness) but I will sure use the right way for future public
libraries.
I like also Roberto's idea of using the Lua registry.
Roberto wrote:
> > Once this userdata is pushed on the stack, what does it do there?
>
> It stays there ;-) (But it is not "this" userdata; see below.)
>
>
> > Do I have to pop it out?
>
> Yes.
OK, I was thinking that, but didn't saw it in the liolib.c. Probably just
overlooked it.
Can I do just:
lua_pushusertag(L, pAH, abHandleTag);
lua_settag(L, closedHandleTag);
lua_pop(L, 1);
Does it works? (I know, I can try, say the question (and answer) is for
newbies that do their homework and search the mailing list...)
> > How this affects actually the real userdata? I am lost.
>
> This trick is not simple, and even not completely correct. (That is why
> we changed this whole stuff in 5.0.) When you "push" the userdata, it
> coalesces with the userdata that already exists in Lua, so it is the
> latter than ends up in the stack.
Mmm, I understood that, but just can't figure how changing the tag on the
userdata on the stack changes also the real userdata. Unless on the stack there
is only a pointer to the userdata, and lua_settag actually changes the
pointed object... Or the coalescence works both ways?
Tricky indeed. Of course, it is the result that count :-)
I use as GC function the close() wrapper, the same as for the Lua function.
So it does call the CloseAB() function, changing the tag. Do you see any side
effect? Should I do a separate function, like you did in iolib?
Regards.
--
--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--
Philippe Lhoste (Paris -- France)
Professional programmer and amateur artist
http://jove.prohosting.com/~philho/
--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--=#=--
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net