72 $passthru = $interpreter->loadString(
'return ...',
'passthru' );
73 $ret = $interpreter->callFunction( $passthru, NAN );
74 $this->assertTrue( is_nan( $ret[0] ),
'NaN was not passed through' );
76 $interpreter->registerLibrary(
'test',
77 [
'passthru' => [ $this,
'passthru' ] ] );
78 $doublePassthru = $interpreter->loadString(
79 'return test.passthru(...)',
'doublePassthru' );
80 $ret = $interpreter->callFunction( $doublePassthru, NAN );
81 $this->assertTrue( is_nan( $ret[0] ),
'NaN was not double passed through' );
159 $func = $interpreter->wrapPhpFunction(
function ( $n ) {
162 $res = $interpreter->callFunction( $func,
'From PHP' );
163 $this->assertEquals( [ 42,
'From PHP' ],
$res );
165 $chunk = $interpreter->loadString(
'
167 return f( "From Lua" )
169 'wrappedPhpFunction' );
170 $res = $interpreter->callFunction( $chunk, $func );
171 $this->assertEquals( [ 42,
'From Lua' ],
$res );
176 $test1Called =
false;
177 $test2Called =
false;
180 $interpreter->registerLibrary(
'mw_interface', [
181 'foo' =>
function ( $v ) use ( &$test1Called ) {
185 $interpreter->callFunction(
186 $interpreter->loadString(
'test1 = mw_interface; mw_interface = nil',
'test' )
189 $interpreter->registerLibrary(
'mw_interface', [
190 'foo' =>
function ( $v ) use ( &$test2Called ) {
194 $interpreter->callFunction(
195 $interpreter->loadString(
'test2 = mw_interface; mw_interface = nil',
'test' )
198 $interpreter->callFunction(
199 $interpreter->loadString(
'test1.foo( "first" ); test2.foo( "second" )',
'test' )
201 $this->assertSame(
'first', $test1Called,
'test1.foo was called with "first"' );
202 $this->assertSame(
'second', $test2Called,
'test2.foo was called with "second"' );