Hello, there

i am happy to say that during last week, i found a cure for my
callback code, and so finally callbacks are now working without
crashing the VM. :)
But before releasing it to public, first, i need to update VMs for
that, because of additional callback support code in VM.

Right now, i'd like to discuss about different ways of
defining/creating callbacks. And i need more input from people,
because i think
the way how i implemented it is good for get started, but it looks
like there could be more convenient forms :)

So, the existing implementation, for creating a callback, you must
make a subclass of NBFFICallback, overide #fnSpec method
and then instantiate it by using:

callback := MyCallBack on: [:... some block ]

and then you must pass it somewhere (to some external function), and
so, when callback get called, your block will handle it.

In objective-C, however it would be much nicer to have a smalltalk
objects act as a Obj-C objects (so implementing a methods
for it will naturally map them as a callbacks ).

For instance imagine that i wanna make own subclass of NSFoo obj-C class
and wanna override the #bar method.
And then i passing it as an obj-c instance around and each time ,Obj-C
#bar message is sent to it , i got a #bar message sent to my smalltalk
instance.
That would be really cool, isnt? Despite it is only applicable to
obj-c  because of similar object model :)

I imagine it could be done as following:
in #bar method you putting a special pragma:

MyClass>>bar
 <objCMethod: 'int ()'>
  ^ 5

that's it, you telling the compiler that given method can be called
from Objective-C.. and you don't have to manually instantiate
callbacks etc..

In fact, same form can be used for non-objC callbacks , you must just
tell something like:

callback := (MyClass>>#bar) asCallbackFor: myObject.

here, you instantiating a callback, which when called, the object
'myObject' will receive #bar message. But unlike from Obj-C this
callback
won't work for all instances of MyClass, but just for specific one.

And third form is a variation of original one, instead of subclassing
the NBFFICallback, actually i can change implementation to use special
factory class(es) for it, so to create a callback you will do
something like:

callbackFactory := NBFFICallback withSignature: #( int (int x, void * bar)).

callback := callbackFactory on: [:x :bar | .... ].

So, i'd like to hear your input, which one you like, and which ones
you prefer to have

1. requires creating a subclass of NBFFICallback, overriding it's
fnSpec method. Takes a block closure as a callback.
2. first you must create a factory object by specifying a callback
signature, then you can instantiate new callbacks by passing a block
closure to that factory
3. to create a callback you must specify it's signature in one of the
compiled methods, and specify an object which will receive a message
when callback will be called.


-- 
Best regards,
Igor Stasenko.

Reply via email to