Topic on Project:Support desk

"mw.getCurrentFrame():getParent()" is a broken table

3
Taylor 49 (talkcontribs)

Extension:Scribunto/Lua reference manual#frame:getParent

[SCRIBUNTO] I can seize single parameters passed to the caller using "mw.getCurrentFrame():getParent().args[1]". Thus "mw.getCurrentFrame():getParent().args" should be the complete table with all parameters. Function "type" reports "table" as expected but function "next" reports "nil" making it impossible to traverse the table. How can I fix this? Thanks.

121.214.112.149 (talkcontribs)

Read Extension:Scribunto/Lua reference manual#frame.args. The frame args table is an empty table, with a metatable containing the actual arguments. You cannot use next() unless you convert it to a normal table (iterate over the whole table with pairs and copy the values to a new table).

Taylor 49 (talkcontribs)

Thanks ... that's exactly what I have found out in the meantime. Extension:Scribunto/Lua reference manual#frame.args does contain the hint ... it is just a bit hidden. And I have mostly fixed the problem. I can seize a "private next function"


<code>

funnext = pairs (vartmp) ; -- keep 1 result and throw away 2

</code>


and call it instead of the unusable official "next". But there is a mystery left: what is the syntax of this function? I tried both with the table name


<code>nextindex = funnext (vartmp, nil) -- seize 0:th index

nextindex = funnext (vartmp) -- seize 0:th index

nextindex = funnext (vartmp, thisindex) -- seize next index

</code>


and without


<code>

nextindex = funnext (nil) -- seize 0:th index

nextindex = funnext () -- seize 0:th index

nextindex = funnext (thisindex) -- seize next index

</code>


and the chocker is that both do work, How is this possible? What syntax is preferable?

Reply to ""mw.getCurrentFrame():getParent()" is a broken table"