Commit graph

814 commits

Author SHA1 Message Date
Brad Jorsch 6b4cfd5b94 Fix LuaStandalone nil handling
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
2013-01-30 10:12:23 -05:00
Brad Jorsch 9f17590f47 Fix unit test parameter order
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
2013-01-28 19:05:41 -05:00
Demon c9781606fa Merge "Fix reference handling in LuaEnvironmentComparisonTest" 2013-01-28 20:33:24 +00:00
Brad Jorsch dd5241273b Support __pairs and __ipairs
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
2013-01-24 15:46:33 -05:00
Brad Jorsch 10aa7dce46 Fix reference handling in LuaEnvironmentComparisonTest
The Lua engines cannot handle circular data structures. Avoid returning
one for this test.

Change-Id: I7483c29fa440110bc4567bdd4807b035d7475ffc
2013-01-24 15:21:53 -05:00
Demon dfb6455c2c Merge "Fix string extending" 2013-01-24 19:59:54 +00:00
Demon 8b784ce3f9 Merge "Refactor unit tests" 2013-01-24 19:58:04 +00:00
Translation updater bot 5860942eaa Localisation updates from http://translatewiki.net.
Change-Id: I22e6123e19e77dd915f78dc2b296bd812165a77a
2013-01-17 21:28:54 +00:00
Translation updater bot a2df9086fa Localisation updates from http://translatewiki.net.
Change-Id: Ib1dc18ef4d8ab067db3e55ba76235fa6df3f1e0c
2013-01-13 20:40:47 +00:00
Brad Jorsch bdacaabf21 Fix string extending
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
2013-01-09 15:54:44 +00:00
Brad Jorsch c84d699e9b Refactor unit tests
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
2013-01-09 15:54:25 +00:00
Brad Jorsch af0f1926f4 Fix mw.allToString( nil )
This should return "nil", not the empty string.

Change-Id: I6363e5ca8c1966e45eec9d05fb583fb4f98a92b5
2013-01-09 05:56:55 +00:00
Brad Jorsch 114f5c13ec Add Scribunto_LuaInterpreter::isLuaFunction method
Add a method to LuaInterpreter to determine whether an object is a
wrapped Lua function.

Change-Id: I20bf16948db025372d68cc89bf5ddcbf617db864
2013-01-09 05:55:12 +00:00
Brad Jorsch 374972c924 Add Scribunto_LuaInterpreter::wrapPhpFunction
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
2013-01-09 05:54:36 +00:00
Brad Jorsch 8c2300e320 Make loader available to console, interface modules
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
2013-01-09 05:47:06 +00:00
Tim Starling 2b4b42288c Allow the profiler to be configured or disabled
Because bugs were found in it.

Change-Id: I2737bad8663af3c8afec8a0ea4cca5d0f5b13714
2013-01-07 06:26:02 +00:00
Translation updater bot 6e3c5da6b8 Localisation updates from http://translatewiki.net.
Change-Id: Ia7c5dc47f52000ec05b3189449edcc12ea95a58b
2013-01-03 23:13:20 +00:00
Translation updater bot 0d3f6ee2a0 Localisation updates from http://translatewiki.net.
Change-Id: Iabfcc545d6f570b5cfbd83289d3138a864cb4359
2012-12-31 21:01:22 +00:00
Translation updater bot 288d636f46 Localisation updates from http://translatewiki.net.
Change-Id: I61c6368da452ddb8dd751314194e80c85509c499
2012-12-29 19:45:50 +00:00
Translation updater bot 2aa1f897cc Localisation updates from http://translatewiki.net.
Change-Id: If00e44e7fdfefbd2b87301e1f4dbd3488cd87b9b
2012-12-27 21:26:50 +00:00
Translation updater bot ce61573ec5 Localisation updates from http://translatewiki.net.
Change-Id: I8b07012db015760ec7cc0475f69260e36158e6c8
2012-12-23 21:57:52 +00:00
Translation updater bot c17b6a12e7 Localisation updates from http://translatewiki.net.
Change-Id: Iaa7cccba055f021691ef7e92f490de771f46c8ab
2012-12-22 22:19:07 +00:00
Demon 8ed53b1280 Merge "Allow mw.log and console to handle multiple values" 2012-12-21 15:29:54 +00:00
Brad Jorsch 9a5dc931f5 Allow mw.log and console to handle multiple values
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
2012-12-21 10:26:38 -05:00
Chad Horohoe 590d40e145 Make sure to call parent::setUp()
Change-Id: I9da9bbf803ee37d48b954e2e82407fae4dfe464c
2012-12-20 11:43:03 -05:00
Demon e7c930256d Merge "Unit test: verify LuaSandbox and LuaStandalone are equivalent" 2012-12-20 16:32:26 +00:00
Translation updater bot 565c090f76 Localisation updates from http://translatewiki.net.
Change-Id: Iae0dbde50466609e29b2e17f2b684f4047c018a6
2012-12-18 20:39:43 +00:00
Demon 89e103274f Merge "Handle cloned parsers correctly" 2012-12-14 15:00:42 +00:00
Brad Jorsch 27f9cb5d91 Unit test: verify LuaSandbox and LuaStandalone are equivalent
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
2012-12-13 13:53:29 -05:00
Brad Jorsch eabb081c4f Handle non-finite numbers
There's no reason LuaStandalone cannot handle NaN and Inf.

Also, add some unit tests to check this.

Change-Id: I8570242a792e212489ad24dfc04fb1f2940190a5
2012-12-13 13:40:18 -05:00
Translation updater bot bbd155c72a Localisation updates from http://translatewiki.net.
Change-Id: I644d9959a543693add908e4a0aadfd3faad21005
2012-12-04 21:07:32 +00:00
Tim Starling d5bd1102d0 Fixed transmission of \0 from Lua standalone
* 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
2012-12-03 17:46:11 +11:00
Translation updater bot 037463715c Localisation updates from http://translatewiki.net.
Change-Id: I6d8fad75ee4d4f23f1dbc6eda37cecdc017b349f
2012-11-27 21:09:21 +00:00
Translation updater bot 54aef84b55 Localisation updates from http://translatewiki.net.
Change-Id: Ib77390bf10acdcd236e444144b6619f693a0e26c
2012-11-19 20:19:31 +00:00
Brad Jorsch 50cde6fe8d Handle cloned parsers correctly
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
2012-11-16 11:27:55 -05:00
Translation updater bot c2aa4c7c39 Localisation updates from http://translatewiki.net.
Change-Id: Id4b1bb86b43fb60efd81c2a11da4a1d9990bb5a5
2012-11-02 20:20:32 +00:00
Translation updater bot f3c9525a2b Localisation updates from http://translatewiki.net.
Change-Id: I47231de2f7d4c3bcae0578dc3debf76560e60cb8
2012-10-31 20:40:52 +00:00
Translation updater bot 396bf79e27 Localisation updates from http://translatewiki.net.
Change-Id: I493e7a04b756e2488aa613c0a22663ee44756c3b
2012-10-22 01:43:21 +00:00
Siebrand Mazeland e7dd3e5275 Replace remaining wfMsgExt calls.
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
2012-10-09 06:08:48 +00:00
Siebrand Mazeland 9d5759e985 Merge "Reformat JavaScript and CSS code." 2012-10-07 23:58:45 +00:00
Siebrand Mazeland d88f246cfc Merge "Replace deprecated methods." 2012-10-07 14:18:39 +00:00
Siebrand Mazeland ce27d6eefc Reformat JavaScript and CSS code.
Change-Id: Id5630bacfbc97ace3d2c68b69403b463eb6b5e87
2012-10-07 16:13:39 +02:00
Siebrand Mazeland 42c0c55225 Replace deprecated methods.
Change-Id: Ifab19bbc6f75148c8dcee758e09149280e2b229b
2012-10-07 02:59:30 +02:00
Siebrand Mazeland 7e43f640a6 Tweaks and fixes suggested by JSHint/JSLint.
Change-Id: Ia2e089dba787fafbd48e27a3da197dec328c5181
2012-10-07 02:36:28 +02:00
Translation updater bot 840a9fa586 Localisation updates from http://translatewiki.net.
Change-Id: I0af2b3951ca6ffdba0aa35721d44596d8692b86a
2012-10-03 20:17:56 +00:00
Translation updater bot 26e1149f64 Localisation updates from http://translatewiki.net.
Change-Id: I9ee9799add485fbac4274d38468297cc5ea4a954
2012-10-02 13:55:11 +00:00
Translation updater bot 303b8c0517 Localisation updates from http://translatewiki.net.
Change-Id: I0bb1c31875ae5739a162ca87b1ad6a2ab2b43bda
2012-09-26 19:52:17 +00:00
Tim Starling 27428cad87 Remove trailing whitespace
Test commit for wmf branch update script

Change-Id: Iafc71899d4cd9b827ec7325453950acf4f02314c
2012-09-26 13:35:46 +10:00
Tim Starling e287d47b4a (bug 40480) Fix "undefined class constant 'PERCENT'"
Do not try to use the new LuaSandbox class constants in the
backwards-compatible section of the code.

Change-Id: I0c4ca9e019095fce5bd1c1d17dbdf36dc198dfb7
2012-09-25 14:55:11 +10:00
Translation updater bot 071f22b295 Localisation updates from http://translatewiki.net.
Change-Id: I7881ef8c8ad93a8647618de5b45f65740ab6e5cc
2012-09-23 19:05:01 +00:00