Hello,
I guess this can be answered by Tim or Victor, but I'm grateful for any pointers that can help me with a rather specific problem with Scribunto.
I'm currently working on the Wikidata project to include Lua functions for templates that access Wikidata entities.
I've toyed around a bit and extended LuaCommon.php with a getEntities function and a wikibase table to hold that function. Now I wonder if there are any plans for Lua extensions outside the mw.* namespace.
I've added a wikibase.lua file and a wikibase.* namespace in Lua. However, the way PHP and Lua play together and how Scribunto can be extended looks a bit like black magic (which is to be expected, given that Scribunto is far from finished).
Here are my questions: 1. Is there an easy way to add your own Lua functions (that call PHP Api functions) to Scribunto other than writing them into LuaCommon.php? 2. Is using your own namespace the way to go? 3. Are there some kind of examples how to wrap PHP functions into the Lua environment (using the frame etc)? 4. Is there any way to introspect or debug such wrapped functions?
Thanks for any suggestions!
Cheers, Jens
On Mon, Feb 4, 2013 at 8:46 AM, Jens Ohlig jens.ohlig@wikimedia.de wrote:
Here are my questions:
- Is there an easy way to add your own Lua functions (that call PHP Api functions) to Scribunto other than writing them into LuaCommon.php?
Yes. Probably the best example to look at right now is gerrit change 47109.[1] You could also look at 42050, 38013, or 46478. Keep in mind that any functions you provide have the at least same sorts of security and performance concerns as parser function hooks.
The major issue right now is that there's no way to add something to Scribunto_LuaEngine::$libraryClasses from another extension. There's also the issue of easily adding unit tests from another extension, since ideally the unit tests should be run against both the LuaStandalone and LuaSandbox engines. I'll probably have a look at this today.
[1]: https://gerrit.wikimedia.org/r/#/c/47109/
- Is using your own namespace the way to go?
You'd add your library object in Lua as a child of the "mw" object.
- Are there some kind of examples how to wrap PHP functions into the Lua environment (using the frame etc)?
See #1. Although I can't think of a case where a PHP function would need to use the frame instead of being passed whatever parameters it needs explicitly by the Lua caller.
- Is there any way to introspect or debug such wrapped functions?
I'm not sure what you mean here.
2013/2/4 Brad Jorsch bjorsch@wikimedia.org:
You'd add your library object in Lua as a child of the "mw" object.
Sounds like same little mistake we are already "dealing" with in JavaScript, see: http://www.mediawiki.org/wiki/Manual_talk:Coding_conventions/JavaScript#Plac... Perhaps not too late to get this right in Scribunto from the beginning.
Am 04.02.2013 um 18:03 schrieb Brad Jorsch bjorsch@wikimedia.org:
On Mon, Feb 4, 2013 at 8:46 AM, Jens Ohlig jens.ohlig@wikimedia.de wrote:
Here are my questions:
- Is there an easy way to add your own Lua functions (that call PHP Api functions) to Scribunto other than writing them into LuaCommon.php?
Yes. Probably the best example to look at right now is gerrit change 47109.[1] You could also look at 42050, 38013, or 46478. Keep in mind that any functions you provide have the at least same sorts of security and performance concerns as parser function hooks.
The major issue right now is that there's no way to add something to Scribunto_LuaEngine::$libraryClasses from another extension. There's also the issue of easily adding unit tests from another extension, since ideally the unit tests should be run against both the LuaStandalone and LuaSandbox engines. I'll probably have a look at this today.
Thank you very much! This was EXACTLY the kind of answer I was hoping for. Thank you very much for getting me unstuck \o/
On Tue, Feb 5, 2013 at 5:31 AM, Jens Ohlig jens.ohlig@wikimedia.de wrote:
Am 04.02.2013 um 18:03 schrieb Brad Jorsch bjorsch@wikimedia.org:
On Mon, Feb 4, 2013 at 8:46 AM, Jens Ohlig jens.ohlig@wikimedia.de wrote:
Here are my questions:
- Is there an easy way to add your own Lua functions (that call PHP Api functions) to Scribunto other than writing them into LuaCommon.php?
Yes. Probably the best example to look at right now is gerrit change 47109.[1] You could also look at 42050, 38013, or 46478. Keep in mind that any functions you provide have the at least same sorts of security and performance concerns as parser function hooks.
The major issue right now is that there's no way to add something to Scribunto_LuaEngine::$libraryClasses from another extension. There's also the issue of easily adding unit tests from another extension, since ideally the unit tests should be run against both the LuaStandalone and LuaSandbox engines. I'll probably have a look at this today.
Thank you very much! This was EXACTLY the kind of answer I was hoping for. Thank you very much for getting me unstuck \o/
Update: 47548 adds hooks for other extensions to add libraries,[2] and 47549 (which the above are already rebased on top of) reworks the unit testing so other extensions can add Lua unit tests halfway sanely.[3]
[2]: https://gerrit.wikimedia.org/r/#/c/47548/ [3]: https://gerrit.wikimedia.org/r/#/c/47549/
Hi Jens!
On 02/04/2013 05:46 AM, Jens Ohlig wrote:
I'm currently working on the Wikidata project to include Lua functions for templates that access Wikidata entities.
I've toyed around a bit and extended LuaCommon.php with a getEntities function and a wikibase table to hold that function. Now I wonder if there are any plans for Lua extensions outside the mw.* namespace.
I'm wondering if some of the specialized functionality can be avoided by fetching JSON data from wikibase / wikidata through a web API. This would be more versatile, and could be used by alternative templating systems.
Gabriel
wikitech-l@lists.wikimedia.org