Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between chunk and block in lua

Tags:

lua

what's the difference between chunk and block in lua? I can not understand what is chunk!!!

like image 951
booirror Avatar asked Dec 06 '22 12:12

booirror


2 Answers

A chunk is an independently executable sequence of statements. A block is just a sequence of statements. The difference is that a chunk can be executed independently of other chunks.

All chunks are blocks (sequences of statements), but not all blocks are chunks.

A chunk is basically a Lua function; you can call it with some parameters, and it will return 0 or more values. That's what I mean by "independently executable": the statements within a chunk will be executed in order. But once you exit a chunk, what chunk you execute next is up to you.

like image 92
Nicol Bolas Avatar answered Jan 18 '23 22:01

Nicol Bolas


Has been asked and addressed here: http://lua-users.org/lists/lua-l/2012-06/threads.html#00723

From the 5.2 Manual:

The unit of execution of Lua is called a chunk. Syntactically, a chunk is simply a block: chunk ::= block

From the mouth of Roberto:

The fact that a chunk is a block does not mean that any block is a chunk. Chunks do not nest (unlike blocks). A chunk is an outermost block which you feed to "load".

like image 41
daurnimator Avatar answered Jan 19 '23 00:01

daurnimator