From: "Alexandru E. Ungur" Date: 2007-01-11T22:16:14+09:00 Subject: Re: Sharing constants between C and Ruby code >>> sender: "Nathaniel Trellice" date: "Thu, Jan 11, 2007 at 09:01:50PM +0900" << Hello, > > I'm new to ruby, but fairly experienced in C. I am using Ruby on Rails > to chat to a postgres database. I have some C functions that I can run > in the database backend. I would like to use constants defined in C > header files, e.g "#define MY_CONSTANT 100" within ruby code. I know I > can similarly define a constant in ruby, i.e. "MY_CONSTANT=100", but > given that I have quite a few of these, and synchronising the two files > could become tricky, is there some (preferably simple) clever way/hack > that I can define constants in a single file and use them both in C and > in Ruby? Hello, I've had a similar problem to solve when I had a mixed PHP/Ruby project. I ended up using a separate file from both PHP and Ruby, like: 0 = some_constant 1 = some_other_constant etc. which was trivial to parse and turn into constants into either of them. It actually made the project cleaner to have the constants defined like that so I ended up putting all the constants there not just the common ones between PHP and Ruby scripts. Later, for parsing that same definitions file from C, I found a nice library: http://sbooth.org/ccl/index.html All the best, Alex