[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Problem w/lua_pushuserdata
- From: Edgar Toernig <froese@...>
- Date: Sat, 07 Apr 2001 03:39:11 +0200
Matthias Gall wrote:
>
> When I push NULL from the C-function like this:
>[...] lua_pushuserdata (m_pLuaState, O); [...]
> get's anything, but never "nil" when it should.
Who said that a pushuserdata(NULL) gives a nil? You're right that it is
broken in Lua 4.0 - you get a userdata object with some kind of random
pointer but expecting nil...
This patch will fix the bug:
--- src/lstring.c Sat Apr 7 03:22:54 2001
+++ src/lstring.c Sat Oct 30 18:49:00 2001
@@ -119,7 +119,7 @@
ts->nexthash = NULL;
ts->len = s;
ts->u.d.tag = 0;
- ts->u.d.value = (udata == NULL) ? uts+1 : udata;
+ ts->u.d.value = s ? uts+1 : udata;
L->nblocks += sizestring(s);
/* insert it on table */
newentry(L, &L->udt, ts, IntPoint(ts->u.d.value) & (L->udt.size-1));
> lua_pushuserdata _should_ work with a NULL pointer for obvious reasons.
> Any ideas?
It's simply a bug ;-) But if you expect a nil you have to change your
code too.
Ciao, ET.
PS: Be careful when using userdata objects with the default tag...