From: Oliver Date: 2007-07-17T04:20:04+09:00 Subject: C library extension question hi, folks - I am working on a ruby extension for a C library, and having difficulty of figuring out how to deal with this structure and wrapping it nicely in Ruby. it is a command dispatch structure, where you supply an array of function pointers: /* command dispatch structure */ typedef int (*proxy_cmd)(int trans_id, int nargs, char **args); struct proxy_commands { int cmd_base; int cmd_size; proxy_cmd * cmd_funcs; }; typedef struct proxy_commands proxy_commands; /* end of definition */ Then, as a user you can define an array of function pointers like this: proxy_cmd cmds[] = { func_a, func_b, func_c, ... }; and fill in the structure: proxy_commands mytabs = { CMD_BASE; sizeof(cmds)/sizeof(proxy_cmd), cmds } An example of API will look like this: register(&mytabs, .... ) What is the best way of wrapping this in Ruby? >From end user perspective, I am thinking the interaction like this: def func_a ( ...) end def func_b( ...) end mytabs = [func_a, func_b] register(mytabs) If you have experience on writing C extensions, I'd appreciate your input. TIA Oliver