]> git.saurik.com Git - cycript.git/commitdiff
Support bridge support variables.
authorJay Freeman (saurik) <saurik@saurik.com>
Tue, 1 Sep 2009 07:34:01 +0000 (07:34 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Tue, 1 Sep 2009 07:34:01 +0000 (07:34 +0000)
Tweak.mm
makefile

index fc7007d09a0db0f567d3831f954ef73a4d760924..43d6f2c15ad5c7aeb34599b517a4c17b7d84de92 100644 (file)
--- a/Tweak.mm
+++ b/Tweak.mm
@@ -131,9 +131,7 @@ class _H {
     }
 };
 /* }}} */
-
-#define _pooled _H<NSAutoreleasePool> _pool([[NSAutoreleasePool alloc] init], true);
-
+/* APR Pool Helpers {{{ */
 void *operator new(size_t size, apr_pool_t *pool) {
     return apr_palloc(pool, size);
 }
@@ -142,6 +140,27 @@ void *operator new [](size_t size, apr_pool_t *pool) {
     return apr_palloc(pool, size);
 }
 
+class CYPool {
+  private:
+    apr_pool_t *pool_;
+
+  public:
+    CYPool() {
+        apr_pool_create(&pool_, NULL);
+    }
+
+    ~CYPool() {
+        apr_pool_destroy(pool_);
+    }
+
+    operator apr_pool_t *() const {
+        return pool_;
+    }
+};
+/* }}} */
+
+#define _pooled _H<NSAutoreleasePool> _pool([[NSAutoreleasePool alloc] init], true);
+
 static JSContextRef Context_;
 
 static JSClassRef Functor_;
@@ -675,24 +694,6 @@ JSObjectRef CYMakeFunction(JSContextRef context, void *function, const char *typ
     return CYMakeFunction(context, reinterpret_cast<void (*)()>(function), type);
 }
 
-static JSValueRef Global_getProperty(JSContextRef context, JSObjectRef object, JSStringRef name, JSValueRef *exception) { _pooled
-    @try {
-        NSString *string(CYCastNSString(name));
-        if (Class _class = NSClassFromString(string))
-            return CYMakeObject(context, _class);
-        if (NSMutableArray *entry = [Bridge_ objectForKey:string])
-            switch ([[entry objectAtIndex:0] intValue]) {
-                case 0:
-                    return CYMakeFunction(context, [string cy$symbol], [[entry objectAtIndex:1] UTF8String]);
-                case 1:
-                    _assert(false);
-                case 2:
-                    return JSEvaluateScript(JSGetContext(), CYString([entry objectAtIndex:1]), NULL, NULL, 0, NULL);
-            }
-        return NULL;
-    } CYCatch
-}
-
 void CYSetProperty(JSContextRef context, JSObjectRef object, const char *name, JSValueRef value) {
     JSValueRef exception(NULL);
     JSObjectSetProperty(context, object, CYString(name), value, kJSPropertyAttributeNone, &exception);
@@ -874,24 +875,6 @@ JSValueRef CYFromFFI(JSContextRef context, sig::Type *type, void *data) {
     return value;
 }
 
-class CYPool {
-  private:
-    apr_pool_t *pool_;
-
-  public:
-    CYPool() {
-        apr_pool_create(&pool_, NULL);
-    }
-
-    ~CYPool() {
-        apr_pool_destroy(pool_);
-    }
-
-    operator apr_pool_t *() const {
-        return pool_;
-    }
-};
-
 static JSValueRef CYCallFunction(JSContextRef context, size_t count, const JSValueRef *arguments, JSValueRef *exception, sig::Signature *signature, ffi_cif *cif, void (*function)()) { _pooled
     @try {
         if (count != signature->count - 1)
@@ -914,6 +897,27 @@ static JSValueRef CYCallFunction(JSContextRef context, size_t count, const JSVal
     } CYCatch
 }
 
+static JSValueRef Global_getProperty(JSContextRef context, JSObjectRef object, JSStringRef name, JSValueRef *exception) { _pooled
+    @try {
+        NSString *string(CYCastNSString(name));
+        if (Class _class = NSClassFromString(string))
+            return CYMakeObject(context, _class);
+        if (NSMutableArray *entry = [Bridge_ objectForKey:string])
+            switch ([[entry objectAtIndex:0] intValue]) {
+                case 0:
+                    return JSEvaluateScript(JSGetContext(), CYString([entry objectAtIndex:1]), NULL, NULL, 0, NULL);
+                case 1:
+                    return CYMakeFunction(context, [string cy$symbol], [[entry objectAtIndex:1] UTF8String]);
+                case 2:
+                    CYPool pool;
+                    sig::Signature signature;
+                    sig::Parse(pool, &signature, [[entry objectAtIndex:1] UTF8String]);
+                    return CYFromFFI(context, signature.elements[0].type, [string cy$symbol]);
+            }
+        return NULL;
+    } CYCatch
+}
+
 bool stret(ffi_type *ffi_type) {
     return ffi_type->type == FFI_TYPE_STRUCT && (
         ffi_type->size > OBJC_MAX_STRUCT_BY_VALUE ||
index 024cd30cd85ec2646326f056a0d62a7e69f40835..9e874da7c1134eaef196c93126286d3be7f3a496 100644 (file)
--- a/makefile
+++ b/makefile
@@ -18,7 +18,7 @@ clean:
        rm -f $(name).dylib
 
 libcyrver.plist: Bridge.def makefile
-       sed -e 's/^F/0/;s/^V/1/;s/^C/2/' Bridge.def | while read -r line; do \
+       sed -e 's/^C/0/;s/^F/1/;s/^V/2/' Bridge.def | while read -r line; do \
            if [[ $$line == '' ]]; then \
                continue; \
            fi; \