
EN: rebol.com -
rebol.org -
rebol.net -
FR: Rebol Documentation Project -
forum RebelBB -
rebol-france.org -
forum codeur -
Note for translation purpose dokuwiki to MD2 format you can use this cute little script (a little bit modificate to read this page) http://rebol.dev.fr/view.php?sid=150
As Carl Sassenrath is back today we have a nice chat with him regarding using rebol function directly from C code. It’s what we can call callbacks.
Callbacks are first based on a datatype in rebol named callback!
Some rebolers like Cyphre, Jaime Vargas, Pekr, Romano, Gabriele, have asked thru ALTME to Carl Sassenrath what datatype callbacks! stand for in REBOL VM. Gently Carl try to apport the needed knowledge on it :) !!
Carl describe it like this : “
It was implemented as part of what was needed by the Morpheus project, and it should be part of existing builds for Win32 and Unixes that use stack-based function arguments. You put the CALLBACK into the routine specs.
In the text that follows, the word ”spec“ refers to the make routine! specification block.
eg: […. [CALLBACK ….] ….]
At that time it builds a frame to call the REBOL callback function.
I should note that there is a limit to the maximum # of callbacks you can have: 16.
This is due to the fact that the stack frames for each callback # must be literally implemented within the C code itself TIMES the # of datatypes that are allowed to be returned from the callback.
Currently callbacks are allowed to only return: integer, decimal, and string. (And void - no result)
Note that if you specify a callback function that returns INTEGER but you actually return something else, REBOL will force the result to a null integer (zero). Same is true for the other returned datatypes.
They only work in win32 and unix, and only on specific cpu’s with specific compilers.
Also: don’t forget to specify the RETURN [(type)] in the CALLBACK spec block, if you need a returned value.
Note that […. [callback …. return [callback]]] is allowed.
But I’m not so sure if it works or what the result will be.
Also note: the spec can include multiple callbacks. CALLBACK! is a virtual datatype.
On OSX, the routine parsing function does not recognize the CALLBACK! word. ”
Cyphre code illustrating this:
C SIDE :
extern "C" MYDLL_API int test(int a, int b, int (*pFunc)(int, int)) { int result = pFunc(a, b); return result; }
REBOL SIDE :
add-it: func [a b][return a + b] test: make routine! [ a [int] b [int] c [callback! [int int return: [int]]] return: [int] ] agg-lib "test" >> test 1 2 :add-it == 3 >>