lua-users home
lua-l archive

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


this is the complete syntax of lua:


chunk ::= {stat [`;´]} [laststat [`;´]]

block ::= chunk

stat ::=  varlist `=´ explist | 
functioncall | 
do block end | 
while exp do block end | 
repeat block until exp | 
if exp then block {elseif exp then block} [else block] end | 
for Name `=´ exp `,´ exp [`,´ exp] do block end | 
for namelist in explist do block end | 
function funcname funcbody | 
local function Name funcbody | 
local namelist [`=´ explist] 

laststat ::= return [explist] | break

funcname ::= Name {`.´ Name} [`:´ Name]

varlist ::= var {`,´ var}

var ::=  Name | prefixexp `[´ exp `]´ | prefixexp `.´ Name 

namelist ::= Name {`,´ Name}

some Personal view:

function foo() ... end is the semantics sugar of foo = function() ... end, but one can write
local t = {}
t[1] = function() end

but can not write:
local t = {}
function t[1]() end

so maybe:
funcname = var [`:' Name]