lua-users home
lua-l archive

Re: Life cycle question...

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


A "chunk" is a syntactical concept. At run time, chunks are loaded in
Lua as functions. Those functions are subject to garbage collection,
like all objects inside a Lua environment. Of course, if a chunk defines
other functions, to "unload" the chunk you have to free those functions,
too.
For instance, assume a chunk like this:
 function a () print(1) end
 function b (x) return x+1 end
Once you load it, running << chunk = loadfile("filename") >>, Lua
creates a new function that represents the chunk. Once you call
that function, running << chunk() >>, it creates two new global
variables, "a" and "b". If you set "a", "b", and "chunk" to nil (or any
other value), the three functions are now garbage and are eventually
collected.
-- Roberto

AltStyle によって変換されたページ (->オリジナル) /