Use PHP 7 variadic params for LuaInterpreter::callFunction()

Change-Id: I3b32e73dcee6a92d91f29915a76dd4e83c080ada
This commit is contained in:
Kunal Mehta 2019-03-20 21:17:45 -07:00
parent f308135df3
commit c3d93b61e2
3 changed files with 4 additions and 5 deletions

View file

@ -16,8 +16,9 @@ abstract class Scribunto_LuaInterpreter {
* at zero. If an error occurs, a Scribunto_LuaError will be thrown.
*
* @param mixed $func The function object
* @param mixed ...$args Arguments to the function
*/
abstract public function callFunction( $func /*...*/ );
abstract public function callFunction( $func, ...$args );
/**
* Wrap a PHP callable as a Lua function, which can be passed back into

View file

@ -309,9 +309,7 @@ class Scribunto_LuaSandboxInterpreter extends Scribunto_LuaInterpreter {
# $name, [ $this, 'callback' ], $functions );
}
public function callFunction( $func /*, ... */ ) {
$args = func_get_args();
$func = array_shift( $args );
public function callFunction( $func, ...$args ) {
try {
$ret = $func->call( ...$args );
if ( $ret === false ) {

View file

@ -354,7 +354,7 @@ class Scribunto_LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
return new Scribunto_LuaStandaloneInterpreterFunction( $this->id, $result[1] );
}
public function callFunction( $func /* ... */ ) {
public function callFunction( $func, ...$args ) {
if ( !( $func instanceof Scribunto_LuaStandaloneInterpreterFunction ) ) {
throw new MWException( __METHOD__ . ': invalid function type' );
}