Adds a base class for libraries with some utility functions in PHP, and a
Lua library with utility functions for use from Lua.
Change-Id: I3d67b1de8bc50488fe3a722e4e2de5849285d127
The listing of the standard modules in package.loaded seems to have been
removed to avoid leaking information to loaded modules. However, since
the *entire* environment is cloned, *including* package.loaded itself,
this does not seem to actually be a problem. But for good measure, also
add a unit test to verify that the version of the standard module tables
referenced from package.loaded is the same as that in _G.
This change also cleans up some unused local variables and an unused
local function from the package module.
Change-Id: I7ec8227b3273059e8f65ad735c215bfd0c623e64
In Lua, a table entry with a nil value is the same as a table entry that
doesn't exist. So when serializing for transfer to PHP, these keys will
be skipped. For a table as an associative array this isn't much of a
problem, but for a table as a list it means we have missing indexes.
Some of Lua's functions for handling "lists" (i.e. tables with numeric
keys) also have a problem when the list contains nils.
To work around these issues when passing argument lists and return value
lists, pass the number of elements along with the sparse list. On the
PHP end we can use this to fill in the missing nulls, and on the Lua
end we can pass this count to unpack() to avoid the problems on the Lua
side.
Change-Id: I858e3905a06e377693301da2b8bc534808f00e3e
Trivial fix, the parameter order to assertEquals() was backwards so if
the test failed it would indicate the "Actual" results as "Expected" and
vice versa.
Change-Id: Ibfe12591a58b10e0321aafea576c36cfa674f51d
Lua 5.2 introduces a nice feature where a metatable can override the
standard behavior of the pairs() and ipairs() functions. That would be
very useful in allowing a more standard syntax for our frame.args, and
it's very easy to do both in C and in Lua.
Change-Id: I37efc59a0c8876ee16184807e15fafbc07e2d288
Built-in modules (e.g. the upcoming ustring) should be able to extend
the string metatable, but user modules (and the debug console) should
not be able to.
But currently built-in modules cannot extend the string metatable in
LuaStandalone, while in LuaSandbox the string metatable can be extended
in the console. Fix this and add unit tests.
Change-Id: I15f5598fed318f2fe26b08ec47e16053dddc13c4
The existing unit tests work, but the setup is really not amenable to
the addition of additional tests in a modular fashion. This splits
things out so there is a framework for tests in Lua, and all a module
has to do on the Lua side is supply a list of functions to call and
results to expect. And then on the php side, only one array entry and
two short functions need to be added to LuaSandboxEngineTest to run the
tests.
Change-Id: Ib241b246aa0c7223c33887b38a5858582d7d31b0
Currently, the only way for PHP to pass a function to Lua is to pass
back a function that it received from Lua. This means, for example, that
PHP cannot implement a Lua iterator function except by registering a
library holding the function or by using loadString.
This changeset adds Scribunto_LuaInterpreter::wrapPhpFunction (and
implements it for both LuaSandbox and LuaStandalone), which takes a PHP
callable and returns a Lua function wrapping it.
Note that fallback code is included so this does not depend on
I2e552799.
Change-Id: Ic0a98eec7cc17ef4b1acee032c0f42d617b998d2
The package module is loaded into the "base" environment but not
correctly initialized, so interface modules and the console cannot
actually load anything.
Change-Id: I92a47d318ccadd7361edb1ac3b0e4bb304ff8a9c
In the debug console, "=unpack( { 1, 2, 3 } )" prints only "1". And
similarly, "mw.log( 1, 2, 3 )" logs only "1". Since Lua uses multiple
return values extensively, this is not particularly helpful.
Following the lead of the lua command-line client, change these to
output multiple values by converting each one using tostring() and then
concatenating them with tab as a separator.
Change-Id: I791d4c92415fc722bbd7c62d0f5f88752d31fe07
We should include a unit test to try to ensure that we don't add
features to one environment and forget about the other.
Change-Id: I72b1acf8eea4a05e05fed1efeb0663a3eff9278a
There's no reason LuaStandalone cannot handle NaN and Inf.
Also, add some unit tests to check this.
Change-Id: I8570242a792e212489ad24dfc04fb1f2940190a5
* string.format() truncates the string at a null character, causing a
deadlock when Lua attempts to send null characters to PHP. Use
concatenation instead.
* Added test.
* Fixed an error reporting issue in the console, which I happened to
notice at the same time as the above bug.
Change-Id: I2e6061a04512557492bffbd04bc09ca3bc1d80d6
If the parser is cloned, we need to give the new instance a new
ScribuntoEngine. Otherwise when one of the clones has ParserClearState
called, the engine for the other will also be unexpectedly destroyed.
Change-Id: Ia6ded082e5adddfbd91387bca825a305ccbf831d
Depends-On: Ieec65c908d71e89b9a66f83b9a626f842aadacbb
All of these were in getScriptTraceHtml, which used some magic ($msgOptions) which is no
longer that easy when using the Message class. As only inContentLanguage ('content') was
used, I documented that, and added the relevant code paths.
I tried to keep the code as readable and brief as possible and also removed an unused
local variable ($linedefined).
Change-Id: I38e1ce0bf90d9aa462e88ca7c795fcc848c4f118