2 ms·
Good question. I'm going to try to answer it for embedding a scripting language into your existing code base. I'm going to presume that your code base is writt
by Derbasti 15y ago
Good question. I'm going to try to answer it for embedding a scripting language into your existing code base.
I'm going to presume that your code base is written in something relatively low-level because otherwise you would not need to embed a scripting language. Hence, your application probably has some performance demands. Obviously you expect your scripting system to be slower, but not dog slow. While Lua is quite a bit faster than Ruby, both are orders of magnitude slower than C code, so I don't really see this as a problem in most cases.
Common tasks for an embedded language might be configuring some part of your application. For that, the embedded language does not need to be particularly fast or small. It only needs to have convenient ways of creating data structures and a simple C-API. I would wager that the C API of Lua is about as simple as it gets and it is absolutely trivial to embed it into your program. I would say that Ruby needs to catch up a bit to be useful here.
Another typical application is to write non performance-critical but complicated code in a nicer language. This usually evolves pretty quickly into some kind of specialized DSL. Hence, you need a language with rich metaprogramming capabilities. In my limited experience with metaprogramming in Ruby I have found it to be amazingly powerful (if somewhat hard to grasp). On the other hand, I would say that the absence of a built-in object system in Lua does count as a benefit here, since rolling your own hand-tailored object system that perfectly suits your DSL needs is relatively simple. In the end though, many more people know Ruby syntax than Lua syntax, so I could see a future for Ruby here.
Still, I don't really see Ruby and Lua in the same ballpark here. Lua is designed from ground up for embedding. As a result it is really fast, very small and extremely easy to embed.
Ruby is a proper general-purpose programming language in its own right. Even though mruby is going quite far to make it small and simple, it will never compete with something that was purposely built for that. On the other hand, Lua will never compete with Ruby in terms of library support and rich syntax.