lua-users home
lua-l archive

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


I just compiled and installed lua5 final and everything went smoothly.
With lua5b I had written a luaL_getn function that just counted all
the elements in a vector-table as a temporary replacement until lua5
would be released. I deleted this function recomiled and got a
segfault in luaH_getstr. After some debugging this is what I've found
out:The segfault was caused by the line
  luaL_getn(l, -1)
which worked fine with my version but not with the official one of
luaL_getn.That's because right at the beginning of the function there
are the two lines:
  lua_pushliteral(L, "n");
  lua_rawget(L, t);
where t = -1 so rawget is used on the literal. So, this might not
qualify as a bug but it is unexpected behaviour and I assume that
similar utility functions may have this problem as well. It could be
checked wether t<0 and if yes adjust t to t-1. Also shouldn't the fact
that a literal is beeing indexed cause an error instead of a segfault?
Anyway I have solved the problem(although using -1 would make the code
look nicer) but I thought I'd let you know.

Dimitris