Ruby: looking for ruby-embeddable interpreter or scripting language
FWIW, I ended up tweaking a version of stickup to use as a embeddable interpreter. The process was fast and easy and serves my needs well. (And besides, I used to work for a Common Lisp company, so it was an excuse to re-live the joys of s-expressions.)
Ruby sandboxing vs. integrating a scripting language
You might consider using the Shikashi gem, which allows you to create sandboxes and define a whitelist of allowed method calls on individual objects.
How to embed Ruby in C++?
swig is probablly the way to go..... but ruby doesnt embed too well......
if you want a language that embeds nicely into C++, try lua
Can I script a C++ application with Ruby like with Lua?
Yes, you can. You just need to embed a Ruby engine in your application.
Note that, unlike the main Lua engine, some Ruby engines aren't really that well suited to being embedded into other programs. But, for example, Rubinius, IronRuby and JRuby have been specifically designed with embedding in mind, and even though it isn't pretty, you can embed YARV or MRI as well, even though they are not designed for it.
There's also MRuby, but unlike the others, it doesn't implement the full Ruby Language Specification, it only implements a subset of the ISO Ruby Specification which itself is only a small subset of the intersection of Ruby 1.8 and Ruby 1.9. Plus, it hasn't been released yet, as is evidenced by the fact that not even its homepage exists yet. It is, however, specifically designed for embedding, in both senses of the word: being embedded into other programs, and being useful on an embedded device with very little RAM.
As you may have noticed, it is much easier to embed Ruby into your app if the app is running on the Java platform or the CLI. There are C++ compilers for both the Java platform and the CLI, so that option is not entirely out of the question. Otherwise, I'd say that Rubinius is easier to embed, but more people have tried embedding YARV, so there are more blog posts about how to do that. (Or maybe, embedding Rubinius is so trivial nobody needs to write blog posts about it.)
A long time ago, someone was working on an implementation of Ruby for the Lua VM, but that implementation never went anywhere. Would solve all your problems, though :-)
Ruby vs Lua as scripting language for C++
I've used Lua extensively in the past.
Luabind is really easy to use, there is no need for an external generator like SWIG, the doc is great. Compile times remain decent.
Biggest problem I've seen : lua is mostly ... write-only. You don't really have classes, but only associative arrays with a bit of syntaxic sugar ( object['key'] can be written object.key ), so you easily end up adding a 'member' in an obscure function, completely forget about it, and have side effects later.
For this reason, and this reason only, I'd prefer Python. Boost::Python is the basis for Luabind so both have a similar API (Luabind used to be slightly easier to build but not anymore). In terms of functionality, they are quite equivalent.
Not directly related : None of these can be reliably used in a multithreaded environment (so this depends on the complexity of your server).
- N Python threads : the GIL ( Global Interpreter Lock ) is on your way. Each and every time you use a variable in a thread, it's locked, so it kinda ruins the point, except for long I/O operations and calls to C functions.
- lua has coroutines, but they aren't parallelisable.
- Ruby threads aren't really threads, but similar to Lua's coroutines
Note that you can still create one environement for each thread, but they won't be able to communicate (except with a C++ machinery). This is especially easy in Lua.
Real and non-embedded use of Ruby, Python and their friends
Python (combined with PyQt) is a very solid combination for GUI desktop applications (note that while QT is LGPL, PyQt (the Python bindings) is dual licensed: GPL or commercial).
It offers the same (GUI library-wise) as Qt on C++ but with Python's specific strenghts. I'll list some of the more obvious ones:
- rapid prototyping
- extremely readable (hence maintainable) code
Should I stick with C(++) for desktop apps?
In general: no, unless you want to / need to (for a specific reason).
Is Ruby really an interpreted language if all of its implementations are compiled into bytecode?
Yes, Ruby's still an interpreted language, or more precisely, Matz's Ruby Interpreter (MRI), which is what people usually talk about when they talk about Ruby, is still an interpreter. The compilation step is simply there to reduce the code to something that's faster to execute than interpreting and reinterpreting the same code time after time.
Related Topics
Undefined Method Error When Creating Delayed_Job Workers with Script/Delay_Job
Regular Expression to Match Only the First File in a Rar File Set
Ruby String Split into Words Ignoring All Special Characters: Simpler Query
How to Implement Editing/Formating Text Area in Rails
How to Link to a Page with Page.Url Without the HTML Extension in Jekyll
Initializing a Hash with Empty Array Unexpected Behaviour
How to Http Post Stream Data from Memory in Ruby
Disabling Irb Autocomplete on Heroku
Openssl::Ssl::Sslcontext Sni Servername_Cb Not Working
Capture Webcam's Image with Ruby
Config Undefined in Environment Specific Configuration Files
How to Reset Boolean to "Default: False" at End of Day
Open Xml File with Nokogiri Update Node and Save
How to Run Rails App in a Completely Isolated Instances of Chrome
What Is an Eoferror in Ruby File I/O
Wicked_Pdf Is Not Rendering Header
Ruby Syntax Question: Rational(A, B) and Rational.New!(A, B)