One curiosity...

77 views
Skip to first unread message

Francisco Olarte

unread,
May 18, 2026, 12:51:21 PM (5 days ago) May 18
to lu...@googlegroups.com
While doing some C-module coding I managed to put a table at TOS and do...

  lua_rawseti(L, -1, i);

It was a finger slip, and did lead to an easily fixable bug, but it let me wondering if this ( and some of the variants which can be coded with the table-setting-value-popping functions ) is legal, or I just dodged a bullet by tripping.

I mean, from a direct read of the manual if I do...

int dirty_trick(lua_State *L) {
   luaL_checktable(L,1);
   lua_setop(L,1);
   lua_rawseti(L,1,1);
   return 0;
}

I would expect just an empty stack when reaching the return, and if I call it like....

local t={}
dirty_trick(t)

I would expect t[1]==t and nothing more.

I am not presently using it, but I am asking because if it works this way it could simplify border-case logic in some other code I have.

Francisco Olarte.

Jure Bagić

unread,
May 18, 2026, 1:14:24 PM (5 days ago) May 18
to lu...@googlegroups.com
I am not presently using it, but I am asking because if it works this way it could simplify border-case logic in some other code I have.

The implementation seems to only expect that the value at index is a table,
and that there is at least one value on the stack
that is not marked to-be-closed.

I might be wrong, but to me this use case looks valid and clever.

Francisco, ignore the private email, sometimes randomly,
my email client by default replies to the mailing list or
to the individual, depending if it rained outside.


Reply all
Reply to author
Forward
0 new messages