[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: A question on the definition of a chunk
- From: Michal Kottman <k0mpjut0r@...>
- Date: Wed, 27 Jun 2012 10:06:51 +0200
On 27 June 2012 08:58, Alexander R. <firstname.lastname@example.org> wrote:
> I'm afraid it's a language problem as my English is not perfect, but do I
> get this right: A chunk in Lua is everything, each piece of code that gets
> executed by Lua is called so, no matter if it's a 50-line-function or a
> single association, et cetera?
Each "thing" you compile using the "load" family of functions - i.e.
luaL_loadbuffer, luaL_loadstring, luaL_loadfile from the C API and
load, loadfile, loadstring from the Lua API - is understood as a
"chunk" and is compiled as if it were a function (without the
"function (...)" header). You can even pass parameters to the chunk
and return values from it:
local paramA, paramB = ...
return paramA + paramB
How big is a chunk is depending on how (often) you call the load*
function - you can either load entire file in one go - then the whole
file is one chunk - or you can compile each line (or series of lines)
as the Lua interpreter does - then each line is its own chunk, and any
locals you define have scope only in that chunk - that line.