User:OrenBochman/Lua MediaWiki Interface
Appearance
Invocation
[edit]- {{ #invoke: module_name | function_name |arg1 | arg2 | name1 = value1 }}
- #invoke instances are isolated, globals defined in one are not available in another
- Only caches are shared
Module structure
[edit]- A module is a Lua chunk that returns an export
table
- require() provided
- not isolated
- package library provided
Return Value
[edit]The exported function returns a wikitext string:
- Multiple return values are concatenated
- Non-string return values are converted to string
- Metatable entry "tostring" supported
Frame Methods
[edit]- Argument access: args
local name1 = frame.args.name1
- argumentPairs()
local t = {}
for name, value in frame:argumentPairs() do
t[name] = value
end
- getParent()
- Provides access to the parent frame, i.e. the arguments to the template which called #invoke
- Wikitext preprocessing
frame:preprocess('{{template}}')
- Structured template invocation
frame:expandTemplate{
title = 'template',
args = {foo = foo}}
Trying it it out
[edit]local p = {}
function p.hello(frame)
return 'Hello ' .. frame.args[1]
end
return p