stillflame
Programmer
- Jan 12, 2001
- 416
i come from perl and ruby - high level scripting languages. there is an ability in both of them to construct a string and then evaluate that string as if it were code. i find myself now writing an extension for ruby in c and i have the following problem:
there are a bunch of functions in the API i'm wrapping with names like the following:
'parse_options_get_verbosity'
'parse_options_get_max_cost'
'parse_options_get_linkage_limit'
you get the point. so i'm creating a method which takes as its argument the last part of any of those ('verbosity', 'max_cost' or 'linkage_limit' in this case), and will then concatenate that onto the string 'parse_options_get_', but i'm writing it in c, since the function calls will all be in c, therefore i can't use eval...
my c skills are lacking, i admit to that readily. there may be a simple answer to this, but even so i don't know it, and couldn't find it searching through the forum here. the only thing i could come up with would be to make a separate ruby method for each of the numerous c functions, thus allowing me to do the eval in ruby (which i will end up doing if nothing else is brought forth), but i'm hoping for something better than that. i also really hope this is possible, but the inherent differences a compiled language has from those of my experience seems to be a fairly large barrier to this. in that case, this is really just me not fully accepting/understanding those differences yet.
just in case, let it be known that from ruby, it is impossible to make any direct c calls. i have to wrap every c fuction into something callable from ruby. i thought to try to eval it somehow first and then pass that to c, but it doesn't work.
thanks for any advice,
stillflame "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."
there are a bunch of functions in the API i'm wrapping with names like the following:
'parse_options_get_verbosity'
'parse_options_get_max_cost'
'parse_options_get_linkage_limit'
you get the point. so i'm creating a method which takes as its argument the last part of any of those ('verbosity', 'max_cost' or 'linkage_limit' in this case), and will then concatenate that onto the string 'parse_options_get_', but i'm writing it in c, since the function calls will all be in c, therefore i can't use eval...
my c skills are lacking, i admit to that readily. there may be a simple answer to this, but even so i don't know it, and couldn't find it searching through the forum here. the only thing i could come up with would be to make a separate ruby method for each of the numerous c functions, thus allowing me to do the eval in ruby (which i will end up doing if nothing else is brought forth), but i'm hoping for something better than that. i also really hope this is possible, but the inherent differences a compiled language has from those of my experience seems to be a fairly large barrier to this. in that case, this is really just me not fully accepting/understanding those differences yet.
just in case, let it be known that from ruby, it is impossible to make any direct c calls. i have to wrap every c fuction into something callable from ruby. i thought to try to eval it somehow first and then pass that to c, but it doesn't work.
thanks for any advice,
stillflame "If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito."