Embedding: ruby vs. lua

I need an embedded scripting language.

Lua was the first one that jumped into my head, even though I know very
little about the language, other than the fact that games often embed it.

I work with C++, but ruby is my language of choice. So I would prefer
to embed ruby, as I just like the language in general.

The main consideration, is that the embedded interpreter be very
lightweight, and fast.

API richness would not really be an issue, as most lot of the functionality of the scripts would come from the C++ the vm interpreter was embedded in.

When it comes to embedding 'Io' sounds great. But the syntax looks like ass...

Thought? tips?

~S

I tried to send this offlist, but it failed, so my apologies if some might consider this off-topic.

When it comes to embedding 'Io' sounds great. But the syntax looks like ass...

I understand it might not be what you're after, and that's fine; but you can bend and twist Io's syntax to fit whatever kind of syntax you want. For instance, you can give Io a C syntax in very few lines of code (admittingly, not the best way to do it) but: http://blurgle.blogspot.com/2006/09/fun-with-c-dsl.html

I've created several shim DSLs using nothing but more Io message manipulation for many common languages (some more completely than others) including (but not limited to): C, LISP, Objective-C and my own language.

Food for thought.

···

On 18-Jan-07, at 2:10 PM, Shea Martin wrote:

--
Jeremy Tregunna
jtregunna@blurgle.ca

I need an embedded scripting language.

Lua was the first one that jumped into my head, even though I know very
little about the language, other than the fact that games often embed it.

I'm probably going to learn Lua for World of Warcraft at some point,
but I really don't know anything about it yet. I know there's
something called RubyInline which is very well-regarded, but I'm
almost certain it does C inline Ruby, not Ruby inline C. I could be
wrong.

···

--
Giles Bowkett
http://www.gilesgoatboy.org

http://gilesgoatboy.blogspot.com

I am in the process of writing a minimal C++ program, which would do the sort of things I will be doing for my project. Then I am going to write a benchmark script in Lua, Ruby, Io, and maybe others, and bindings to my C++.

This will give me good idea of how syntacticly nice the it is to create bindings. I will eliminate anything that is a bitch to work with.

Then run the benchmarks.

If ruby is competitive, I will use it, as I prefer it. Otherwise I will choose the smallest/fastest/easiest....

If there is interest here, I will post my results back.

~S

Shea Martin wrote:

Lua was the first one that jumped into my head, even though I know very
little about the language, other than the fact that games often embed it.

I use Lua almost daily in my work, and have written moderate-sized
libraries with it.

Things that are great about Lua, in my opinion:
* It's really small, and really fast.
* It's easy to embed, and designed that way.
* It has strong, dynamic typed variables, and first-class functions,
and automatic (now incremental) garbage collection.
* The language itself is REALLY simple and elegant; you can learn it
in a few days, and nearly master it in a week.
* It is an entirely procedural, not object-oriented language...and yet
a tiny, simple bit of syntax sugar and a few powerful metaevents can
make it look like OOP for simple tasks, and it's easy to write your own
fully-OOP framework.
* It's crazy portable to a lot of platforms.
* You can compile code to bytecode and load bytecode in directly.
* A recent addition called token filters (that I don't fully
understand) allow you to easily extend the language to support near
arbitrary syntax additions that you want.

Things that make Lua not nearly as cool as Ruby, in my opinion:
* The core library of functionality is extremely limited. (No IO. No
time or date objects. No XML. Limited pattern matching.)
* Verbose syntax. ("function" instead of "def" makes lambdas
inconvenient. "then" with every "if" statement. Not only no ++, but no
+= either.) The amount of typing just to accomplish a simple task makes
me feel like I'm working with a low-level language like C, not a high
level scripting language.

Lua is so clean and elegant at the core that I have to love it. I
enjoyed writing my own OOP wrapper that mimics Ruby's hierarchy (though
I decided not to add modules or 'super' calls, it's absolutely
possible). But programming in it generally feels like I'm working to
figure out how to make Lua do what I want, whereas Ruby enables me to
do it.

Shea Martin wrote:

I need an embedded scripting language.

Lua was the first one that jumped into my head, even though I know very
little about the language, other than the fact that games often embed it.

I work with C++, but ruby is my language of choice. So I would prefer
to embed ruby, as I just like the language in general.

The main consideration, is that the embedded interpreter be very
lightweight, and fast.

API richness would not really be an issue, as most lot of the functionality of the scripts would come from the C++ the vm interpreter was embedded in.

When it comes to embedding 'Io' sounds great. But the syntax looks like ass...

Thought? tips?

~S

If you are looking at lua and c++ be sure to check out luabind, it makes connecting c++ functions, classes, etc to lua MUCH easier.

http://www.rasterbar.com/products/luabind.html

It needs boost to build, which is a massive dependecy to tack onto your project, but I think it's worth it for the ease of use you gain.

Ken

* No bitwise operations without a library when last I looked. That one really hurt my ability to use it.

James Edward Gray II

···

On Jan 18, 2007, at 2:50 PM, Phrogz wrote:

Things that make Lua not nearly as cool as Ruby, in my opinion:
* The core library of functionality is extremely limited. (No IO. No
time or date objects. No XML. Limited pattern matching.)

Hey Shea,

Shea Martin wrote:

I am in the process of writing a minimal C++ program, which would do the sort of things I will be doing for my project. Then I am going to write a benchmark script in Lua, Ruby, Io, and maybe others, and bindings to my C++.

This will give me good idea of how syntacticly nice the it is to create bindings. I will eliminate anything that is a bitch to work with.

Then run the benchmarks.

If ruby is competitive, I will use it, as I prefer it. Otherwise I will choose the smallest/fastest/easiest....

If there is interest here, I will post my results back.

Please do. :slight_smile: I'm currently playing around with something similar
and personally would be very interested in the results.

Garth

Shea Martin wrote:

I am in the process of writing a minimal C++ program, which would do the
sort of things I will be doing for my project. Then I am going to write
a benchmark script in Lua, Ruby, Io, and maybe others, and bindings to
my C++.

Be sure to try LuaJIT.

Shea Martin:

I am in the process of writing a minimal C++ program, which would do
the sort of things I will be doing for my project. Then I am going
to write a benchmark script in Lua, Ruby, Io, and maybe others, and
bindings to my C++.

If there is interest here, I will post my results back.

Please do!

-- Shot

···

--
You can safely assume that you've created God in your own image when it
turns out that God hates all the same people you do. -- Anne Lamott

Jeremy Tregunna wrote:

I tried to send this offlist, but it failed, so my apologies if some might consider this off-topic.

When it comes to embedding 'Io' sounds great. But the syntax looks like ass...

I understand it might not be what you're after, and that's fine; but you can bend and twist Io's syntax to fit whatever kind of syntax you want. For instance, you can give Io a C syntax in very few lines of code (admittingly, not the best way to do it) but: http://blurgle.blogspot.com/2006/09/fun-with-c-dsl.html

I've created several shim DSLs using nothing but more Io message manipulation for many common languages (some more completely than others) including (but not limited to): C, LISP, Objective-C and my own language.

Food for thought.

--
Jeremy Tregunna
jtregunna@blurgle.ca

I have embedded lua, and ruby, and run some benchmarks which basically launch a script in the interpreter; the script manipulates objects in on the C side.

Lua looks to be 3x as fast, and use 1/3 the memory. But unless all you care about is performance, it is a lot more work to embed. Roughly about double the amount of code for writing my interface to Lua, versus my interface to Ruby.

I had discounted Io, but after seeing Ruby's performance, and being annoyed with Lua, am much more open to Io. Have embedded lua before? How does it compare to Io? Do you have to manually manage the stack, etc?

Thanks,

~S

···

On 18-Jan-07, at 2:10 PM, Shea Martin wrote: