lua-users home
lua-l archive

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


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".  

  -spc