Page MenuHomePhabricator

Metatables don't work from wikitext (__index)
Closed, ResolvedPublic

Description

Create Module:Foo with the following code:
local p, mt = {}, {}

function mt.__index(table, key)
return function(frame)

		return 'You called the ' .. key .. ' function'

end
end

setmetatable(p, mt)

return p

From the console, "=p.bar()" correctly produces "You called the bar function". However, from wikitext, "{{#invoke:Foo|bar}}" instead produces "Script error: The function "bar" does not exist."


Version: unspecified
Severity: normal

Details

Reference
bz64141

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 3:19 AM
bzimport added a project: Scribunto.
bzimport set Reference to bz64141.
bzimport added a subscriber: Unknown Object (MLST).

I don't currently have LuaSandbox set up, but while trying to fix this, I noticed that in LuaStandalone, passing an object from Lua to PHP and back causes its metatable to be lost.

Change 127458 had a related patch set uploaded by Jackmcbarn:
Keep modules' export tables inside Lua

https://gerrit.wikimedia.org/r/127458

Change 127458 merged by jenkins-bot:
Keep modules' export tables inside Lua

https://gerrit.wikimedia.org/r/127458

This will be live on all WMF wikis starting June 5th.