Fandom

Wikia Developers Wiki

Lua templating/Debug console

< Lua templating

889pages on
this wiki
Add New Page
Talk0 Share
Consoledebug
The Debug console is a tool that allows one to quickly try out some code in real time. It is only available when editing a module in the Module:Namespace as show in the screenshot.

Purpose

This helps to debug one or more modules without having to leave the current page and without having to save a page. A good introduction for lua is available in Wikiversity[1].

Usage

There are primarily two ways to interact with the debug console. One by directly typing text and waiting for the output, and the other is to access functions in the code editor.

Direct

Debugusage

The simplest way to use the code editor is to write code directly in it and pressing "enter". The results may take some time because they are returned from the server.

Example

 print (5 * 6)
Output:
30

Code editor

ConsoleDemo1
One can quickly put code in the code editor and try it out using the console before saving as depicted in the image. This helps to try out a lot of code without filling up the debug console, and it reduces the need to copy paste from console to editor.
--Code Editor 
local p = {}
 
function p.morning()
   return "Good morning to you too"
end
 
return  p
--Console
print (p.morning() )

Other functions from external modules

Trying other functions from modules stored in other pages is also possible. This is possible using:

--Module:Morning
local p = {}
 
function p.morning()
   return "Good morning to you too"
end
--Console
local storedModule = require ("Module:Morning")
print (storedModule.morning() )
Output: 
Good morning to you too

Global Modules

Modules stored in a central repository (dev.wikia.com) can also be accessed in a similar manner to external modules by writing:

local storedModule = require ("Dev:Morning")
print (storedModule.morning() )

Limitations

Functions that use the frame can't be easily tested using the console, and may show errors when a regular invoke wouldn't especially if they use things such as frame:preprocess() or frame:getCurrentTitle(). One way around this is to create a fake frame such as the one used in Module:Debug to test out the functions.

Tips and tricks

Rather than writing the whole text each time or pasting it into the console, one can add commonly used functions or code to MediaWiki:Scribunto-console-intro. This will allow anyone in the community easy access to them.

Notes

Most of the library can be accessed without any problems. However, the frame library is inaccessible because it is only created through an {{#invoke.

See also

References

  1. https://en.wikiversity.org/wiki/Lua

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.