]> git.saurik.com Git - cycript.git/blobdiff - Internal.hpp
Completed massive refactoring operation to completely isolate Objective-C.
[cycript.git] / Internal.hpp
index eaf7150e4d7edc537892a256e0d375423f368058..8b77fd5284edb29f961d09d5218cd55eb5f6dd27 100644 (file)
@@ -4,6 +4,7 @@
 #include "Pooling.hpp"
 
 #include <JavaScriptCore/JSBase.h>
+#include <JavaScriptCore/JSObjectRef.h>
 #include <JavaScriptCore/JSValueRef.h>
 
 #include <sig/parse.hpp>
@@ -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<void *>(value))
+    {
+        sig::Parse(pool_, &signature_, type, &Structor_);
+        sig::sig_ffi_cif(pool_, &sig::ObjectiveC, &signature_, &cif_);
+    }
+
+    void (*GetValue())() const {
+        return reinterpret_cast<void (*)()>(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*/