From: Logan Capaldo Date: 2006-08-02T12:55:46+09:00 Subject: Re: Embedded Ruby Question On Aug 1, 2006, at 9:28 PM, Brian Campbell wrote: > Hi Timothy, > > Thanks for the reply! > > Yes, I have the Pickaxe 2. Unfortunately, it doesn't describe/ > document, what I need to do. It describes how to embed the > interpreter, call/execute Ruby from an existing file, extend Ruby > via C/C++, but it does not describe how to pass a string that is > Ruby code from C++ to the interpreter and have it execute. That's > what I need. > > Thanks. > One of the best sources of documentation for C extensions is README.EXT in the source distribution. Here is the relevant section for what you want to do: 2.2.1 Evaluate Ruby Programs in a String The easiest way to use Ruby's functionality from a C program is to evaluate the string as Ruby program. This function will do the job. VALUE rb_eval_string(const char *str) Evaluation is done under the current context, thus current local variables of the innermost method (which is defined by Ruby) can be accessed. > -Brian > > -------------------- > Brian E Campbell > becampbel@hotmail.com > > > > >> From: "Timothy Goddard" >> Reply-To: ruby-talk@ruby-lang.org >> To: ruby-talk@ruby-lang.org (ruby-talk ML) >> Subject: Re: Embedded Ruby Question >> Date: Wed, 2 Aug 2006 09:50:10 +0900 >> >> There's a good section on embedding Ruby in the Pickaxe 2. You >> have to >> be extremely careful with some aspects of it, especially if you use >> threads (the Ruby interpreter is not currently thread safe). >> >> Brian Campbell wrote: >> > Hi all, >> > >> > I want to embed Ruby in my C++ application. I'd like to read >> one or more >> > Ruby scripts stored in my RDBMS, pass the Ruby script as a >> string (not a >> > file name) to the interpreter, and have it execute the code. Is >> this >> > possible? If so, is there a URL that describes how to do this >> or shows an >> > example? >> > >> > Thanks! >> > >> > -Brian >> > >> > -------------------- >> > Brian E Campbell >> > becampbel@hotmail.com >> >> > > >