lua-users home
lua-l archive

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

On 12/17/2014 01:12 PM, Lev wrote:
On Wed, 17 Dec 2014 12:39:21 +0100
Thomas Jericke <> wrote:

Depends on the usecase. Normally I would call luaL_newstate only once.
And then run all the scripts in the same state. Now there is one
issue here, if your scripts use globals you need to ensure that you
don't have any conflicts.
Thanks for the answer. Yes, I set global variables each time I call my
scripts. Shall I call lua_settop(L, 0) before any stack operation, and then
let the garbage collector do the right thing?

Thanks again,
Globals are not stored on the stack and therefore lua_settop(L, 0) won't clean any globals. Calling lua_settop(L, 0) after running a script only removes any results returned by the previous script. If you don't return any results from the scripts you can simply ignore them by setting nresults of lua_pcall to zero.