Jump to content

Module:Flag and Module:Flag/sandbox: Difference between pages

(Difference between pages)
Page 1
Page 2
Content deleted Content added
simplify
 
add metatable
 
Line 136: Line 136:
p['IOC athlete'] = p.IOCathlete
p['IOC athlete'] = p.IOCathlete


return setmetatable (p, {['__index'] = -- returns table p with the metatable __index set so that, if the table KEY isn't recognized, it returns
local function index (_, key) -- This function gets called by the metatable as index(table, key)
function (_, key) -- this anonymous function called as function(p, KEY)
return function (frame) return _main(frame, 'Flag', 'unc', key) end -- Interpret it as {{flag|key}} as pass to _main()
end
return function (frame) return _main(frame, 'Flag', 'unc', key) end -- which interprets the module call as {{flag|KEY}} and passes it to _main()

end
local metatable = {['__index'] = index} -- Set __index, which is returned if table[key] is nil, to the index function
})

setmetatable (p, metatable) -- Assign the metatable to the returned table

return p