+namespace cy {
+struct Functor :
+ CYValue
+{
+ private:
+ void set() {
+ sig::sig_ffi_cif(*pool_, &sig::ObjectiveC, &signature_, &cif_);
+ }
+
+ public:
+ sig::Signature signature_;
+ ffi_cif cif_;
+
+ Functor(const sig::Signature &signature, void (*value)()) :
+ CYValue(reinterpret_cast<void *>(value))
+ {
+ 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)() {
+ return reinterpret_cast<void (*)()>(value_);
+ }
+
+ static JSStaticFunction const * const StaticFunctions;
+}; }
+
+struct Closure_privateData :
+ cy::Functor
+{
+ JSGlobalContextRef context_;
+ JSObjectRef function_;
+
+ Closure_privateData(JSContextRef context, JSObjectRef function, const sig::Signature &signature) :
+ cy::Functor(signature, NULL),
+ context_(CYGetJSContext(context)),
+ function_(function)
+ {
+ //XXX:JSGlobalContextRetain(context_);
+ JSValueProtect(context_, function_);
+ }
+
+ virtual ~Closure_privateData() {
+ JSValueUnprotect(context_, function_);
+ //XXX:JSGlobalContextRelease(context_);
+ }
+};
+
+Closure_privateData *CYMakeFunctor_(JSContextRef context, JSObjectRef function, const sig::Signature &signature, void (*callback)(ffi_cif *, void *, void **, void *));
+void CYExecuteClosure(ffi_cif *cif, void *result, void **arguments, void *arg, JSValueRef (*adapter)(JSContextRef, size_t, JSValueRef[], JSObjectRef));
+