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/call.h | |
parent | 8b94e46c8f044a21c18435525da84bee28594d1a (diff) |
introduced Php::call() call function to make builtin, and user space functions callable from C++ space
Diffstat (limited to 'include/call.h')
-rw-r--r-- | include/call.h | 54 |
1 files changed, 54 insertions, 0 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 + */ +} + |