On Aug 28, 4:44 pm, chris_the_frog <[email protected]> wrote:
> Hi! I am a computer science student and I have a problem I just can't
> seem to find an answer to. I would like to embed a read-eval-print-
> loop in a website. Essentially, I'd like a window that mimics a
> console: the user types in some random text, it is processed, a value
> is returned and displayed, and then it waits for the user's input
> again*.  Exactly like a console.
>
> I am new to Ruby and I have only just begun looking at Rails. In fact,
> I have absolutely no experience in web programming whatever. So even
> if someone could just point me in the right direction, I'd appreciate
> it.
>
> * FYI, I am trying to create an online version of my research project:
> an interpreter and interactive environment for a small functional
> language.

I can't imagine Rails offering any aid in this endeavour; if you're
just taking user input to pass to a custom language interpreter, a
basic CGI script will do quite nicely (or maybe if you absolutely want
to get the lightweight stuff out of the way a much smaller framework
like Camping or Sinatra). Let me ask, do you already have your
language written? If so, I presume you used something other than Ruby,
so I'd probably be easiest to just write the web REPL in the used
language and pass the user's input as a string to to your interpreters
routines. Otherwise, using Ruby to call your language's interpreter
executable safely may prove difficult, as the easiest way to capture
output of an external command (backticks ` or %x{}) could make it
extremely difficult to sanitize input, and I know of no way to
redirect the output of the multi-argument version of Kernel#system
(which bypasses shell escaping). Eitherway, if anything malicious *is*
possible with your language, you'll first need to create a sandboxed
version of your interpreter before even considering building a web
frontend.

For just learning how to write a CGI script with Ruby though, the
standard documentation itself is quite explanatory (http://www.ruby-
doc.org/stdlib/libdoc/cgi/rdoc/classes/CGI.html), and most frameworks
come with fantatsic documentation as well (hell, the text on www.sinatrarb.com
home page really is all you need for a working Sinatra app).
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to