My confusion comes from luaL_addlstring, a code that works fine for lua53. luaL_addlstring may create a value of toclose, which is throw error when I try to remove a value on the stack after call luaL_addlstring.
Maybe it should be added in manual.
> It was thus said that the Great Roberto Ierusalimschy once stated:
> > > The manual states for lua_toclose():
> > >
> > > [...] AN INDEX MARKED AS TO-BE-CLOSED SHOULD NOT BE REMOVED FROM
> > > THE STACK BY ANY OTHER FUNCTION IN THE API EXCEPT LUA_SETTOP OR
> > > LUA_POP.
> > >
> > > [...]
> > >
> > > [...] It might be that moving the item to be
> > > cleaned is disallowed as well and the manual doesn't mention it.
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > It seems it does.
>
> No, it wasn't removed, it was *moved*. As I stated in the email
> (switching the comments to use a Forth-like stack notation):
>
> // before -- after | stack
> lua_pushinteger(L,1); // -- i | i
> lua_newtable(L); // -- t | t i
> luaL_newlib(L,mt); // -- t | t2 t i
> lua_setmetatable(L,-2); // t2 x -- x | t i
> lua_toclose(L,-1); // -- | t i
> lua_remove(L,-2); // ? -- ? | t
>
> When lua_tclose() was called, the stack looked like:
>
> -1 table marked as to-close
> -2 integer
>
> The lua_remove(L,-2) is removing the integer, not the variable marked as
> "to-close". It's *moved*, not *removed*, unless the act of "moving" is the
> same as "remove, then insert".
What is marked to be closed is the index, not its value (see manual).
An index cannot be moved.
-- Roberto
--