lua-users home
lua-l archive

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

On 22/11/13 18:33, Andrew Starks wrote:

I've looked around for this and can't find it. It's not a big deal,
but I find myself wanting to do

t[#t + 1] = v

and in C, that's actually a lot of code. Right now, I'm inlining a
function like this:
int luaL_returnlen(L, index) {
   lua_len(L, index);
   len = lua_tointeger(L,-1);
   lua_pop(L, 1);
   return len;

so that I can inline a function like this:

void luaL_rawsetnexti(L, index){
   lua_rawseti(L, index,luaL_returnlen(L, index) + 1);


So, this works. My question:

Is there a better way with the way the C API? Or is the answer, "Welcome to C!"


For 5.2 there is luaL_len[1] and it's raw counterpart lua_rawlen[2] whilst in 5.1 there is the raw method lua_objlen[3].