Hello,
Sorry for the noise, but I didn't know where to post this. Please point me any place more appropriate for this kind of topic if you know one.
So, I begin to play with Lua, trying to rewrite piece a software which take a digit ([0-9]*) in input, and provide a "how you spell/pronounce it" string in various languages in output. Well, that's not a transcendent goal, but I think it's a good way to learn this new tool.
Now that I have a minimal piece of functions (but nothing close to even a single language decent support), I wanted to make a unit tests page.
But I'm blocked, because I don't find how to call my main module within my test module. For those interested, pages are there : https://fr.wiktionary.org/wiki/Module:Pr0n https://fr.wiktionary.org/wiki/Module:Pr0n/test https://fr.wiktionary.org/wiki/Utilisateur:Psychoslave/test_pr0n
And the relevant part are:
pron = require( "Module:Pr0n" ) for i=0,99 do pron.ortho(i) -- fail! end
Here is the error message:
Erreur Lua dans Module:Pr0n à la ligne 37: attempt to index local 'frame' (a number value).
Trace arrière:
Module:Pr0n:37 : dans la fonction « ortho » Module:Pr0n/test:8 : dans la fonction « chunk » mw.lua:463 : dans la fonction « chunk »
On Tue, Apr 2, 2013 at 9:46 AM, Mathieu Stumpf psychoslave@culture-libre.org wrote:
Sorry for the noise, but I didn't know where to post this. Please point me any place more appropriate for this kind of topic if you know one.
https://www.mediawiki.org/wiki/Talk:Lua_scripting is generally a good place, as is https://en.wikipedia.org/wiki/Wikipedia:Lua_requests if you can avoid sounding too off-topic. As for mailing lists, wikitech-l might be appropriate too.
And the relevant part are:
pron = require( "Module:Pr0n" ) for i=0,99 do pron.ortho(i) -- fail! end
Here is the error message:
Erreur Lua dans Module:Pr0n à la ligne 37: attempt to index local 'frame' (a number value).
Your function expects a frame object,[1] as is required for it to be called from #invoke, and you're passing it a number.
You can create a new frame object with mw.getCurrentFrame():newChild.[2] Or, if the only thing you're using from the frame object is frame.args, you can cheat and call it something like
pron.ortho( { args = { i } } )
Another option is to make two functions: one which takes a number, and a second which takes a frame, extracts the number, and calls the first:
-- This can be called from other modules, test cases, etc function pron.orthoInternal( number ) { -- Existing code here }
-- This wrapper is for calling using {{#invoke:}} function pron.ortho( frame ) { return pron.orthoInternal( frame.args[1] ) }
[1]: https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#Fram... [2]: https://www.mediawiki.org/wiki/Extension:Scribunto/Lua_reference_manual#fram...
wikimedia-l@lists.wikimedia.org