lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

If I run the following script:

t = {}
tinsert(t, 3, "hello", 1)

I get:


when I expect


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?


if (v > 3) v = 3; /* adjust to three args maximum */

as the third line of the function cures the problem. Or have I misunderstood

-- | egrep, n.  a bird that debugs bison