Put these statements into functions, these functions into a table, and execute all elements of the table:
my_routine =
{ function() print "stat 1" end,
function() print "stat 2" end,
function() print "stat 3" end }
-- Add a 4th statement:
table.insert (my_routine, function() print "stat 4" end)
-- Put the calling code into the metatable, so that you can call your table as a regular function: --
mt = { }
function mt.__call(x)
for _, stat in ipairs(x) do stat() end
end
setmetatable (my_routine, mt)
-- This will execute all statements in the table, in order: --
my_routine()
Limitations:
- you'll have troubles sharing local variables across independent statements
- the syntax is heavy. Metalua offers a lighter syntax for anonymous functions returning a value: "function(x) some_expr(x) end" can be written "|x| some_expr(x)"; therefore the first statement addition above can be written "
table.insert(my_routine, || print('stat 4'))"
If you feel like you need some deeper syntactical or semantic changes in the language, I encourage you to have a look at metalua, which allows you to do so with as little pain as possible:
http://metalua.luaforge.net Fabien.