the rdyncall package
play

the rdyncall package A n i m p r o v e d f o r e i g n f u n c t - PowerPoint PPT Presentation

the rdyncall package A n i m p r o v e d f o r e i g n f u n c t i o n i n t e r f a c e f o r R Daniel Adler Tassilo Philipp Georg-August Potion Studios Universitt Gttingen Game Development useR! 2009, 9th of July,


  1. the rdyncall package A n i m p r o v e d f o r e i g n f u n c t i o n i n t e r f a c e f o r R Daniel Adler Tassilo Philipp Georg-August Potion Studios Universität Göttingen Game Development useR! 2009, 9th of July, Rennes, France

  2. Program of this talk Binding Binary Functionality Example: Binding R with libSDL using ".C(..)" Improvements using ".dyncall(..)" Implementation: the dyncall C library Overview of the rdyncall R Package 'Dynports' concept Availability

  3. Binding Binary Functionality

  4. Binding Binary Functionality Compiled Libraries Dynamic Languages

  5. Binding Binary Functionality Compiled Libraries Dynamic Languages

  6. Binding Binary Functionality Compiled Libraries SDL Simple Directmedia Layer Dynamic Languages

  7. Binding Binary Functionality Compiled Libraries SDL Simple Directmedia Layer C Dynamic Languages

  8. Binding Binary Functionality Compiled Libraries SDL Simple Directmedia Layer C Dynamic Languages

  9. Binding Binary Functionality Compiled Libraries glew C SDL Simple Directmedia Layer C C C C Dynamic Languages

  10. Binding Binary Functionality Compiled Libraries glew C SDL Simple Directmedia Layer C C C C Dynamic Languages

  11. Binding Binary Functionality Compiled Libraries glew C SDL Simple Directmedia Layer C C C C Dynamic Languages

  12. Binding Binary Functionality Compiled Libraries glew C SDL Simple Directmedia Layer C C C C Dynamic Languages

  13. Binding Binary Functionality Compiled Libraries glew C C SDL Simple Directmedia Layer C C C C Dynamic Languages

  14. Binding Binary Functionality Compiled Libraries glew C C SDL Simple Directmedia Layer C C C C Dynamic Languages

  15. Binding Binary Functionality Compiled Libraries glew C C SDL Simple Directmedia Layer C C C C Call(args) Foreign Function Interface Results Dynamic Languages

  16. Binding libSDL using ".C(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags);

  17. Binding libSDL using ".C(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); surface <- .C(funaddr, 640L, 480L, 32L, 0L) R calls C:

  18. Binding libSDL using ".C(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); fails surface <- .C(funaddr, 640L, 480L, 32L, 0L) R calls C:

  19. Binding libSDL using ".C(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); fails surface <- .C(funaddr, 640L, 480L, 32L, 0L) R calls C: Expected C Interface: void SDL_SetVideoMode(int* w, int* h, int* bpp, int* flags); R to C mapping: Limitations: R Vector mode C Pointer Type logical int* integer int* double double* character char** raw unsigned char*

  20. Binding libSDL using ".C(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); fails surface <- .C(funaddr, 640L, 480L, 32L, 0L) R calls C: Expected C Interface: void SDL_SetVideoMode(int* w, int* h, int* bpp, int* flags); R to C mapping: Limitations: R Vector mode C Pointer Type logical int* no scalar types integer int* double double* character char** raw unsigned char*

  21. Binding libSDL using ".C(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); fails surface <- .C(funaddr, 640L, 480L, 32L, 0L) R calls C: Expected C Interface: void SDL_SetVideoMode(int* w, int* h, int* bpp, int* flags); R to C mapping: Limitations: R Vector mode C Pointer Type logical int* no scalar types integer int* no return types double double* character char** raw unsigned char*

  22. Binding libSDL using ".C(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); fails surface <- .C(funaddr, 640L, 480L, 32L, 0L) R calls C: Expected C Interface: void SDL_SetVideoMode(int* w, int* h, int* bpp, int* flags); R to C mapping: Limitations: R Vector mode C Pointer Type logical int* no scalar types integer int* no return types double double* one-to-one mapping character char** raw unsigned char*

  23. Binding libSDL using ".Call(..)" + Wrapper DLL C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags);

  24. Binding libSDL using ".Call(..)" + Wrapper DLL C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); SEXP wrapper(SEXP w, SEXP h, SEXP bpp, SEXP flags) { return R_MakeExternalPtr( SDL_SetVideoMode( C wrapper INTEGER(w)[0], INTEGER(h)[0], source code: INTEGER(bpp)[0], (uint) INTEGER(flags)[0] ), R_NilValue, R_NilValue); }

  25. Binding libSDL using ".Call(..)" + Wrapper DLL C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); SEXP wrapper(SEXP w, SEXP h, SEXP bpp, SEXP flags) { return R_MakeExternalPtr( SDL_SetVideoMode( C wrapper INTEGER(w)[0], INTEGER(h)[0], source code: INTEGER(bpp)[0], (uint) INTEGER(flags)[0] ), R_NilValue, R_NilValue); } Runtime: wrapper.dll SDL.dll

  26. Binding libSDL using ".Call(..)" + Wrapper DLL C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); SEXP wrapper(SEXP w, SEXP h, SEXP bpp, SEXP flags) { return R_MakeExternalPtr( SDL_SetVideoMode( C wrapper INTEGER(w)[0], INTEGER(h)[0], source code: INTEGER(bpp)[0], (uint) INTEGER(flags)[0] ), R_NilValue, R_NilValue); } compile, link Runtime: wrapper.dll SDL.dll

  27. Binding libSDL using ".Call(..)" + Wrapper DLL C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); SEXP wrapper(SEXP w, SEXP h, SEXP bpp, SEXP flags) { return R_MakeExternalPtr( SDL_SetVideoMode( C wrapper INTEGER(w)[0], INTEGER(h)[0], source code: INTEGER(bpp)[0], (uint) INTEGER(flags)[0] ), R_NilValue, R_NilValue); } compile, link Runtime: wrapper.dll SDL.dll

  28. Binding libSDL using ".Call(..)" + Wrapper DLL C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); SEXP wrapper(SEXP w, SEXP h, SEXP bpp, SEXP flags) { return R_MakeExternalPtr( SDL_SetVideoMode( C wrapper INTEGER(w)[0], INTEGER(h)[0], source code: INTEGER(bpp)[0], (uint) INTEGER(flags)[0] ), R_NilValue, R_NilValue); } compile, link Runtime: wrapper.dll SDL.dll surfPtr <- .Call(wrapper_funptr, 640L, 480L, 32L, 0L ) R calls C:

  29. Direct call using ".dyncall(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags);

  30. Direct call using ".dyncall(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); surface <- .dyncall(funaddr, "iiiI)p" , 640L, 480L, 32L, 0L) R calls C:

  31. Direct call using ".dyncall(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); surface <- .dyncall(funaddr, "iiiI)p" , 640L, 480L, 32L, 0L) R calls C: Function Call Signature

  32. Direct call using ".dyncall(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); surface <- .dyncall(funaddr, "iiiI)p" , 640L, 480L, 32L, 0L) R calls C: Function Call Signature Signature "{argument types in left-to-right order} ' ) ' {return type}" Format:

  33. Direct call using ".dyncall(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); surface <- .dyncall(funaddr, "iiiI)p" , 640L, 480L, 32L, 0L) R calls C: Function Call Signature Signature "{argument types in left-to-right order} ' ) ' {return type}" Format: C Type Signature Character void 'v' char, short, int, long, long long 'c', 's', 'i', 'j', 'l' 'C', 'S', 'I', 'J', 'L' unsigned integers (capitalized) float, double 'f', 'd' T* (any C pointer) 'p' or '*' ... const char*(C String) 'Z' bool (c++), _Bool_t 'B' struct/union C pointers '*<' typename '>'

  34. Direct call using ".dyncall(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); surface <- .dyncall(funaddr, "iiiI)p" , 640L, 480L, 32L, 0L) R calls C: Function Call Signature Signature "{argument types in left-to-right order} ' ) ' {return type}" Format: Supports C Type Signature Character void 'v' char, short, int, long, long long 'c', 's', 'i', 'j', 'l' 'C', 'S', 'I', 'J', 'L' unsigned integers (capitalized) float, double 'f', 'd' T* (any C pointer) 'p' or '*' ... const char*(C String) 'Z' bool (c++), _Bool_t 'B' struct/union C pointers '*<' typename '>'

  35. Direct call using ".dyncall(..)" C Function: SDL_Surface* SDL_SetVideoMode(int w, int h, int bpp, uint flags); surface <- .dyncall(funaddr, "iiiI)p" , 640L, 480L, 32L, 0L) R calls C: Function Call Signature Signature "{argument types in left-to-right order} ' ) ' {return type}" Format: Supports C Type Signature Character void 'v' scalars char, short, int, long, long long 'c', 's', 'i', 'j', 'l' 'C', 'S', 'I', 'J', 'L' unsigned integers (capitalized) float, double 'f', 'd' T* (any C pointer) 'p' or '*' ... const char*(C String) 'Z' bool (c++), _Bool_t 'B' struct/union C pointers '*<' typename '>'

Recommend


More recommend