Module talk:ScribuntoUnit: Difference between revisions

Content deleted Content added
Line 29:
At the moment, if two different tables are tested for equality, the wikitable generated by the module simply lists them both as "table". It would be nice to actually show the contents of the table in a reasonably nice format. Perhaps we can do something with [[Module:User:Anomie/deepToString]] and/or [https://git.wikimedia.org/blob/mediawiki%2Fextensions%2FScribunto.git/dbbf1803c6489dcb58d77566044e283ec17e7602/engines%2FLuaCommon%2Flualib%2Fmw.lua#L575 mw.logObject]? deepToString fails when trying to display mw.title objects, and while mw.logObject handles them ok, it only outputs to the log buffer. So we would need to do some tweaking to get something that suits our purposes, but it probably wouldn't be too hard. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 12:00, 5 January 2014 (UTC)
: Hm, how does it fail? I tried using mw.title at [[Module_talk:ScribuntoUnit/showcase]], and it seems to work, but I'm not familiar with it. – ''[[User:Danmichaelo|Danmichaelo]] ([[User talk:Danmichaelo|talk]])'' 18:47, 5 January 2014 (UTC)
:: You used the mw.title library, rather than a title object. To get a title object you need to use code like <code>mw.title.new('Wikipedia:Sandbox')</code>. I tried doing just that in the showcase module, and the whole script fails with a "not enough memory" error. The problem is that some of the title object fields are self-references. For example:
<source lang="lua">
local sandbox = mw.title.new('Wikipedia:Sandbox') -- title object for [[Wikipedia:Sandbox]]
sandbox.basePageTitle -- Also the title object for [[Wikipedia:Sandbox]]
sandbox.basePageTitle.basePageTitle -- Again, the same title object.
</source>
:: So if you try and iterate recursively through any given title object, while respecting metatables, you will just keep on going forever. Scribunto then dies when it runs into the memory limit. This problem has been resolved somehow in mw.logObject, but I haven't looked deeply enough at the code to know exactly what was done. — '''''[[User:Mr. Stradivarius|<span style="color: #194D00; font-family: Palatino, Times, serif">Mr. Stradivarius</span>]]''''' <sup>[[User talk:Mr. Stradivarius|♪ talk ♪]]</sup> 11:06, 6 January 2014 (UTC)