模块:Deep4 ExprDirect
可在模块:Deep4 ExprDirect/doc创建此模块的帮助文档
local p = {}
function p.test()
local results = {}
-- Call expr directly
if mw.ext and mw.ext.ParserFunctions then
results[1] = "ext_keys: "
local ek = {}
for k in pairs(mw.ext) do ek[#ek+1] = k end
results[1] = results[1] .. table.concat(ek, ",")
if mw.ext.ParserFunctions.expr then
local expr_fn = mw.ext.ParserFunctions.expr
results[2] = "expr_type=" .. type(expr_fn)
-- Try calling with a number
local ok1, r1 = pcall(expr_fn, "1+1")
results[3] = "expr(1+1)=" .. tostring(ok1) .. ":" .. tostring(r1)
-- Try calling with a string
local ok2, r2 = pcall(expr_fn, "2*3")
results[4] = "expr(2*3)=" .. tostring(ok2) .. ":" .. tostring(r2)
else
results[2] = "no_expr_func"
end
else
results[1] = "no_ext"
end
return table.concat(results, " | ")
end
return p