From d447cc5ea4c809f006cfbe984a509c21e7635100 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Tue, 20 Oct 2009 21:40:22 +0000 Subject: [PATCH] Added Cycript.gc() and fixed 0-argument system.print(). --- Library.mm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/Library.mm b/Library.mm index faed79e..45126dc 100644 --- a/Library.mm +++ b/Library.mm @@ -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; @@ -3703,6 +3711,10 @@ JSGlobalContextRef CYGetJSContext() { class_addMethod(NSCFType_, @selector(cy$toJSON:), reinterpret_cast(&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)); -- 2.45.2