diff options
author | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-08 11:41:00 +0100 |
---|---|---|
committer | Emiel Bruijntjes <emiel.bruijntjes@copernica.com> | 2014-03-08 11:41:00 +0100 |
commit | 5b93d44d2a05b3648ec13ae1f076e224d63287d5 (patch) | |
tree | 87e9566f8bf6e02105690750df618a1194eee9b0 /include | |
parent | 8b94e46c8f044a21c18435525da84bee28594d1a (diff) |
introduced Php::call() call function to make builtin, and user space functions callable from C++ space
Diffstat (limited to 'include')
-rw-r--r-- | include/call.h | 54 | ||||
-rw-r--r-- | include/globals.h | 29 |
2 files changed, 55 insertions, 28 deletions
diff --git a/include/call.h b/include/call.h new file mode 100644 index 0000000..bae0a0a --- /dev/null +++ b/include/call.h @@ -0,0 +1,54 @@ +/** + * Call.h + * + * This file holds a function to call a PHP function + * + * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com> + * @copyright 2014 Copernica BV + */ + +/** + * Set up namespace + */ +namespace Php { + +/** + * Call a function in PHP + * @param name Name of the function to call + * @param params Variable number of parameters + * @return Value + */ +template <typename ...Params> +Value call(const char *name, Params&&... params) +{ + // the name can be turned into a Php::Value object, which implements + // the operator () method to call it + Value function(name); + + // invoke the operator () + return function(std::forward<Params>(params)...); +} + +/** + * Long list of simply-forwarded function calls + * + * Most functions in this list are forwarded to the call() method described + * above, which of course is slower than necessary, because they will have to + * pass the entire zend engine to look up the actual implementation, while a + * direct call the C implementation was possible too. The reason for this is + * that we are lazy - if you feel like looking up the actual implementation for + * each function in the PHP source, your support is more than welcome. + * + * But since it is a stupid idea to call a PHP function from your extension + * anyway (that's what people write extension for: to get away from PHP and + * make the code run on the highway), it is not expected that these functions + * are going to be used very often anyway. + */ +inline Value array_keys(const Value &value) { return call("array_keys", value); } +inline Value array_values(const Value &value) { return call("array_values", value); } + +/** + * End of namespace + */ +} + diff --git a/include/globals.h b/include/globals.h index 6faeb8a..0278c88 100644 --- a/include/globals.h +++ b/include/globals.h @@ -53,35 +53,8 @@ public: */ Global operator[](const std::string &name); - /** - * Call a function in PHP - * We have ten variants of this function, depending on the number of parameters - * @param name Name of the function - * @return Value - */ - Value call(const Value &name); - Value call(const Value &name, Value p0); - Value call(const Value &name, Value p0, Value p1); - Value call(const Value &name, Value p0, Value p1, Value p2); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8); - Value call(const Value &name, Value p0, Value p1, Value p2, Value p3, Value p4, Value p5, Value p6, Value p7, Value p8, Value p9); - private: /** - * Call function with a number of parameters - * @param name Function name - * @param argc Number of parameters - * @param argv The parameters - * @return Value - */ - Value exec(const Value &name, int argc, struct _zval_struct ***params); - - /** * Constructor */ Globals() {} @@ -98,7 +71,7 @@ public: * We always have one instance * @var Globals */ -extern Globals &globals; +extern Globals &GLOBALS; /** * End of namespace |