[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Oddity with tinsert (Lua 4.0)
- From: Reuben Thomas <rrt@...>
- Date: Sat, 11 Aug 2001 14:36:02 +0100 (BST)
If I run the following script:
t = {}
tinsert(t, 3, "hello", 1)
print(t[3])
I get:
1
when I expect
hello
Looking at the source of luaB_tinsert in lbaselib.c, there appears to be a
bug: the first line says:
int v = lua_gettop(L); /* last argument: to be inserted */
i.e. it always inserts tinsert's *last* argument, not its third.
I was bitten by this because I was trying to execute a statement of the form:
tinsert(t, n, gsub(...)), and was getting the number of replacements rather
than the result of the replacement inserted. Surely this is wrong?
Adding
if (v > 3) v = 3; /* adjust to three args maximum */
as the third line of the function cures the problem. Or have I misunderstood
something?
--
http://sc3d.org/rrt/ | egrep, n. a bird that debugs bison