SerpentofSetGive feedback
Joined 26 September 2024
SerpentofSet (talk | contribs) mNo edit summary |
SerpentofSet (talk | contribs) mNo edit summary |
||
| Line 1: | Line 1: | ||
I am bad at the game so I edit the wiki | I am bad at the game so I edit the wiki | ||
Below stolen shamelessly from the MediaWiki Scribunto articles | |||
==Examples== | |||
===Invoking module directly=== | |||
Given [[Module:Test]] with the following contents: | |||
<syntaxhighlight lang="lua"> | |||
local p = {} | |||
function p.main(frame) | |||
local args = frame.args | |||
mw.log("log test") | |||
return args[1]..args["sep"]..args[2] | |||
end | |||
return p | |||
</syntaxhighlight> | |||
The following invoke call: | |||
<code><nowiki>{{#invoke:Test|a|sep=;|b}}</nowiki></code> | |||
Can be simulated accurately with the following code in the debug console: | |||
<syntaxhighlight lang="lua"> | |||
=p.main( | |||
mw.getCurrentFrame():newChild{ | |||
title="Module:Test", | |||
args={"a",["sep"]=";","b"} | |||
} | |||
)</syntaxhighlight> | |||
Note that in this example the element in the export table which is being evaluated is called "main". | |||
====Simplified version==== | |||
If the module you are debugging does not use any [[Extension:Scribunto/Lua_reference_manual#Frame_object|frame object methods]] (such as <code>frame:preprocess()</code>), like the example [[#Invoking module directly|above]], then the frame object analog(?) does not have to be complete, and the debugging code can be simplified into the following: | |||
<syntaxhighlight lang="lua"> | |||
=p.main{ | |||
args={"a",["sep"]=";","b"} | |||
}</syntaxhighlight> | |||
What's a sandbox | What's a sandbox | ||