summaryrefslogtreecommitdiff
path: root/src/callable.cpp
diff options
context:
space:
mode:
authorEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-08-25 17:40:03 +0200
committerEmiel Bruijntjes <emiel.bruijntjes@copernica.com>2013-08-25 17:40:03 +0200
commite14055694478d70e58b5fc653b08a9a514bbc455 (patch)
treeab47d723699a7fe86f47f68c182ab695bf9b3bab /src/callable.cpp
parente838e180f5bbcf19e7235f30311645e942ff92d2 (diff)
{more work in progress: the function that was defined with c++ now gets calls, but it does not yet call the actual implementation
Diffstat (limited to 'src/callable.cpp')
-rw-r--r--src/callable.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/src/callable.cpp b/src/callable.cpp
new file mode 100644
index 0000000..1ad4ed2
--- /dev/null
+++ b/src/callable.cpp
@@ -0,0 +1,87 @@
+/**
+ * Callable.cpp
+ *
+ * Implementation for the Callable class
+ *
+ * @author Emiel Bruijntjes <emiel.bruijntjes@copernica.com>
+ * @copyright 2013 Copernica BV
+ */
+#include "includes.h"
+
+/**
+ * Namespace
+ */
+namespace PhpCpp {
+
+/**
+ * Function that is called by the Zend engine every time that a function gets called
+ * @param mixed
+ */
+void invoke_callable(INTERNAL_FUNCTION_PARAMETERS)
+{
+ std::cout << "invoke_callable" << std::endl;
+
+}
+
+/**
+ * Fill a function entry
+ * @param entry
+ */
+void Callable::fill(zend_function_entry *entry)
+{
+ // fill the members of the entity
+ entry->fname = _function.c_str();
+ entry->handler = invoke_callable;
+ entry->arg_info = _argv;
+ entry->num_args = _argc;
+ entry->flags = _flags;
+}
+
+/**
+ * Another attempt to fill internal function info
+ * @param entry
+ */
+void Callable::fill(zend_internal_function_info *info)
+{
+ // fill in all the members, not that the returning by reference is not used
+ info->_name = _function.c_str();
+ info->_name_len = _function.size();
+ info->_class_name = _classname.size() ? _classname.c_str() : NULL;
+ info->required_num_args = _required;
+ info->_type_hint = _type;
+ info->return_reference = false;
+ info->pass_rest_by_reference = false;
+}
+
+/**
+ * Process the arguments
+ * @param arguments
+ */
+void Callable::process(const std::initializer_list<Argument> &arguments)
+{
+ // store counters
+ _argc = arguments.size();
+ _required = arguments.size();
+
+ // allocate memory for the arguments, with one extra record to hold information
+ _argv = new zend_arg_info[_argc + 1];
+
+ // fill the info
+ fill((zend_internal_function_info *)_argv);
+
+ // iteration counter
+ int i = 0;
+
+ // loop through the arguments
+ for (auto it = begin(arguments); it != arguments.end(); it++)
+ {
+ // fill the argument structure
+ it->internal()->fill(&_argv[++i]);
+ }
+}
+
+/**
+ * End of namespace
+ */
+}
+