X-Git-Url: https://git.saurik.com/cycript.git/blobdiff_plain/3c1c3635db4635a7aef0a5f625678378f48b6696..37954781d9756ece500551055562183a1e28e943:/Internal.hpp diff --git a/Internal.hpp b/Internal.hpp index eaf7150..8b77fd5 100644 --- a/Internal.hpp +++ b/Internal.hpp @@ -4,6 +4,7 @@ #include "Pooling.hpp" #include +#include #include #include @@ -120,4 +121,46 @@ struct CYOwned : } }; +namespace cy { +struct Functor : + CYValue +{ + sig::Signature signature_; + ffi_cif cif_; + + Functor(const char *type, void (*value)()) : + CYValue(reinterpret_cast(value)) + { + sig::Parse(pool_, &signature_, type, &Structor_); + sig::sig_ffi_cif(pool_, &sig::ObjectiveC, &signature_, &cif_); + } + + void (*GetValue())() const { + return reinterpret_cast(value_); + } + + static JSStaticFunction const * const StaticFunctions; +}; } + +struct Closure_privateData : + cy::Functor +{ + JSContextRef context_; + JSObjectRef function_; + + Closure_privateData(JSContextRef context, JSObjectRef function, const char *type) : + cy::Functor(type, NULL), + context_(context), + function_(function) + { + JSValueProtect(context_, function_); + } + + virtual ~Closure_privateData() { + JSValueUnprotect(context_, function_); + } +}; + +Closure_privateData *CYMakeFunctor_(JSContextRef context, JSObjectRef function, const char *type, void (*callback)(ffi_cif *, void *, void **, void *)); + #endif/*CYCRIPT_INTERNAL_HPP*/