This module helps to debug lua errors in modules using the console.
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:
- Create a test module, e.g. Module:Sandbox
- 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 |