I wrote a tool a while back I called rubypp (pp as in preprocessor),
which lets you do something like this:
#include <iostream>
#ruby <<END
puts '#define FOO BAR'
'#define BAR BAZ'
END
#ruby def foo(x) ; \
x.to_s.chop ; \
end
extern "C" {
int foo(int a) {
std::cout << "1" << std::endl;
}
int foo(double a) {
std::cout << "2" << std::endl;
}
main() {
foo(1);
foo(1.0);
std::cout << "#{foo(1.0)}" << std::endl;
}
which produces this output:
#include <iostream>
#define FOO BAR
#define BAR BAZ
extern "C" {
int foo(int a) {
std::cout << "1" << std::endl;
}
int foo(double a) {
std::cout << "2" << std::endl;
}
main() {
foo(1);
foo(1.0);
std::cout << "1." << std::endl;
}
The syntax is a little odd, but it's surprisingly powerful. I use it to
generate code for nodewrap. You can find it at:
http://rubystuff.org/rubypp/rubypp.rb
Paul