diff --git a/src/ObjectiveC/ObjCProxyCallback.class.st b/src/ObjectiveC/ObjCProxyCallback.class.st index 6cac34f..28236ca 100644 --- a/src/ObjectiveC/ObjCProxyCallback.class.st +++ b/src/ObjectiveC/ObjCProxyCallback.class.st @@ -1,3 +1,7 @@ +" +I'm a special callback, meant to implement proxy methods. +ObjC will call Pharo using this callbacks. +" Class { #name : #ObjCProxyCallback, #superclass : #FFICallback, @@ -12,12 +16,25 @@ ObjCProxyCallback >> parseSignature: signature [ ^ self newParser parseSignature: signature ] +{ #category : #initialization } +ObjCProxyCallback >> signature: signature block: aBlock [ + + super signature: signature block: aBlock. + functionSpec arguments: { + ObjCProxyCallbackArgument new. "receiver" + ObjCProxyCallbackArgument new. "selector" + }, + functionSpec arguments. + +] + { #category : #evaluation } ObjCProxyCallback >> valueWithArguments: args [ - ^ [ - "skip self, SEL and keep just the arguments" - block value: (args allButFirst: 2) ] + ^ [ block + value: args first + value: args second + value: (args allButFirst: 2) ] on: Error fork: [ :e | e debug ] return: [ self returnOnError ] diff --git a/src/ObjectiveC/ObjCProxyCallbackArgument.class.st b/src/ObjectiveC/ObjCProxyCallbackArgument.class.st new file mode 100644 index 0000000..ce3a48a --- /dev/null +++ b/src/ObjectiveC/ObjCProxyCallbackArgument.class.st @@ -0,0 +1,52 @@ +" +I'm a function argument type to be used on the declaration of proxy methods. +I am needed because in ObjC every method implementation has the same structure: + +id (*IMP)(receiver, selector, ...) + +https://developer.apple.com/documentation/objectivec/objective-c_runtime/imp + +being the first two arguments the receiver and the selector. +this is internally converted to a send of the form + +receiver selector: arg + +(a call with the arguments). + +To match a regular send, we need to add this arguments to the callback, but they are hidden to the user. + + +" +Class { + #name : #ObjCProxyCallbackArgument, + #superclass : #FFIFunctionArgument, + #traits : 'TObjCLibrary', + #classTraits : 'TObjCLibrary classTrait', + #category : #'ObjectiveC-Proxy' +} + +{ #category : #resolution } +ObjCProxyCallbackArgument >> asOldArraySpec [ + + ^ #() +] + +{ #category : #initialization } +ObjCProxyCallbackArgument >> initialize [ + + super initialize. + type := ObjCTypeDeclaration newType: (FFIVoid new + pointerArity: 1; + yourself) +] + +{ #category : #resolution } +ObjCProxyCallbackArgument >> resolveUsing: aResolver [ + "Do nothing" +] + +{ #category : #initialization } +ObjCProxyCallbackArgument >> resolvedType [ + + ^ type resolvedType +] diff --git a/src/ObjectiveC/ObjCProxyClass.class.st b/src/ObjectiveC/ObjCProxyClass.class.st index cb97f8f..b33218b 100644 --- a/src/ObjectiveC/ObjCProxyClass.class.st +++ b/src/ObjectiveC/ObjCProxyClass.class.st @@ -1,3 +1,6 @@ +" +I define a class that will be installed in ObjC and will work as a proxy between ObjC and Pharo +" Class { #name : #ObjCProxyClass, #superclass : #Object, @@ -95,7 +98,7 @@ ObjCProxyClass >> class_addMethodClass: cls selector: name implementation: imp s { #category : #private } ObjCProxyClass >> createCallbackFor: aSelector signature: aString [ - ^ ObjCProxyCallback + ^ ObjCProxyCallback signature: aString block: [ :receiver :ignoredSelector :args | self diff --git a/src/ObjectiveC/ObjCProxyObject.class.st b/src/ObjectiveC/ObjCProxyObject.class.st index fbdc28e..0e657c7 100644 --- a/src/ObjectiveC/ObjCProxyObject.class.st +++ b/src/ObjectiveC/ObjCProxyObject.class.st @@ -9,9 +9,6 @@ Class { #superclass : #Object, #traits : 'TObjCProxyClass', #classTraits : 'TObjCProxyClass classTrait', - #instVars : [ - 'proxy' - ], #category : #'ObjectiveC-Proxy' } @@ -32,13 +29,3 @@ ObjCProxyObject >> initialize [ ObjCProxyObject >> initializeProxy [ ] - -{ #category : #accessing } -ObjCProxyObject >> proxy [ - ^ proxy -] - -{ #category : #accessing } -ObjCProxyObject >> proxy: anObject [ - proxy := anObject. -] diff --git a/src/ObjectiveC/ObjCTypeDeclaration.class.st b/src/ObjectiveC/ObjCTypeDeclaration.class.st index f6e1ccb..79b0b69 100644 --- a/src/ObjectiveC/ObjCTypeDeclaration.class.st +++ b/src/ObjectiveC/ObjCTypeDeclaration.class.st @@ -1,3 +1,7 @@ +" +I'm a type declaration for ObjC functions. +I'm needed because when matching ObjC functions I already have all needed data, so I can skip the resolution of type. +" Class { #name : #ObjCTypeDeclaration, #superclass : #FFITypeDeclaration,