lua-users home
lua-l archive

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


I think in Lua 5 you are supposed to say

	local tbl = {}
	local table_size = tbl : getn()

In which case the table is always the first parameter. 
Also, correct me if I am wrong Lua 5 Beta doesn't define luaL_getn but rather luaB_getn. I don't have the latest beta though.

AB
	
> -----Original Message-----
> From: jimmyp_gr [mailto:jimmyp@hal.csd.auth.gr]
> Sent: Friday, April 04, 2003 3:23 PM
> To: Multiple recipients of list
> Subject: luaL_getn bug(well sort of)
> 
> 
> 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
> 
> 
>