Help:Lua debugging: Difference between revisions

Content deleted Content added
Dcoetzee (talk | contribs)
== Support == If you're still stuck and not sure how to proceed, please leave a note on Wikipedia:Lua requests requesting debugging help.
Module sandboxing
Line 24:
 
A tactic, for dealing with older bugs, is to plan to run special extra test data to activate code areas, or show debug-display output, where new Lua script might be added, to provide a [[sanity check]] that the affected areas are functioning soundly, before adding too much new, detailed logic. In most cases, note: "''proofreading is the fastest form of testing"'' if having the patience, or mental memory power, to review the details of older source code. However, another tactic is to reserve specific test-data values to trigger debug-display code which dumps the values of all related data to the screen, or provides a call-tree list to ensure the logic flows into various function sections as expected. In many cases, human memory cannot cope with details beyond 5-9 variables, and so debug-display becomes an easier option, despite the extra time needed to write the debug-print statements into the Lua module. Be careful to proceed slowly, because once extensive amounts of new Lua script are added, then it can become a puzzling guessing game whether the problems were caused by "all the new stuff" rather than by pre-existing bugs in the older Lua script.
 
== Lua sandbox ==
The English wikipedia has the [[mw:Extension:Template sandbox|Template Sandbox]] extension installed. There is a Synergy bewteen the "template sandbox" and "Scribuntu" extensions, which allows to develop and modify Lua modules in private (i.e., in the user space) pages, before moving them to the global space.
=== How to use "Template Sandbox" to develop scribuntu module? ===
Let's take a practical example. for this example, assume your user name is "Lua Developer". Let's say you want to test a bug-fix or enhancement to the [[Module:String|String]] module. There are two reasons you can't do it directly: this module contains functions that are used by hundreds of templates, transcluded in milions of articles. any bug will present a huge disruption to wikipedia. The 2nd reason is more prosaic: because this module is so central, it is also protected, and our "Lua Developer" user does not have the required permissions to modify this module.
 
So, the first stem in "sandboxing" is to copy [[Module:String]] to the private page [[User:Lua Developer/sandbox/Module:String]]. Now our developer can edit the module to her heart's content. at any given moment, she can open [[Special:TemplateSandbox]], and use the default "Sandbox prefix", which in her case, will be "User:Lua Developer/sandbox". This means that viewing any page from the sandbox, whenever the parser encounters a Template '''T''' or Module '''M''', it will look forst to see if a page named "User:Lua Developer/sandbox/Template:T" or "User:Lua Developer/sandbox/Module/M" exists, and if so, will use those for the parsed page, instead of the ones in the "real" namespaces. For any template or module which do not exit under the "Sandbox prefix", the parser will use the regular ones.
 
From the Template sandbox, the developer can view any page, and see it as it would look like after the modules and templates will be copied to the corresponding namespaces. The developer can also enter raw wikitext, and ask the parser to parse it using the faux templates and modules she created under the "Sandbox prefix"
 
=== Small caveat: The case of the wrong case ===
Wikipedia has a small perversion regarding pange name casing: it will convert the first character of a page name to uppercase, regardless of the way it was entered. To compensate, it also converts the first letter of a template (when transcluded) and module (when invoked) to uppercase. however, this does not extend to the sandbox, because in the sandbox "the first letter" is not the first letter any more. Here is an actual example: for real modules, let's say [[Module:String]], mediawiki software will allow you to use <nowiki>{{#invoke:String|replace|Hara I am|a|e}}</nowiki> to return "Here I em" (try it). It will also allow you to use <nowiki>{{#invoke:string|replace|Hara I am|a|e}}</nowiki> to get the same result:
{|class="wikitable"
|-
! wikitext !! result
|-
|<nowiki>{{#invoke:String|replace|Hara I am|a|e}}</nowiki>||{{#invoke:String|replace|Hara I am|a|e}}
|-
|<nowiki>{{#invoke:string|replace|Hara I am|a|e}}</nowiki>||{{#invoke:string|replace|Hara I am|a|e}}
|}
 
However, if our developer would create a page named [[User:Lua Developer/sandbox/Module:string]], she would not be able to invoke this module in any way, because the parser will look for a page named "Module:String" and not "Module:string" under the sandbox prefix, Wikipedia will not convert the name to "Module:String" (because it only converts the 1st character in the page name), and will not find it, so it will take the module from the main namespace (if such module exists), or will complain that the module does not exist.
 
 
== Plan for extensive debug-display code ==