--- /dev/null
+C YES true
+C NO false
+C nil null
+
+l objc
+
+F class_addIvar B#*LC*
+F class_addMethod B#:^?*
+F class_addProtocol B#@
+F class_conformsToProtocol B#@
+F class_copyIvarList ^^{objc_ivar=}#^I
+F class_copyMethodList ^^{objc_method=}#^I
+F class_copyPropertyList ^^{objc_property=}#^I
+F class_copyProtocolList ^@#^I
+F class_createInstance @#L
+F class_getClassMethod ^{objc_method=}#:
+F class_getClassVariable ^{objc_ivar=}#*
+F class_getInstanceMethod ^{objc_method=}#:
+F class_getInstanceSize L#
+F class_getInstanceVariable ^{objc_ivar=}#*
+F class_getIvarLayout *#
+F class_getMethodImplementation ^?#:
+F class_getMethodImplementation_stret ^?#:
+F class_getName *#
+F class_getProperty ^{objc_property=}#*
+F class_getSuperclass ##
+F class_getVersion i#
+F class_getWeakIvarLayout *#
+F class_isMetaClass B#
+F class_replaceMethod ^?#:^?*
+F class_respondsToSelector B#:
+F class_setIvarLayout v#*
+F class_setSuperclass ###
+F class_setVersion v#i
+F class_setWeakIvarLayout v#*
+
+F ivar_getName *^{objc_ivar=}
+F ivar_getOffset i^{objc_ivar=}
+F ivar_getTypeEncoding *^{objc_ivar=}
+
+F method_copyArgumentType ^c^{objc_method=}I
+F method_copyReturnType ^c^{objc_method=}
+F method_exchangeImplementations v^{objc_method=}^{objc_method=}
+F method_getArgumentType v^{objc_method=}I^cL
+F method_getImplementation ^?^{objc_method=}
+F method_getName :^{objc_method=}
+F method_getNumberOfArguments I^{objc_method=}
+F method_getReturnType v^{objc_method=}^cL
+F method_getTypeEncoding *^{objc_method=}
+F method_setImplementation ^?^{objc_method=}^?
+
+F objc_allocateClassPair ##*L
+F objc_copyProtocolList ^@^I
+F objc_duplicateClass ##*L
+F objc_getClass #*
+F objc_getClassList i^#i
+F objc_getFutureClass #*
+F objc_getMetaClass @*
+F objc_getProtocol @*
+F objc_getRequiredClass @*
+F objc_lookUpClass @*
+F objc_registerClassPair v#
+F objc_setFutureClass v#*
+
+F object_copy @@L
+F object_dispose @@
+F object_getClass #@
+F object_getClassName *@
+F object_getIndexedIvars ^v@
+F object_getInstanceVariable ^{objc_ivar=}@*^^v
+F object_getIvar @@^{objc_ivar=}
+F object_setClass #@#
+F object_setInstanceVariable ^{objc_ivar=}@*^v
+F object_setIvar v@^{objc_ivar=}@
+
+F property_getAttributes *^{objc_property=}
+F property_getName *^{objc_property=}
+
+F protocol_conformsToProtocol B@@
+F protocol_copyMethodDescriptionList ^{objc_method_description=:*}@BB^I
+F protocol_copyPropertyList ^{objc_property=}@^I
+F protocol_copyProtocolList ^@@^I
+F protocol_getMethodDescription {objc_method_description=:*}@:BB
+F protocol_getName *@
+F protocol_getProperty ^{objc_property=}@*BB
+F protocol_isEqual B@@
+
+F sel_getName *:
+F sel_getUid :*
+F sel_isEqual B::
+F sel_registerName :*
+
+f UIKit
+
+F UIApplicationUseLegacyEvents vB
+
+F UIAccessibilityPostNotification vI@
+F UIApplicationMain ii^^c@@
+F UIGraphicsEndImageContext v
+F UIGraphicsGetCurrentContext @
+F UIGraphicsGetImageFromCurrentImageContext @
+F UIGraphicsPopContext v
+F UIGraphicsPushContext v@
+F UIImageJPEGRepresentation @@
+F UIImagePNGRepresentation @@
+F UIImageWriteToSavedPhotosAlbum v@@:^v
+
+F UIKeyboardDisableAutomaticAppearance v
+F UIKeyboardEnableAutomaticAppearance v
+F UIKeyboardInputModeUsesKBStar B@
+
+F _UIImageWithName @@
+
+F UIUnformattedPhoneNumberFromString @@
+
+V UIApp @
+
+V kUIButtonBarButtonAction @
+V kUIButtonBarButtonInfo @
+V kUIButtonBarButtonInfoOffset @
+V kUIButtonBarButtonSelectedInfo @
+V kUIButtonBarButtonSizeToFit @
+V kUIButtonBarButtonStyle @
+V kUIButtonBarButtonTag @
+V kUIButtonBarButtonTarget @
+V kUIButtonBarButtonTitle @
+V kUIButtonBarButtonTitleVerticalHeight @
+V kUIButtonBarButtonTitleWidth @
+V kUIButtonBarButtonType @
+
+V UIKeyboardAnimationCurveUserInfoKey @
+V UIKeyboardAnimationDurationUserInfoKey @
+V UIKeyboardBoundsUserInfoKey @
+V UIKeyboardCenterBeginUserInfoKey @
+V UIKeyboardCenterEndUserInfoKey @
+V UIKeyboardRequiresInternationalKey @
+
+V UIKeyboardCandidateCorrectionDidChangeNotification @
+V UIKeyboardCurrentInputModeDidChangeNotification @
+V UIKeyboardDefaultsDidChangeNotification @
+V UIKeyboardDidHideNotification @
+V UIKeyboardDidShowNotification @
+V UIKeyboardEmptyDelegateNotification @
+V UIKeyboardWillHideNotification @
+V UIKeyboardWillShowNotification @
+
+V UIWebViewDidReceiveMessageNotification @
+V UIWebViewDidClearMessagesNotification @
+V UIWebViewGrowsAndShrinksToFitHeight f
+V UIWebViewGrowsAndShrinksToFitWidth f
+V UIWebViewScalesToFitScale f
+
+f AddressBook
+
+F ABAddressBookAddRecord B@@^@
+F ABAddressBookCopyArrayOfAllGroups @@
+F ABAddressBookCopyArrayOfAllPeople @@
+F ABAddressBookCopyLocalizedLabel @@
+F ABAddressBookCreate @
+F ABAddressBookGetGroupCount l@
+F ABAddressBookGetPersonCount l@
+F ABAddressBookHasUnsavedChanges B@
+F ABAddressBookRegisterExternalChangeCallback v@^?^v
+F ABAddressBookRemoveRecord B@@^@
+F ABAddressBookRevert v@
+F ABAddressBookSave B@^@
+F ABAddressBookUnregisterExternalChangeCallback v@^?^v
+
+V ABAddressBookErrorDomain @
+C kABOperationNotPermittedByStoreError 0
+
+F ABMultiValueCopyArrayOfAllValues @@
+F ABMultiValueCopyLabelAtIndex @@l
+F ABMultiValueCopyValueAtIndex @@l
+F ABMultiValueGetCount l@
+F ABMultiValueGetFirstIndexOfValue l@@
+F ABMultiValueGetIdentifierAtIndex i@l
+F ABMultiValueGetIndexForIdentifier l@i
+F ABMultiValueGetPropertyType S@
+
+C kABMultiValueInvalidIdentifier -1
+
+F ABMultiValueAddValueAndLabel @@@^i
+F ABMultiValueCreateMutable @S
+F ABMultiValueCreateMutableCopy @@
+F ABMultiValueInsertValueAndLabelAtIndex B@@@l^i
+F ABMultiValueRemoveValueAndLabelAtIndex B@l
+F ABMultiValueReplaceLabelAtIndex B@@l
+F ABMultiValueReplaceValueAtIndex B@@l
+
+F ABRecordCopyCompositeName @@
+F ABRecordCopyValue @@i
+F ABRecordGetRecordID i@
+F ABRecordGetRecordType I@
+F ABRecordRemoveValue B@i^@
+F ABRecordSetValue B@i@^@
+
+C kABPersonType 0
+C kABGroupType 1
+
+# this was (1<<8)
+C kABMultiValueMask 0x100
+
+C kABInvalidPropertyType 0x0
+C kABStringPropertyType 0x1
+C kABIntegerPropertyType 0x2
+C kABRealPropertyType 0x3
+C kABDateTimePropertyType 0x4
+C kABDictionaryPropertyType 0x5
+C kABMultiStringPropertyType 0x101
+C kABMultiIntegerPropertyType 0x102
+C kABMultiRealPropertyType 0x103
+C kABMultiDateTimePropertyType 0x104
+C kABMultiDictionaryPropertyType 0x105
+
+C kABRecordInvalidID -1
+C kABPropertyInvalidID -1
+
+F ABAddressBookGetGroupWithRecordID @@i
+F ABGroupAddMember B@@^@
+F ABGroupCopyArrayOfAllMembers @@
+F ABGroupCopyArrayOfAllMembersWithSortOrdering @@I
+F ABGroupCreate @
+F ABGroupRemoveMember B@@^@
+
+V kABGroupNameProperty i
+
+F ABAddressBookCopyPeopleWithName @@@
+F ABAddressBookGetPersonWithRecordID @@i
+F ABPersonComparePeopleByName i@@I
+F ABPersonCopyImageData @@
+F ABPersonCopyLocalizedPropertyName @i
+F ABPersonCreate @
+F ABPersonGetCompositeNameFormat I
+F ABPersonGetSortOrdering I
+F ABPersonGetTypeOfProperty SI
+F ABPersonHasImageData B@
+F ABPersonRemoveImageData B@^@
+F ABPersonSetImageData B@@^@
+
+C kABPersonSortByFirstName 0
+C kABPersonSortByLastName 1
+
+C kABPersonCompositeNameFormatFirstNameFirst 0
+C kABPersonCompositeNameFormatLastNameFirst 1
+
+V kABPersonFirstNameProperty i
+V kABPersonLastNameProperty i
+V kABPersonMiddleNameProperty i
+V kABPersonPrefixProperty i
+V kABPersonSuffixProperty i
+V kABPersonNicknameProperty i
+V kABPersonFirstNamePhoneticProperty i
+V kABPersonLastNamePhoneticProperty i
+V kABPersonMiddleNamePhoneticProperty i
+V kABPersonOrganizationProperty i
+V kABPersonJobTitleProperty i
+V kABPersonDepartmentProperty i
+V kABPersonEmailProperty i
+V kABPersonBirthdayProperty i
+V kABPersonNoteProperty i
+V kABPersonCreationDateProperty i
+V kABPersonModificationDateProperty i
+
+V kABPersonAddressProperty i
+V kABPersonAddressStreetKey @
+V kABPersonAddressCityKey @
+V kABPersonAddressStateKey @
+V kABPersonAddressZIPKey @
+V kABPersonAddressCountryKey @
+V kABPersonAddressCountryCodeKey @
+
+V kABPersonDateProperty i
+V kABPersonAnniversaryLabel @
+
+V kABPersonKindProperty i
+V kABPersonKindPerson @
+V kABPersonKindOrganization @
+
+V kABPersonPhoneProperty i
+V kABPersonPhoneMobileLabel @
+V kABPersonPhoneIPhoneLabel @
+V kABPersonPhoneMainLabel @
+V kABPersonPhoneHomeFAXLabel @
+V kABPersonPhoneWorkFAXLabel @
+V kABPersonPhonePagerLabel @
+
+V kABPersonInstantMessageProperty i
+V kABPersonInstantMessageServiceKey @
+V kABPersonInstantMessageServiceYahoo @
+V kABPersonInstantMessageServiceJabber @
+V kABPersonInstantMessageServiceMSN @
+V kABPersonInstantMessageServiceICQ @
+V kABPersonInstantMessageServiceAIM @
+V kABPersonInstantMessageUsernameKey @
+
+V kABPersonURLProperty i
+V kABPersonHomePageLabel @
+
+V kABPersonRelatedNamesProperty i
+V kABPersonMotherLabel @
+V kABPersonFatherLabel @
+V kABPersonParentLabel @
+V kABPersonSisterLabel @
+V kABPersonBrotherLabel @
+V kABPersonChildLabel @
+V kABPersonFriendLabel @
+V kABPersonSpouseLabel @
+V kABPersonPartnerLabel @
+V kABPersonManagerLabel @
+V kABPersonAssistantLabel @
+
+V kABWorkLabel @
+V kABHomeLabel @
+V kABOtherLabel @
+
+f CoreLocation
+
+V kCLLocationAccuracyBest d
+V kCLLocationAccuracyNearestTenMeters d
+V kCLLocationAccuracyHundredMeters d
+V kCLLocationAccuracyKilometer d
+V kCLLocationAccuracyThreeKilometers d
+
+V kCLDistanceFilterNone d
+V kCLHeadingFilterNone d
+
+C kCLErrorLocationUnknown 0
+C kCLErrorDenied 1
+C kCLErrorNetwork 2
+C kCLErrorHeadingFailure 3
+
+V kCLErrorDomain @
+
+f CoreData
+
+C NSUndefinedAttributeType 0
+C NSInteger16AttributeType 100
+C NSInteger32AttributeType 200
+C NSInteger64AttributeType 300
+C NSDecimalAttributeType 400
+C NSDoubleAttributeType 500
+C NSFloatAttributeType 600
+C NSStringAttributeType 700
+C NSBooleanAttributeType 800
+C NSDateAttributeType 900
+C NSBinaryDataAttributeType 1000
+C NSTransformableAttributeType 1800
+C NSObjectIDAttributeType 2000
+
+C NSUndefinedEntityMappingType 0x00
+C NSCustomEntityMappingType 0x01
+C NSAddEntityMappingType 0x02
+C NSRemoveEntityMappingType 0x03
+C NSCopyEntityMappingType 0x04
+C NSTransformEntityMappingType 0x05
+
+V NSMigrationManagerKey @
+V NSMigrationSourceObjectKey @
+V NSMigrationDestinationObjectKey @
+V NSMigrationEntityMappingKey @
+V NSMigrationPropertyMappingKey @
+V NSMigrationPropertyMappingKey @
+
+C NSManagedObjectResultType 0x00
+C NSManagedObjectIDResultType 0x01
+C NSDictionaryResultType 0x02
+
+C NSFetchRequestExpressionType 50
+
+C NSSnapshotEventUndoInsertion 1<<1
+C NSSnapshotEventUndoDeletion 1<<2
+C NSSnapshotEventUndoUpdate 1<<3
+C NSSnapshotEventRollback 1<<4
+C NSSnapshotEventRefresh 1<<5
+C NSSnapshotEventMergePolicy 1<<6
+
+V NSInsertedObjectsKey @
+V NSUpdatedObjectsKey @
+V NSDeletedObjectsKey @
+V NSRefreshedObjectsKey @
+V NSInvalidatedObjectsKey @
+V NSInvalidatedAllObjectsKey @
+
+V NSErrorMergePolicy @
+V NSMergeByPropertyStoreTrumpMergePolicy @
+V NSMergeByPropertyObjectTrumpMergePolicy @
+V NSOverwriteMergePolicy @
+V NSRollbackMergePolicy @
+
+V NSSQLiteStoreType @
+V NSBinaryStoreType @
+V NSInMemoryStoreType @
+
+V NSStoreTypeKey @
+V NSStoreUUIDKey @
+
+V NSAddedPersistentStoresKey @
+V NSRemovedPersistentStoresKey @
+V NSUUIDChangedPersistentStoresKey @
+
+V NSReadOnlyPersistentStoreOption @
+V NSPersistentStoreTimeoutOption @
+V NSSQLitePragmasOption @
+V NSSQLiteAnalyzeOption @
+V NSSQLiteManualVacuumOption @
+
+V NSIgnorePersistentStoreVersioningOption @
+V NSMigratePersistentStoresAutomaticallyOption @
+V NSInferMappingModelAutomaticallyOption @
+
+V NSStoreModelVersionHashesKey @
+V NSStoreModelVersionIdentifiersKey @
+V NSPersistentStoreOSCompatibility @
+
+C NSNoActionDeleteRule 0
+C NSNullifyDeleteRule 1
+C NSCascadeDeleteRule 2
+C NSDenyDeleteRule 3
+
+C NSFetchedResultsChangeInsert 1
+C NSFetchedResultsChangeDelete 2
+C NSFetchedResultsChangeMove 3
+C NSFetchedResultsChangeUpdate 4
+
+V NSDetailedErrorsKey @
+V NSValidationObjectErrorKey @
+V NSValidationKeyErrorKey @
+V NSValidationPredicateErrorKey @
+V NSValidationValueErrorKey @
+V NSAffectedStoresErrorKey @
+V NSAffectedObjectsErrorKey @
+
+V NSSQLiteErrorDomain @
+
+C NSManagedObjectValidationError 1550
+C NSValidationMultipleErrorsError 1560
+C NSValidationMissingMandatoryPropertyError 1570
+C NSValidationRelationshipLacksMinimumCountError 1580
+C NSValidationRelationshipExceedsMaximumCountError 1590
+C NSValidationRelationshipDeniedDeleteError 1600
+C NSValidationNumberTooLargeError 1610
+C NSValidationNumberTooSmallError 1620
+C NSValidationDateTooLateError 1630
+C NSValidationDateTooSoonError 1640
+C NSValidationInvalidDateError 1650
+C NSValidationStringTooLongError 1660
+C NSValidationStringTooShortError 1670
+C NSValidationStringPatternMatchingError 1680
+
+C NSManagedObjectContextLockingError 132000
+C NSPersistentStoreCoordinatorLockingError 132010
+C NSManagedObjectReferentialIntegrityError 133000
+C NSManagedObjectExternalRelationshipError 133010
+C NSManagedObjectMergeError 133020
+
+C NSPersistentStoreInvalidTypeError 134000
+C NSPersistentStoreTypeMismatchError 134010
+C NSPersistentStoreIncompatibleSchemaError 134020
+C NSPersistentStoreSaveError 134030
+C NSPersistentStoreIncompleteSaveError 134040
+C NSPersistentStoreOperationError 134070
+C NSPersistentStoreOpenError 134080
+C NSPersistentStoreTimeoutError 134090
+C NSPersistentStoreIncompatibleVersionHashError 134100
+
+C NSMigrationError 134110
+C NSMigrationCancelledError 134120
+C NSMigrationMissingSourceModelError 134130
+C NSMigrationMissingMappingModelError 134140
+C NSMigrationManagerSourceStoreError 134150
+C NSMigrationManagerDestinationStoreError 134160
+C NSEntityMigrationPolicyError 134170
+C NSInferredMappingModelError 134190
+C NSExternalRecordImportError 134200
+
+C NSCoreDataError 134060
+C NSSQLiteError 134180
+
+V NSCoreDataVersionNumber d
+
+C NSCoreDataVersionNumber10_4 46.0
+C NSCoreDataVersionNumber10_4_3 77.0
+C NSCoreDataVersionNumber10_5 185.0
+C NSCoreDataVersionNumber10_5_3 186.0
+
+f MapKit
+
+C MKMapTypeStandard 0
+C MKMapTypeSatellite 1
+C MKMapTypeHybrid 2
+
+V MKErrorDomain @
+
+C MKErrorUnknown 1
+C MKErrorServerFailure 2
+C MKErrorLoadingThrottled 3
+C MKErrorPlacemarkNotFound 4
+
+C MKPinAnnotationColorRed 0
+C MKPinAnnotationColorGreen 1
+C MKPinAnnotationColorPurple 2
+
+# MKCoordinateRegionMake
+# MKCoordinateRegionMakeWithDistance
+# MKCoordinateSpanMake
static JSContextRef Context_;
-static JSClassRef ffi_;
-static JSClassRef joc_;
-static JSClassRef ptr_;
-static JSClassRef sel_;
+static JSClassRef Functor_;
+static JSClassRef Instance_;
+static JSClassRef Pointer_;
+static JSClassRef Selector_;
static JSObjectRef Array_;
static Class NSCFBoolean_;
+static NSMutableDictionary *Bridge_;
+
struct Client {
CFHTTPMessageRef message_;
CFSocketRef socket_;
};
JSObjectRef CYMakeObject(JSContextRef context, id object) {
- return JSObjectMake(context, joc_, [object retain]);
+ return JSObjectMake(context, Instance_, [object retain]);
}
@interface NSMethodSignature (Cyrver)
- (JSValueRef) cy$JSValueInContext:(JSContextRef)context;
@end
+@interface NSString (Cyrver)
+- (void *) cy$symbol;
+@end
+
+@interface NSNumber (Cyrver)
+- (void *) cy$symbol;
+@end
+
@implementation NSObject (Cyrver)
- (NSString *) cy$toJSON {
return [self class] != NSCFBoolean_ ? JSValueMakeNumber(context, [self doubleValue]) : JSValueMakeBoolean(context, [self boolValue]);
}
+- (void *) cy$symbol {
+ return [self pointerValue];
+}
+
@end
@implementation NSString (Cyrver)
return [reinterpret_cast<const NSString *>(json) autorelease];
}
+- (void *) cy$symbol {
+ return dlsym(RTLD_DEFAULT, [self UTF8String]);
+}
+
@end
@interface CYJSObject : NSDictionary {
void CYThrow(JSContextRef context, JSValueRef value);
id CYCastNSObject(JSContextRef context, JSObjectRef object) {
- if (JSValueIsObjectOfClass(context, object, joc_))
+ if (JSValueIsObjectOfClass(context, object, Instance_))
return reinterpret_cast<id>(JSObjectGetPrivate(object));
JSValueRef exception(NULL);
bool array(JSValueIsInstanceOfConstructor(context, object, Array_, &exception));
}
}
-static JSValueRef joc_getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) {
+static JSValueRef Instance_getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) {
return NULL;
}
typedef id jocData;
-static JSObjectRef joc_callAsConstructor(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { _pooled
+static JSObjectRef Instance_callAsConstructor(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) { _pooled
@try {
id data(reinterpret_cast<jocData>(JSObjectGetPrivate(object)));
return CYMakeObject(context, [[data alloc] autorelease]);
}
};
-static void ptr_finalize(JSObjectRef object) {
+static void Pointer_finalize(JSObjectRef object) {
ptrData *data(reinterpret_cast<ptrData *>(JSObjectGetPrivate(object)));
apr_pool_destroy(data->pool_);
}
-static void joc_finalize(JSObjectRef object) {
+static void Instance_finalize(JSObjectRef object) {
id data(reinterpret_cast<jocData>(JSObjectGetPrivate(object)));
[data release];
}
-static JSValueRef obc_getProperty(JSContextRef context, JSObjectRef object, JSStringRef propertyName, JSValueRef *exception) { _pooled
- NSString *name([(NSString *) JSStringCopyCFString(kCFAllocatorDefault, propertyName) autorelease]);
- if (Class _class = NSClassFromString(name))
- return CYMakeObject(context, _class);
- return NULL;
+JSObjectRef CYMakeFunction(JSContextRef context, void (*function)(), const char *type) {
+ ffiData *data(new ffiData(function, type));
+ return JSObjectMake(context, Functor_, data);
+}
+
+
+JSObjectRef CYMakeFunction(JSContextRef context, void *function, const char *type) {
+ 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) {
SEL CYCastSEL(JSContextRef context, JSValueRef value) {
if (JSValueIsNull(context, value))
return NULL;
- else if (JSValueIsObjectOfClass(context, value, sel_)) {
+ else if (JSValueIsObjectOfClass(context, value, Selector_)) {
selData *data(reinterpret_cast<selData *>(JSObjectGetPrivate((JSObjectRef) value)));
return reinterpret_cast<SEL>(data->value_);
} else
return dlsym(RTLD_DEFAULT, CYCastCString(context, value));
case kJSTypeObject:
// XXX: maybe support more than just pointers, like ffis and sels
- if (JSValueIsObjectOfClass(context, value, ptr_)) {
+ if (JSValueIsObjectOfClass(context, value, Pointer_)) {
ptrData *data(reinterpret_cast<ptrData *>(JSObjectGetPrivate((JSObjectRef) value)));
return data->value_;
}
case sig::selector_P: {
if (SEL sel = *reinterpret_cast<SEL *>(data)) {
selData *data(new selData(sel));
- value = JSObjectMake(context, sel_, data);
+ value = JSObjectMake(context, Selector_, data);
} else value = JSValueMakeNull(context);
} break;
case sig::pointer_P: {
if (void *pointer = *reinterpret_cast<void **>(data)) {
ptrData *data(new ptrData(pointer));
- value = JSObjectMake(context, ptr_, data);
+ value = JSObjectMake(context, Pointer_, data);
} else value = JSValueMakeNull(context);
} break;
return CYCallFunction(context, count, arguments, exception, &data->signature_, &data->cif_, reinterpret_cast<void (*)()>(data->value_));
}
-JSObjectRef CYMakeFunction(JSContextRef context, void (*function)(), const char *type) {
- ffiData *data(new ffiData(function, type));
- return JSObjectMake(context, ffi_, data);
-}
-
JSObjectRef ffi(JSContextRef context, JSObjectRef object, size_t count, const JSValueRef arguments[], JSValueRef *exception) {
@try {
if (count != 2)
[NSException raise:NSInvalidArgumentException format:@"incorrect number of arguments to ffi constructor"];
- void (*function)() = reinterpret_cast<void (*)()>(CYCastPointer(context, arguments[0]));
+ void *function(CYCastPointer(context, arguments[0]));
const char *type(CYCastCString(context, arguments[1]));
return CYMakeFunction(context, function, type);
} CYCatch
}
-JSValueRef ptr_getProperty_value(JSContextRef context, JSObjectRef object, JSStringRef name, JSValueRef *exception) {
+JSValueRef Pointer_getProperty_value(JSContextRef context, JSObjectRef object, JSStringRef name, JSValueRef *exception) {
ptrData *data(reinterpret_cast<ptrData *>(JSObjectGetPrivate(object)));
return JSValueMakeNumber(context, reinterpret_cast<uintptr_t>(data->value_));
}
-static JSStaticValue ptr_staticValues[2] = {
- {"value", &ptr_getProperty_value, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete},
+static JSStaticValue Pointer_staticValues[2] = {
+ {"value", &Pointer_getProperty_value, NULL, kJSPropertyAttributeReadOnly | kJSPropertyAttributeDontDelete},
{NULL, NULL, NULL, 0}
};
JSClassDefinition definition;
definition = kJSClassDefinitionEmpty;
- definition.getProperty = &obc_getProperty;
- JSClassRef obc(JSClassCreate(&definition));
+ definition.className = "Pointer";
+ definition.staticValues = Pointer_staticValues;
+ definition.finalize = &Pointer_finalize;
+ Pointer_ = JSClassCreate(&definition);
definition = kJSClassDefinitionEmpty;
- definition.className = "ptr";
- definition.staticValues = ptr_staticValues;
- definition.finalize = &ptr_finalize;
- ptr_ = JSClassCreate(&definition);
+ definition.className = "Functor";
+ definition.parentClass = Pointer_;
+ definition.callAsFunction = &ffi_callAsFunction;
+ Functor_ = JSClassCreate(&definition);
definition = kJSClassDefinitionEmpty;
- definition.className = "ffi";
- definition.parentClass = ptr_;
- definition.callAsFunction = &ffi_callAsFunction;
- ffi_ = JSClassCreate(&definition);
+ definition.className = "Selector";
+ definition.parentClass = Pointer_;
+ Selector_ = JSClassCreate(&definition);
definition = kJSClassDefinitionEmpty;
- definition.className = "sel";
- definition.parentClass = ptr_;
- sel_ = JSClassCreate(&definition);
+ definition.className = "Instance_";
+ definition.getProperty = &Instance_getProperty;
+ definition.callAsConstructor = &Instance_callAsConstructor;
+ definition.finalize = &Instance_finalize;
+ Instance_ = JSClassCreate(&definition);
definition = kJSClassDefinitionEmpty;
- definition.className = "joc";
- definition.getProperty = &joc_getProperty;
- definition.callAsConstructor = &joc_callAsConstructor;
- definition.finalize = &joc_finalize;
- joc_ = JSClassCreate(&definition);
+ definition.getProperty = &Global_getProperty;
+ JSClassRef Global(JSClassCreate(&definition));
- JSContextRef context(JSGlobalContextCreate(obc));
+ JSContextRef context(JSGlobalContextCreate(Global));
Context_ = context;
JSObjectRef global(JSContextGetGlobalObject(context));
- CYSetProperty(context, global, "ffi", JSObjectMakeConstructor(context, ffi_, &ffi));
- CYSetProperty(context, global, "obc", JSObjectMake(context, obc, NULL));
-
-#define CYSetFunction_(name, type) \
- CYSetProperty(context, global, #name, CYMakeFunction(context, reinterpret_cast<void (*)()>(&name), type))
-
- CYSetFunction_(class_addIvar, "B#*LC*");
- CYSetFunction_(class_addMethod, "B#:^?*");
- CYSetFunction_(class_addProtocol, "B#@");
- CYSetFunction_(class_conformsToProtocol, "B#@");
- CYSetFunction_(class_copyIvarList, "^^{objc_ivar=}#^I");
- CYSetFunction_(class_copyMethodList, "^^{objc_method=}#^I");
- CYSetFunction_(class_copyPropertyList, "^^{objc_property=}#^I");
- CYSetFunction_(class_copyProtocolList, "^@#^I");
- CYSetFunction_(class_createInstance, "@#L");
- CYSetFunction_(class_getClassMethod, "^{objc_method=}#:");
- CYSetFunction_(class_getClassVariable, "^{objc_ivar=}#*");
- CYSetFunction_(class_getInstanceMethod, "^{objc_method=}#:");
- CYSetFunction_(class_getInstanceSize, "L#");
- CYSetFunction_(class_getInstanceVariable, "^{objc_ivar=}#*");
- CYSetFunction_(class_getIvarLayout, "*#");
- CYSetFunction_(class_getMethodImplementation, "^?#:");
- CYSetFunction_(class_getMethodImplementation_stret, "^?#:");
- CYSetFunction_(class_getName, "*#");
- CYSetFunction_(class_getProperty, "^{objc_property=}#*");
- CYSetFunction_(class_getSuperclass, "##");
- CYSetFunction_(class_getVersion, "i#");
- CYSetFunction_(class_getWeakIvarLayout, "*#");
- CYSetFunction_(class_isMetaClass, "B#");
- CYSetFunction_(class_replaceMethod, "^?#:^?*");
- CYSetFunction_(class_respondsToSelector, "B#:");
- CYSetFunction_(class_setIvarLayout, "v#*");
- CYSetFunction_(class_setSuperclass, "###");
- CYSetFunction_(class_setVersion, "v#i");
- CYSetFunction_(class_setWeakIvarLayout, "v#*");
- CYSetFunction_(ivar_getName, "*^{objc_ivar=}");
- CYSetFunction_(ivar_getOffset, "i^{objc_ivar=}");
- CYSetFunction_(ivar_getTypeEncoding, "*^{objc_ivar=}");
- CYSetFunction_(method_copyArgumentType, "^c^{objc_method=}I");
- CYSetFunction_(method_copyReturnType, "^c^{objc_method=}");
- CYSetFunction_(method_exchangeImplementations, "v^{objc_method=}^{objc_method=}");
- CYSetFunction_(method_getArgumentType, "v^{objc_method=}I^cL");
- CYSetFunction_(method_getImplementation, "^?^{objc_method=}");
- CYSetFunction_(method_getName, ":^{objc_method=}");
- CYSetFunction_(method_getNumberOfArguments, "I^{objc_method=}");
- CYSetFunction_(method_getReturnType, "v^{objc_method=}^cL");
- CYSetFunction_(method_getTypeEncoding, "*^{objc_method=}");
- CYSetFunction_(method_setImplementation, "^?^{objc_method=}^?");
- CYSetFunction_(objc_allocateClassPair, "##*L");
- CYSetFunction_(objc_copyProtocolList, "^@^I");
- CYSetFunction_(objc_duplicateClass, "##*L");
- CYSetFunction_(objc_getClass, "#*");
- CYSetFunction_(objc_getClassList, "i^#i");
- CYSetFunction_(objc_getFutureClass, "#*");
- CYSetFunction_(objc_getMetaClass, "@*");
- CYSetFunction_(objc_getProtocol, "@*");
- CYSetFunction_(objc_getRequiredClass, "@*");
- CYSetFunction_(objc_lookUpClass, "@*");
- CYSetFunction_(objc_registerClassPair, "v#");
- CYSetFunction_(objc_setFutureClass, "v#*");
- CYSetFunction_(object_copy, "@@L");
- CYSetFunction_(object_dispose, "@@");
- CYSetFunction_(object_getClass, "#@");
- CYSetFunction_(object_getClassName, "*@");
- CYSetFunction_(object_getIndexedIvars, "^v@");
- CYSetFunction_(object_getInstanceVariable, "^{objc_ivar=}@*^^v");
- CYSetFunction_(object_getIvar, "@@^{objc_ivar=}");
- CYSetFunction_(object_setClass, "#@#");
- CYSetFunction_(object_setInstanceVariable, "^{objc_ivar=}@*^v");
- CYSetFunction_(object_setIvar, "v@^{objc_ivar=}@");
- CYSetFunction_(property_getAttributes, "*^{objc_property=}");
- CYSetFunction_(property_getName, "*^{objc_property=}");
- CYSetFunction_(protocol_conformsToProtocol, "B@@");
- CYSetFunction_(protocol_copyMethodDescriptionList, "^{objc_method_description=:*}@BB^I");
- CYSetFunction_(protocol_copyPropertyList, "^{objc_property=}@^I");
- CYSetFunction_(protocol_copyProtocolList, "^@@^I");
- CYSetFunction_(protocol_getMethodDescription, "{objc_method_description=:*}@:BB");
- CYSetFunction_(protocol_getName, "*@");
- CYSetFunction_(protocol_getProperty, "^{objc_property=}@*BB");
- CYSetFunction_(protocol_isEqual, "B@@");
- CYSetFunction_(sel_getName, "*:");
- CYSetFunction_(sel_getUid, ":*");
- CYSetFunction_(sel_isEqual, "B::");
- CYSetFunction_(sel_registerName, ":*");
+ CYSetProperty(context, global, "ffi", JSObjectMakeConstructor(context, Functor_, &ffi));
CYSetProperty(context, global, "objc_msgSend", JSObjectMakeFunctionWithCallback(context, CYString("objc_msgSend"), &$objc_msgSend));
- CYSetProperty(context, global, "YES", JSValueMakeBoolean(context, true));
- CYSetProperty(context, global, "NO", JSValueMakeBoolean(context, false));
- CYSetProperty(context, global, "nil", JSValueMakeNull(context));
+ Bridge_ = [[NSMutableDictionary dictionaryWithContentsOfFile:@"/usr/lib/libcyrver.plist"] retain];
name_ = JSStringCreateWithUTF8CString("name");
message_ = JSStringCreateWithUTF8CString("message");
link := -framework CoreFoundation -framework Foundation -F${PKG_ROOT}/System/Library/PrivateFrameworks -L$(menes)/mobilesubstrate -lsubstrate -lapr-1 -lffi
-all: $(name).dylib $(control)
+all: cyrver $(name).dylib libcyrver.plist
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 \
+ if [[ $$line == '' ]]; then \
+ continue; \
+ fi; \
+ set $$line; \
+ if [[ $$1 =~ [#fl] ]]; then \
+ continue; \
+ fi; \
+ echo "$$2 = ($$1, \"$$3\");"; \
+ done >$@
+
Struct.hpp:
$$($(target)gcc -print-prog-name=cc1obj) -print-objc-runtime-info </dev/null >$@
package: all
rm -rf package
mkdir -p package/DEBIAN
+ cp -a control package/DEBIAN
mkdir -p package/Library/MobileSubstrate/DynamicLibraries
- cp -a control $(control) package/DEBIAN
if [[ -e Settings.plist ]]; then \
mkdir -p package/Library/PreferenceLoader/Preferences; \
cp -a Settings.png package/Library/PreferenceLoader/Preferences/$(name)Icon.png; \
fi
if [[ -e Tweak.plist ]]; then cp -a Tweak.plist package/Library/MobileSubstrate/DynamicLibraries/$(name).plist; fi
cp -a $(name).dylib package/Library/MobileSubstrate/DynamicLibraries
- $(MAKE) extra
- dpkg-deb -b package $(shell grep ^Package: control | cut -d ' ' -f 2-)_$(shell grep ^Version: control | cut -d ' ' -f 2)_iphoneos-arm.deb
-
-extra:
-
-%: %.mm
- $(target)g++ -o $@ -Wall -Werror $< -lobjc -framework CoreFoundation -framework Foundation
-
-.PHONY: all clean extra package
-
-all: cyrver
-
-extra:
mkdir -p package/usr/{bin,lib}
mv package/Library/MobileSubstrate/DynamicLibraries/Cyrver.dylib package/usr/lib/libcyrver.dylib
ln -s /usr/lib/libcyrver.dylib package/Library/MobileSubstrate/DynamicLibraries/Cyrver.dylib
cp -a cyrver package/usr/bin
+ cp -a libcyrver.plist package/usr/lib
+ dpkg-deb -b package $(shell grep ^Package: control | cut -d ' ' -f 2-)_$(shell grep ^Version: control | cut -d ' ' -f 2)_iphoneos-arm.deb
+
+.PHONY: all clean extra package
cyrver: Application.mm Cyrver.dylib
$(target)g++ -g0 -O2 -Wall -Werror -o $@ $(filter %.mm,$^) -framework UIKit -framework Foundation -framework CoreFoundation -lobjc Cyrver.dylib -framework JavaScriptCore -F${PKG_ROOT}/System/Library/PrivateFrameworks