[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Multiple luaL_loadfile()/lua_pcall() and persistance
- From: Roberto Ierusalimschy <roberto@...>
- Date: Mon, 23 Jul 2018 09:37:08 -0300
> I'm on a tool that load then execute several Lua scripts so I have many call to luaL_loadfile()/lua_pcall() pairs. My question is about code persistence.
>
> 3 examples :
>
> --- script1.lua ---
> print "I'm doing very interesting stuffs"
> ---
>
> --- script2.lua ---
> function toto()
> print "even more interesting stuffs"
> end
> ---
>
> --- script3.lua ---
> print "Yeah, I'm here"
>
> function tata()
> print "I'm the most interesting one"
> end
> ---
>
> My assertions are the following :
>
> 1/ content of script1 is only one shot so it is collected and resource are freed
> 2/ toto() and tata() kept, ready to be called by other code.
> 3/ after loading/calling all those 3 script, in Lua's memory only toto() and tata() remain, and "external" prints get collected after execution.
>
> Am I right ?
Yes. 'toto' and 'tata' are kept because they are assigned to global
variables. Everything else is eventually collected, provided you removed
from the stack the result from 'luaL_loadfile()' after calling
'lua_pcall()'.
-- Roberto