Hello,
Maybe I missed some scope subtlety, but I'm stuck with a problem which occurs when I call my function with a template invocation, but return the expected result when I call it from the debug console.
I'm trying to code utilities to convert lua tables to wikisyntax tables. So far I coded something that should enable me to add title, data cells and rows to my lua table and return the wikitable, or at least it should. Indeed, my test page[1] return an empty row instead of my expected filled rows. But while editing the module, calling the function return the expected string. Do you have any idea with what's wrong ?
[1] https://fr.wikiversity.org/wiki/Module:Vikitablo/testu
On Mon, Aug 19, 2013 at 10:37 AM, Mathieu Stumpf < psychoslave@culture-libre.org> wrote:
But while editing the module, calling the function return the expected string.
Are you sure it's returning the expected string? When I call your p.datumtestu() function in the debug console, it returns this:
{| class="wikitable alternance centre" |- |- Datumo1 |- |- Datumo2 |- |- Datumo3 |- |- |- Datumo4 |}
That looks far from correct to me; at the least, the "Datumo" lines should begin with "|" rather than "|-".
Le lundi 19 août 2013 à 13:08 -0400, Brad Jorsch (Anomie) a écrit :
On Mon, Aug 19, 2013 at 10:37 AM, Mathieu Stumpf < psychoslave@culture-libre.org> wrote:
But while editing the module, calling the function return the expected string.
Are you sure it's returning the expected string? When I call your p.datumtestu() function in the debug console, it returns this:
{| class="wikitable alternance centre" |- |- Datumo1 |- |- Datumo2 |- |- Datumo3 |- |- |- Datumo4 |}
That looks far from correct to me; at the least, the "Datumo" lines should begin with "|" rather than "|-".
You are right, but that's an other problem. Of course it could be a related side effect, but I think that on this point it's just some intertwinned iterations where I messed up on the treatment. I think I can manage that on my own, but having a working testing page would help me doing so. Now as I don't have a clue how to debug the "no result" for the template invokation, may be I'll try to debug that and hopefuly this will unexpectedly make my scope problem go away.
Ok, now I almost have what I want, I'm already able to dynamically generate wiki tables from lua array, and specify which cell should be a title, have specific style and col/row-span. :)
Now my data module[1] use a hash, and what I would like is to sort my array before I generate my wiki table. So reading some documentation, I thought naively that something like the follwing code, I putted in [2] would work:
function compare(a,b) return a[1] < b[1] end
… dekuma = ciferaro.dekuma table.sort(dekuma, compare) …
But no, it doesn't, I still generate a randomly ordered wiki table. So, what did I missed?
[1] http://fr.wikiversity.org/wiki/Module:Fabeleblo/ciferaro [2] http://fr.wikiversity.org/wiki/Module:Fabeleblo
Le lundi 19 août 2013 à 19:31 +0200, Mathieu Stumpf a écrit :
Le lundi 19 août 2013 à 13:08 -0400, Brad Jorsch (Anomie) a écrit :
On Mon, Aug 19, 2013 at 10:37 AM, Mathieu Stumpf < psychoslave@culture-libre.org> wrote:
But while editing the module, calling the function return the expected string.
Are you sure it's returning the expected string? When I call your p.datumtestu() function in the debug console, it returns this:
{| class="wikitable alternance centre" |- |- Datumo1 |- |- Datumo2 |- |- Datumo3 |- |- |- Datumo4 |}
That looks far from correct to me; at the least, the "Datumo" lines should begin with "|" rather than "|-".
You are right, but that's an other problem. Of course it could be a related side effect, but I think that on this point it's just some intertwinned iterations where I messed up on the treatment. I think I can manage that on my own, but having a working testing page would help me doing so. Now as I don't have a clue how to debug the "no result" for the template invokation, may be I'll try to debug that and hopefuly this will unexpectedly make my scope problem go away.
Wikitech-l mailing list Wikitech-l@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/wikitech-l
On Wed, Aug 21, 2013 at 4:13 PM, Mathieu Stumpf < psychoslave@culture-libre.org> wrote:
But no, it doesn't, I still generate a randomly ordered wiki table. So, what did I missed?
Two things: 1. table.sort() only sorts the sequence part of the table. So only the elements 1-9 in your table, not 0 or A-E. 2. pairs() doesn't process the elements in any particular order; you can see this by printing out the keys as you iterate through using pairs(). You'd need to use ipairs instead (which again only does the sequence part of the table).
Le 2013-08-21 22:54, Brad Jorsch (Anomie) a écrit :
On Wed, Aug 21, 2013 at 4:13 PM, Mathieu Stumpf < psychoslave@culture-libre.org> wrote:
But no, it doesn't, I still generate a randomly ordered wiki table. So, what did I missed?
Two things:
- table.sort() only sorts the sequence part of the table. So only
the elements 1-9 in your table, not 0 or A-E. 2. pairs() doesn't process the elements in any particular order; you can see this by printing out the keys as you iterate through using pairs(). You'd need to use ipairs instead (which again only does the sequence part of the table).
So as I understand it, I will have to create a new table indexed with integers, using pairs, then sort this "itable", before using ipairs on it. It looks to me like something which may be of real common use, so maybe integrating a function in the mw.* library may be interesting. On the other hand may be I'm just not acustomed with the idiomatic way to build lua code and one may suggest me to architecture my code in an other way.
wikitech-l@lists.wikimedia.org