# HG changeset patch # User Matthew Wild # Date 1352520150 0 # Node ID a96836139ff97b076ebf1097912c8f26f952fcb8 # Parent 1d0ae741807ef3dc183fd392b5c75835a8b826d5 parsers.markdown: Make module callable, to allow parsing text as a module diff -r 1d0ae741807e -r a96836139ff9 parsers/markdown.lua --- a/parsers/markdown.lua Sat Nov 10 03:54:44 2012 +0000 +++ b/parsers/markdown.lua Sat Nov 10 04:02:30 2012 +0000 @@ -119,7 +119,7 @@ -- Set up a table for holding local functions to avoid polluting the global namespace local M = {} -local MT = {__index = _G} +local MT = {__index = _G, __call = function (M, ...) return M.markdown(...); end } setmetatable(M, MT) setfenv(1, M) @@ -136,7 +136,14 @@ end local mt = {__newindex = lock_new_index} - if getmetatable(t) then mt.__index = getmetatable(t).__index end + local orig_mt = getmetatable(t) + if orig_mt then + for k, v in pairs(orig_mt) do + if k ~= "index" then + mt[k] = orig_mt[k] + end + end + end setmetatable(t, mt) end @@ -1355,5 +1362,5 @@ if arg and arg[0]:find("markdown%.lua$") then run_command_line(arg) else - return markdown + return M end