-- Milestone 23: and local attributes. -- : compile-time rejection of reassignment. -- : __close called at every block exit (fall-through, return, break, -- error), reverse declaration order, nil/false skipped. The early-exit and -- error close paths are covered in detail by close_exits.lua. -- Basic read. local pi = 3.14 print(pi) -- 3.14 -- Multiple attribs in one local statement. local x , y = 1, 2 y = y + 1 print(x, y) -- 1 3 -- with __close. local resource_mt = { __close = function(self, err) print("closing", self.name, err == nil and "(no err)" or err) end, } do local r1 = setmetatable({name = "first"}, resource_mt) local r2 = setmetatable({name = "second"}, resource_mt) print("inside do") end print("after do") -- Output: -- inside do -- closing second (no err) -- closing first (no err) -- after do -- nil and false skip __close lookup. do local n = nil local f = false local g = setmetatable({name = "G"}, resource_mt) print("body") end print("end") -- on a value with no __close raises at close time (caught -- by pcall here). Function body is a block; close emission fires -- at its end like any other block. local ok, _err = pcall(function() local bad = setmetatable({}, {}) -- no __close end) print("noclose-pcall returned ok =", ok) -- with a non-numeric value still works. local greeting = "hi" print(greeting)