lua-users home
lua-l archive

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


My writer for lua_dump is this:

static int buf_writer( lua_State *L, const void* b, size_t n, void* B ) {
  (void)L;
  luaL_addlstring((luaL_Buffer*) B, (const char *)b, n);
  return 0;
}

the replacement happens inside
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
  if (l > 0) {  /* avoid 'memcpy' when 's' can be NULL */
    char *b = prepbuffsize(B, l, -1);
    memcpy(b, s, l * sizeof(char));
    luaL_addsize(B, l);
  }
}

when prepbuffsize is called, because my stack contains the function being dumped at the top (since that's what lua_dump needs), and prepbufsize does:

    else {  /* no box yet */
      lua_remove(L, boxidx);  /* remove placeholder */

where boxidx == -1, which removes the function off the top of the stack. The light user data initially pushed by luaL_buffinit is just below.

Le jeu. 8 juil. 2021 à 11:27, Xmilia Hermit <xmilia.hermit@gmail.com> a écrit :

> Even weider: sometimes, lua_dump will replace the dumped closure at
> the top of the stack with a full userdata, instead of leaving the
> stack unchanged.

Are you certain that the writer supplied to lua_dump is not the one
leaving the full userdata at the top of the stack? While lua_dump should
not change the stack the writer could do so.

Regards,
Xmilia


--
Benoit.