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 Meir Shpilraien once stated:
> Hey,
> I was wondering whether or not it's OK to pop out from the stack the
> arguments given to a native C function from Lua code. I am asking
> because users might send a lot of arguments to the C function (using unpack
> for example) and acquire all the room on the stack (which is set by default
> to 8K), leaving no place to push replies or perform other operations that
> require the stack.
> I am using Lua 5.1.5 (if it makes any difference).

  It depends on what you are "popping" out.  Values like floats or integers
are fine if you have them cached in some C variable, but strings are another
issue.  This:

	char const *s = lua_tostring(L,idx);

may cause an issue as a garbage collection could occur and invalidate the
address in s [1].  Similar issues arrise with userdata, and there's no way to
reference a table *except* through the Lua stack.

  You might also want to check out lua_checkstack() to see if you have
enough stack space to do all you need to do and if not, handle the situation
appropriate to what you are trying to do.


[1]	Unless you know a reference to the string (or userdata) exists
	elsewhere, but in general, you shouldn't rely upon this.