Add Scribunto_LuaInterpreter::isLuaFunction method

Add a method to LuaInterpreter to determine whether an object is a
wrapped Lua function.

Change-Id: I20bf16948db025372d68cc89bf5ddcbf617db864
This commit is contained in:
Brad Jorsch 2012-12-24 09:45:16 -05:00 committed by Gerrit Code Review
parent 374972c924
commit 114f5c13ec
3 changed files with 16 additions and 0 deletions

View file

@ -27,6 +27,14 @@ abstract class Scribunto_LuaInterpreter {
*/
abstract public function wrapPhpFunction( $callable );
/**
* Test whether an object is a Lua function.
*
* @param $object
* @return boolean
*/
abstract public function isLuaFunction( $object );
/**
* Register a library of functions.
*

View file

@ -159,6 +159,10 @@ class Scribunto_LuaSandboxInterpreter extends Scribunto_LuaInterpreter {
return $func;
}
public function isLuaFunction( $object ) {
return $object instanceof LuaSandboxFunction;
}
public function getPeakMemoryUsage() {
return $this->sandbox->getPeakMemoryUsage();
}

View file

@ -189,6 +189,10 @@ class Scribunto_LuaStandaloneInterpreter extends Scribunto_LuaInterpreter {
return $ret[1];
}
public function isLuaFunction( $object ) {
return $object instanceof Scribunto_LuaStandaloneInterpreterFunction;
}
public function registerLibrary( $name, $functions ) {
$functionIds = array();
foreach ( $functions as $funcName => $callback ) {