![]() |
R3 et extensions | |
ldci | 20-Feb-2015/14:00:20+1:00 |
Salut à tous, Avec Greg on a commencé à jouer avec les extensions pour R3. Pas mal grâce au code ce Carl ![]() Par contre, la documentation est incomplète et j'ai un problème avec les callbacks comme dans l'exemple suivant en C typedef void (CV_CDECL *CvTrackbarCallback)(int pos); generic pointer to function /* create trackbar and display it on top of given window, set callback */ CVAPI(int) cvCreateTrackbar( const char* trackbar_name, const char* window_name, int* value, int count, CvTrackbarCallback on_change CV_DEFAULT(NULL)); Avec R2 c'était facile, il suffisait de définir un pointeur (de code) sur une fonction rebol ; function pointer that can be called by TrackBar callback trackEvent: func [ pos [integer!] ][print ["Trackbar position is : " pos]] et de l'appeler de la façon suivante: cvCreateTrackbar "Track" windowsName &p 0 :trackEvent ; function as parameter Ca marche très bien, à chaque modification tu tarckbar, la fonction trackEvent renvoie la position Qui aurait une idée lumineuse pour R3 ? | |
GreG | 23-Feb-2015/14:01:16+1:00 |
Hello, Effectivement, on a commencé à jouer avec les extensions R3 et nous avons commencé une extension SDL 2.0 ainsi qu'une extension OpenCV. François, as-tu déjà regardé la doc suivante: http://www.rebol.com/r3/docs/concepts/extensions-callbacks.html Je n'ai pas encore testé les callbacks de mon coté. | |
GreG | 5-Mar-2015/15:38:39+1:00 |
Si je reprends le template de sdl2r3, ainsi que l'exemple trouvé ici: https://github.com/rebol/rebol/blob/master/src/os/host-ext-test.c code pour un callback synchrone: "export calls: command [{test sync callback} context [object!] callback [word!]]\n" RXIEXT int R3SDL_calls (RXIFRM *frm){ // CBI: Callback Information structure with following attributes: // obj: the object context of the function // word: the function's name, a word id // args: the RXIARG argument array to hold input arguments // result: space to hold the result of the callback // flags: for special options (and future controls) RXICBI cbi; RXIARG args[4]; REBCNT n; // These can be on the stack, because it's synchronous. CLEAR(&cbi, sizeof(cbi)); CLEAR(&args[0], sizeof(args)); cbi.obj = RXA_OBJECT(frm, 1); // context where function is declared cbi.word = RXA_WORD(frm, 2); // function to call in above context cbi.args = args; // argument to send to callback function // Pass a single integer arg to the callback function: RXI_COUNT(args) = 1; RXI_TYPE(args, 1) = RXT_INTEGER; args[1].int64 = 123456; // make the call to the REBOL function // n is the datatype enum of the returned value, 0 if error n = RL_CALLBACK(&cbi); if(n == 0) {RL_PRINT("%s\n", "callback error");} RXA_ARG(frm, 1) = cbi.result; RXA_TYPE(frm, 1) = n; return RXR_VALUE; } >> import %sdl2r3.dll >> ctx: context [a: 1 yop: func [t] [print t]] >> calls ctx 'yop 123456 | |
Login required to Post. |