OK, so, let me first make it clear that I have no idea how Lua really works, never written more than 10 lines of code in it and that I'm generally confused about how MediaWiki + Scribunto + Lua works...
So...
I have this wiktionary module/template:
https://en.wiktionary.org/w/index.php?title=Module:pl-IPA&action=edit
It looks to me like perfectly valid lua code.
When I try to run some simple example (e.g. calling the function export.convert_to_IPA("something")
), Lua seems to complain that it doesn't know what mw
is.
From what I know, mw
stands for MediaWiki and is a reference to the Scribunto module.
The question is... how do I find and import this mw
module in a simple Lua script running from the terminal... with the Lua interpreter, on Mac?
In general, you can't use
mw
in standalone Lua without MediaWiki. Almost all of the functions it provides are callbacks into MediaWiki's PHP. However, it looks like you just want to useconvert_to_IPA
rather thantemplate_IPA
, and the only usage ofmw
that the former has is this line:for ch in mw.ustring.gmatch(mw.ustring.lower(word), ".") do
. You're lucky:mw.ustring
is the exception to the rule, and it does have a pure-Lua implementation: https://github.com/wikimedia/mediawiki-extensions-Scribunto/tree/master/includes/engines/LuaCommon/lualib/ustringHere's an example of how you can use it (assuming your current directory contains both
pl-IPA.lua
and theustring
directory I linked):