- 🚀 Quick start
- ✨ Features
- 🖥️ Setup Instructions
- 🐞 Debugging in VS Code
- 📁 Project Structure Example
- 🧪 Simple Example
- 🛠️ Plans / Ideas
Minimal implementation of the mw object for testing and debugging Wikipedia Lua modules outside of MediaWiki.
⚠️ This is a lightweight mock. It is not complete or production-safe — intended for development and debugging only.
First add a module to your repo:
# add to your repo
git submodule add https://github.com/Eccenux/wiki-lua-mw-mock.git mw
# commit the change
git commit -am "Add 'mw' submodule"There are many other ways. Like e.g.: download zip of this repo an unzip to "mw" subdirectory, download once and create a symlink (Unix) or junction (Windows).
Quick example:
-- include this library
local mw = require("mw/mw")
-- replace require to support namespace removal
local originalRequire = require
function require(moduleName)
moduleName = moduleName:gsub("Modu[^:]+:", "")
return originalRequire(moduleName)
end
-- Load a copy of a module
-- Note that this loads "Piechart.lua" file (a local file).
local p = require('Module:Piechart')
local json_data = '[{"label": "k: $v", "value": 33.1}, {"label": "m: $v", "value": -1}]'
local html = p.renderPie(json_data)
mw.logObject(html)- Implements a minimal
mwtable with placeholders for:mw.log,mw.logObjectmw.textmw.ustring(proxy tostring)
- Useful for writing and testing Lua modules locally before deploying to Wikipedia or Wikidata.
- Pure Lua — no dependencies.
After this lua and luac should be available in your terminal.
Install Lua on Windows using Scoop.
If you don’t have Scoop yet:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-ExpressionThen install Lua:
scoop install luaInstall Homebrew.
Then install Lua:
brew update
brew install luaInstall Visual Studio Code.
Install the Lua Debug extension by actboy168:
Extension ID: actboy168.lua-debug
-
Create a
.vscode/launch.json:{ "version": "0.2.0", "configurations": [ { "type": "lua", "request": "launch", "name": "Launch Lua script", "program": "${workspaceFolder}/_test.lua" } ] } -
Create a test file, e.g.
_test.lua:mw = require("mw") -- your mock mw.log("Hello from mock mw!") mw.logObject({ foo = "bar", nested = { a = 1 } })
-
Set breakpoints, hit F5 to debug.
lua-wiki/
│
├── mw/
│ ├── mw.lua -- mw entry point
│ ├── text.lua -- mw.text mock
│ ├── ustring.lua -- mw.ustring proxy
| ...
├── _test.lua -- your dev entry point
-- _test.lua
require("mw")
local data = {
title = "Example",
ns = 0,
isTalk = false,
}
mw.logObject(data)- Add more realistic implementations (e.g. Unicode support in
mw.ustring). - Other mocks/implementations?
- Optional strict mode to catch unexpected fields.