From: emilie3012@... (Steve Hart) Date: 2003-04-14T11:16:08+09:00 Subject: Re: using ruby reflection to generate code ptkwt@shell1.aracnet.com (Phil Tomson) wrote in message news:... > In article <20030413004111.A80880@beaver.net>, > Doug Beaver wrote: > >hello, > > > >i'm curious if anyone out there is using ruby reflection to generate > >code for other languages. i love using ruby to prototype classes and > >their interactions, especially if i can't decide on a design and need to > >try a few different implementations. i'm writing lots of c++ and > >objective c these days, and it's much harder to turn around and quickly > >refactor class designs. > > > >has anyone tried using ruby's reflection to prototype classes in ruby > >and then render the class structure to other languages? i've started > >working along these lines so that i can call #render_objc on any object > >and get back two big strings, one for the header and one for the source. > >i use reflection to pull out instance variables and check their type, so > >a ruby array turns into a NSMutableArray *, hash to NSMutableDictionary > >*, etc, etc. i just look at variables, classes and methods with > >reflection, i don't parse the ruby code or try to do anything smart with > >it yet. the methods in the target language are just stubs. > > > >eventually, i would like to take the ruby code inside my methods and > >stick that as a comment inside the generated methods in my target > >language. then i can use ruby for RAD and generate stubs in my target > >language along with ruby code in comments so i can remember what each > >method was supposed to do. then i can move through the methods, porting > >the ruby code to my target language and getting a finished product more > >quickly. > > > >anyone else going down this road? perhaps you have some advice or > >pointers to examples you've found? i'm not sure it's going to work > >100%, but i'm hoping it will allow me to save time. if anyone's > >interested, i can post code once i fix some bugs and clean it up. if i > >get something useful, i'm going to try this for c++ and perl as well. > > > >thanks, > > > >doug > > I'm not currently doing this, but I do kind of want to be able to convert > RHDL to VHDL and/or Verilog which would entail some similar effort > (actually, it would probalby be harder). > > At any rate, I really would be interested in seeing your code to generate > objective C and/or C++, can you post this or submit it to the RAA? > > Phil Hi, I'm using Ruby as a scripting tool for an OpenGL app, Would it be (theroertically) possible to use reflection to 'reconstruct' the original ruby script. The reason I ask is that I use rb_load() to initialise a Scenegraph within my app. The user can then change the Scenegraph which I then need to save out again as an updated script. Has anyone done something similar?