]> git.saurik.com Git - cycript.git/blobdiff - Library.mm
Checkpointing pretty-printing implementation so I can quickly refactor CYNoLeader.
[cycript.git] / Library.mm
index e4bf70b8580f2ad3a07f334560296514153827e7..45126dceebb44126a6028e6fa94e3b1929de23b4 100644 (file)
@@ -352,6 +352,7 @@ struct Instance :
     virtual ~Instance() {
         if ((flags_ & Transient) == 0)
             // XXX: does this handle background threads correctly?
+            // XXX: this simply does not work on the console because I'm stupid
             [GetValue() performSelector:@selector(release) withObject:nil afterDelay:0];
     }
 
@@ -2805,12 +2806,14 @@ static bool stret(ffi_type *ffi_type) {
 extern "C" {
     int *_NSGetArgc(void);
     char ***_NSGetArgv(void);
-    int UIApplicationMain(int argc, char *argv[], NSString *principalClassName, NSString *delegateClassName);
 }
 
 static JSValueRef System_print(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
     CYTry {
-        NSLog(@"%s", CYCastCString(context, arguments[0]));
+        if (count == 0)
+            NSLog(@"");
+        else
+            NSLog(@"%s", CYCastCString(context, arguments[0]));
         return CYJSUndefined(context);
     } CYCatch
 }
@@ -2919,6 +2922,11 @@ static JSValueRef objc_registerClassPair_(JSContextRef context, JSObjectRef obje
 }
 /* }}} */
 
+static JSValueRef Cycript_gc_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
+    JSGarbageCollect(context);
+    return CYJSUndefined(context);
+}
+
 static JSValueRef Selector_callAsFunction(JSContextRef context, JSObjectRef object, JSObjectRef _this, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
     JSValueRef setup[count + 2];
     setup[0] = _this;
@@ -3469,7 +3477,7 @@ struct CYClient :
             } else {
                 std::ostringstream str;
                 CYOutput out(str);
-                driver.program_->Show(out);
+                driver.program_->Multiple(out);
                 std::string code(str.str());
                 CYExecute_ execute = {pool, code.c_str()};
                 [client performSelectorOnMainThread:@selector(execute:) withObject:[NSValue valueWithPointer:&execute] waitUntilDone:YES];
@@ -3703,6 +3711,10 @@ JSGlobalContextRef CYGetJSContext() {
 
         class_addMethod(NSCFType_, @selector(cy$toJSON:), reinterpret_cast<IMP>(&NSCFType$cy$toJSON), "@12@0:4@8");
 
+        JSObjectRef cycript(JSObjectMake(context, NULL, NULL));
+        CYSetProperty(context, global, CYJSString("Cycript"), cycript);
+        CYSetProperty(context, cycript, CYJSString("gc"), JSObjectMakeFunctionWithCallback(context, CYJSString("gc"), &Cycript_gc_callAsFunction));
+
         CYSetProperty(context, global, CYJSString("objc_registerClassPair"), JSObjectMakeFunctionWithCallback(context, CYJSString("objc_registerClassPair"), &objc_registerClassPair_));
         CYSetProperty(context, global, CYJSString("objc_msgSend"), JSObjectMakeFunctionWithCallback(context, CYJSString("objc_msgSend"), &$objc_msgSend));
         CYSetProperty(context, global, CYJSString("$cyq"), JSObjectMakeFunctionWithCallback(context, CYJSString("$cyq"), &$cyq));