Wrapping Functions Inside of Struct?
- Posted by Icy_Viking Oct 10, 2022
- 927 views
Hi all,
I'm just wondering if there's a way to wrap functions that are in a struct or is there some other work-a-round?
//header file "file.h" from Allegro typedef struct ALLEGRO_FILE_INTERFACE { AL_METHOD(void *, fi_fopen, (const char *path, const char *mode)); AL_METHOD(bool, fi_fclose, (ALLEGRO_FILE *handle)); AL_METHOD(size_t, fi_fread, (ALLEGRO_FILE *f, void *ptr, size_t size)); AL_METHOD(size_t, fi_fwrite, (ALLEGRO_FILE *f, const void *ptr, size_t size)); AL_METHOD(bool, fi_fflush, (ALLEGRO_FILE *f)); AL_METHOD(int64_t, fi_ftell, (ALLEGRO_FILE *f)); AL_METHOD(bool, fi_fseek, (ALLEGRO_FILE *f, int64_t offset, int whence)); AL_METHOD(bool, fi_feof, (ALLEGRO_FILE *f)); AL_METHOD(int, fi_ferror, (ALLEGRO_FILE *f)); AL_METHOD(const char *, fi_ferrmsg, (ALLEGRO_FILE *f)); AL_METHOD(void, fi_fclearerr, (ALLEGRO_FILE *f)); AL_METHOD(int, fi_fungetc, (ALLEGRO_FILE *f, int c)); AL_METHOD(off_t, fi_fsize, (ALLEGRO_FILE *f)); } ALLEGRO_FILE_INTERFACE;
My vague idea would be
include std/ffi.e public constant ALLEGRO_FILE_INTERFACE = define_c_type({ C_STRING, --path C_STRING --mode }) OR --I feel like this wouldn't work, but its an idea I had. public constant ALLEGRO_FILE_INTERFACE = define_c_type({ atom x = define_c_proc(all,"+fi_open",{C_STRING,C_STRING}) public procedure fi_open(sequence path,sequence mode) c_proc(x,{path,mode}) end procedure })