From 114f5c13ec01d2b97ffad65f32f797d57d630945 Mon Sep 17 00:00:00 2001 From: Brad Jorsch Date: Mon, 24 Dec 2012 09:45:16 -0500 Subject: [PATCH] Add Scribunto_LuaInterpreter::isLuaFunction method Add a method to LuaInterpreter to determine whether an object is a wrapped Lua function. Change-Id: I20bf16948db025372d68cc89bf5ddcbf617db864 --- engines/LuaCommon/LuaInterpreter.php | 8 ++++++++ engines/LuaSandbox/Engine.php | 4 ++++ engines/LuaStandalone/LuaStandaloneEngine.php | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/engines/LuaCommon/LuaInterpreter.php b/engines/LuaCommon/LuaInterpreter.php index 7bc9665d..476b8061 100644 --- a/engines/LuaCommon/LuaInterpreter.php +++ b/engines/LuaCommon/LuaInterpreter.php @@ -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. * diff --git a/engines/LuaSandbox/Engine.php b/engines/LuaSandbox/Engine.php index f8801f03..f6fe0c11 100644 --- a/engines/LuaSandbox/Engine.php +++ b/engines/LuaSandbox/Engine.php @@ -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(); } diff --git a/engines/LuaStandalone/LuaStandaloneEngine.php b/engines/LuaStandalone/LuaStandaloneEngine.php index e4a70dac..f694cc20 100644 --- a/engines/LuaStandalone/LuaStandaloneEngine.php +++ b/engines/LuaStandalone/LuaStandaloneEngine.php @@ -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 ) {