Fandom

Wikia Developers Wiki

Global Lua Modules/Debug

< Global Lua Modules

896pages on
this wiki
Add New Page
Talk0 Share

This module helps to debug lua errors in modules using the console.


Install

Installing modules

To get a brief introduction to lua read the basics page first. On Wikia, one can use modules by either accessing a module remotely or copying all its contents to a Wiki. Modules accessed remotely from dev.wikia are subject to change while 'correctly' copied modules are controlled by a particular wiki.

Using a module "remotely" using Module:Devmodule

Create Module:Devmodule and copy the following code to remotely access modules in dev's repository. See more details in Global Lua Modules/Devmodule.
--[[This imports modules from dev.wikia]]
return require("Dev:Devmodule")

Loading modules remotely from dev.wikia

Create Module:Debug in your wiki and add the following code:
--This loads modules directly from dev.wikia.com
return require("Dev:Debug")

Using Module:Debug in another wiki

To use modules without depending on dev see this page. Create Template:Debug in your wiki and add the following code:
{{#invoke:Debug|main}}

Using template in a page

You can use this module in a page using syntax such as:
{{Debug|main|arg1|arg2}}

Description

It contains a method that emulates a full frame in the console, and allows one to debug some lua modules without having to save them.

Usage

Within the console import the module and initialize it. First import this module, then use the frame function to generate a new frame.

local dbg = require("Dev:Debug")
local fakeFrame = dbg.frame({param1, param2})

Example

Follow the following steps:

  1. Create a test module, e.g. Module:Sandbox
  2. Paste the following code into the text area
local p = {}

function p.test(frame)
    return "Hello " .. (frame.args[1] or "missy")
end

function p.test2(frame)
    return "Hello " .. (frame:getParent().args[1] or "missy")
end

return p
  • Now paste the following text in the debug console of a test module
-- Console code
local dbgModule = require("Dev:Debug")
 
-- Then use the frame method to create a fake test frame.
local childFrame = {"Child"}
local parentFrame = {"Parent"}
local frame = dbgModule.frame(childFrame, parentFrame)
 
-- The method above accepts two parameters as tables, one represents the parent
-- frame, and the other the child. Finally pass this frame to a function:
local message1 = p.test(frame)
local message2 = p.test2(frame)
 
print("Message 1:", message1)
print("Message 2:", message2)
Message 1:	Hello Child
Message 2:	Hello Parent

PseudoFrame functions

The frame method currently only supports the functions in the table below:

Function Notes
getParent() This works pretty much like the original
preprocess() Simply returns the text as the frame isn't available to do preprocessing
showargs() Shows a list of arguments contained in both parent and child frame
setargs Sets the arguments
.frame Creates a frame object

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.