embedding: ruby vs. lua

S

Shea Martin

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
 
J

Jeremy Tregunna

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.
 
G

Giles Bowkett

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.
 
S

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++.

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
 
P

Phrogz

Shea said:
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.
 
J

James Edward Gray II

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.)

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

James Edward Gray II
 
K

Ken Allen

Shea said:
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
 
G

GD

Hey Shea,

Shea said:
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. :) I'm currently playing around with something similar
and personally would be very interested in the results.

Garth
 
W

William James

Shea said:
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.
 
S

Shot (Piotr Szotkowski)

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
 
S

Shea Martin

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



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.


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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top