From 6c4a8f17c67165107a00441c4203662657b4b492 Mon Sep 17 00:00:00 2001 From: "Meredith L. Patterson" Date: Sun, 24 Nov 2013 23:10:27 -0600 Subject: [PATCH] need to figure out how to apply a function in zend to something other than an array; about to run out of battery though --- src/bindings/swig/hammer.i | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/bindings/swig/hammer.i b/src/bindings/swig/hammer.i index 06b4515..4e3b7a0 100644 --- a/src/bindings/swig/hammer.i +++ b/src/bindings/swig/hammer.i @@ -150,7 +150,7 @@ struct HParseResult_; static zval* hpt_to_php(const struct HParsedToken_ *token); - //static struct HParsedToken_* call_action(const struct HParseResult_ *p, void* user_data); + static struct HParsedToken_* call_action(const struct HParseResult_ *p, void* user_data); } %typemap(in) (const uint8_t* str, const size_t len) { @@ -247,7 +247,15 @@ } } } +/* +%typemap(in) (HPredicate* pred, void* user_data) { + } +*/ +%typemap(in) (const HAction a, void* user_data) { + $2 = $input; + $1 = call_action; + } #else #warning no Hammer typemaps defined #endif @@ -508,5 +516,19 @@ def int64(): return _h_int64() break; } } + + static struct HParsedToken_* call_action(const struct HParseResult_ *p, void* user_data) { + zval *callable = user_data; + zval *ret; + ALLOC_INIT_ZVAL(ret); + FIXME_SOME_ZEND_APPLY_FUNCTION(ret, (apply_func_t)callable TSRMLS_CC); + if (ret == NULL) { + // FIXME throw some error + return NULL; + } + // TODO: add reference to ret to parse-local data + HParsedToken *tok = h_make(p->arena, h_tt_php, ret); + return tok; + } } #endif