17:1d0ae741807e | 18:a96836139ff9 |
---|---|
117 ]] | 117 ]] |
118 | 118 |
119 | 119 |
120 -- Set up a table for holding local functions to avoid polluting the global namespace | 120 -- Set up a table for holding local functions to avoid polluting the global namespace |
121 local M = {} | 121 local M = {} |
122 local MT = {__index = _G} | 122 local MT = {__index = _G, __call = function (M, ...) return M.markdown(...); end } |
123 setmetatable(M, MT) | 123 setmetatable(M, MT) |
124 setfenv(1, M) | 124 setfenv(1, M) |
125 | 125 |
126 ---------------------------------------------------------------------- | 126 ---------------------------------------------------------------------- |
127 -- Utility functions | 127 -- Utility functions |
134 function lock_new_index(t, k, v) | 134 function lock_new_index(t, k, v) |
135 error("module has been locked -- " .. k .. " must be declared local", 2) | 135 error("module has been locked -- " .. k .. " must be declared local", 2) |
136 end | 136 end |
137 | 137 |
138 local mt = {__newindex = lock_new_index} | 138 local mt = {__newindex = lock_new_index} |
139 if getmetatable(t) then mt.__index = getmetatable(t).__index end | 139 local orig_mt = getmetatable(t) |
140 if orig_mt then | |
141 for k, v in pairs(orig_mt) do | |
142 if k ~= "index" then | |
143 mt[k] = orig_mt[k] | |
144 end | |
145 end | |
146 end | |
140 setmetatable(t, mt) | 147 setmetatable(t, mt) |
141 end | 148 end |
142 | 149 |
143 -- Returns the result of mapping the values in table t through the function f | 150 -- Returns the result of mapping the values in table t through the function f |
144 function map(t, f) | 151 function map(t, f) |
1353 | 1360 |
1354 -- If we are being run from the command-line, act accordingly | 1361 -- If we are being run from the command-line, act accordingly |
1355 if arg and arg[0]:find("markdown%.lua$") then | 1362 if arg and arg[0]:find("markdown%.lua$") then |
1356 run_command_line(arg) | 1363 run_command_line(arg) |
1357 else | 1364 else |
1358 return markdown | 1365 return M |
1359 end | 1366 end |