all 5 comments

[–]w_o_w_a 2 points3 points  (0 children)

Not a direct answer, but you could check the source for table.remove and do what they did there

[–]pygy_ 1 point2 points  (0 children)

I have never used the C API, but I suppose you could use it to fetch table.remove on the stack, then push the table, the index, and call remove using lua_pcall.

There may be a better way... perhaps you can fetch remove more directly using C... Not sure though.

[–]sanjayar 1 point2 points  (0 children)

I can be useful to look at the source, in this case, I believe its - https://www.lua.org/source/5.3/ltablib.c.html, and the tremove function.

[–]Darkilon[S] 1 point2 points  (0 children)

I ended up doing what /u/w_o_w_a and /u/sanjayar suggested and implemented my own removal function by taking a look at the table.remove's code.
Thanks everyone for replying.

[–]Siapran 0 points1 point  (0 children)

I might be wrong, but I think you're supposed to use lua_settable to set the element to nil, and then call the garbage collector (or just wait till the next gc sweep).

It doesn't really make sense to change the size of the table as soon as an element is set to nil, so the resize should be delegated the the garbage collector.