return JSObjectMake(context, Pointer_, internal);
}
-static JSObjectRef CYMakeFunctor(JSContextRef context, void (*function)(), const char *type) {
- return JSObjectMake(context, Functor_, new cy::Functor(type, function));
+static JSObjectRef CYMakeFunctor(JSContextRef context, void (*function)(), const char *encoding) {
+ return JSObjectMake(context, Functor_, new cy::Functor(encoding, function));
+}
+
+static JSObjectRef CYMakeFunctor(JSContextRef context, void (*function)(), sig::Signature &signature) {
+ return JSObjectMake(context, Functor_, new cy::Functor(signature, function));
}
static JSObjectRef CYMakeFunctor(JSContextRef context, const char *symbol, const char *type, void **cache) {
throw CYJSError(context, "incorrect number of arguments to type cast function");
Type_privateData *internal(reinterpret_cast<Type_privateData *>(JSObjectGetPrivate(object)));
+ if (internal->type_->primitive == sig::function_P)
+ return CYMakeFunctor(context, reinterpret_cast<void (*)()>(static_cast<uintptr_t>(CYCastDouble(context, arguments[0]))), internal->type_->data.signature);
+
sig::Type *type(internal->type_);
ffi_type *ffi(internal->GetFFI());
// XXX: alignment?
struct Functor :
CYValue
{
+ private:
+ void set() {
+ sig::sig_ffi_cif(*pool_, &sig::ObjectiveC, &signature_, &cif_);
+ }
+
+ public:
sig::Signature signature_;
ffi_cif cif_;
- Functor(const char *type, void (*value)()) :
+ Functor(sig::Signature &signature, void (*value)()) :
CYValue(reinterpret_cast<void *>(value))
{
- sig::Parse(*pool_, &signature_, type, &Structor_);
- sig::sig_ffi_cif(*pool_, &sig::ObjectiveC, &signature_, &cif_);
+ sig::Copy(*pool_, signature_, signature);
+ set();
+ }
+
+ Functor(const char *encoding, void (*value)()) :
+ CYValue(reinterpret_cast<void *>(value))
+ {
+ sig::Parse(*pool_, &signature_, encoding, &Structor_);
+ set();
}
void (*GetValue() const)() {