Re: wrapping C functions
- Posted by jimcbrown (admin) Feb 21, 2013
- 1520 views
ssallen said...
serialPrintf = link_c_proc(dll_ptr, "serialPrintf", {C_INT, C_POINTER, ...}) procedure euSerialPrintf(integer fd, atom message_ptr, ...) c_proc(serialPrintf, {fd, message_ptr, ...}) end procedure
That's not exactly right. serialPrintf is a vardic function, which isn't directly supported in Euphoria. Though you could do:
serialPrintStr = link_c_proc(dll_ptr, "serialPrintf", {C_INT, C_POINTER, C_POINTER}) procedure euSerialPrintStr(integer fd, sequence message, sequence string) atom message_ptr = allocate_string(message) atom string_ptr = allocate_string(string) c_proc(serialPrintStr, {fd, message_ptr, string_ptr}) free(message_ptr) free(string_ptr) end procedure serialPrintInt = link_c_proc(dll_ptr, "serialPrintf", {C_INT, C_POINTER, C_INT}) procedure euSerialPrintInt(integer fd, sequence message, atom int) atom message_ptr = allocate_string(message) c_proc(serialPrintInt, {fd, message_ptr, int}) free(message_ptr) end procedure
You'd need a new definition for each variation of serialPrintf() that you wanted to handle, though.