diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2011-02-17 06:18:51 -0800 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2011-02-17 06:18:51 -0800 |
commit | b1ca831d87989d531244c62b6e10631e54a42bfd (patch) | |
tree | f16d84eb92dd85958de34f344bdefe99d754123a | |
parent | c9132db418f017e9f72d31b1aeb9ef31bd6e0de8 (diff) |
Add CydiaScript: a better Objective-C bridge.
-rw-r--r-- | MobileCydia.mm | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/MobileCydia.mm b/MobileCydia.mm index 2b6bd1e..e3167c5 100644 --- a/MobileCydia.mm +++ b/MobileCydia.mm @@ -4192,6 +4192,42 @@ static NSString *Warning_; @end /* }}} */ +// CydiaScript {{{ +@interface NSObject (CydiaScript) +- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context; +@end + +@implementation NSObject (CydiaScript) + +- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context { + return self; +} + +@end + +@implementation NSArray (CydiaScript) + +- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context { + WebScriptObject *object([context evaluateWebScript:@"[]"]); + for (size_t i(0), e([self count]); i != e; ++i) + [object setWebScriptValueAtIndex:i value:[[self objectAtIndex:i] Cydia$webScriptObjectInContext:context]]; + return object; +} + +@end + +@implementation NSDictionary (CydiaScript) + +- (id) Cydia$webScriptObjectInContext:(WebScriptObject *)context { + WebScriptObject *object([context evaluateWebScript:@"({})"]); + for (id i in self) + [object setValue:[[self objectForKey:i] Cydia$webScriptObjectInContext:context] forKey:i]; + return object; +} + +@end +// }}} + /* Confirmation Controller {{{ */ bool DepSubstrate(const pkgCache::VerIterator &iterator) { if (!iterator.end()) |