Hacker News new | past | comments | ask | show | jobs | submit login
mruby (github.com/mruby)
174 points by ryansama on April 20, 2012 | hide | past | favorite | 55 comments



Could anyone explain to me what the difference with normal ruby is?

"Lightweight", does that mean:

    Small but slow?
    Big but fast?
    Quite small and quite fast, but with a half-assed library?
    Big, slow, but low RAM usage?
I understand from another comment that this is intended for embedded systems. Does that mean running it on a microcontroller without OS? Cause the moment you can flash Linux, you can use Ruby MRI, no?


Yes, it would be nice to know what tradeoffs mruby makes and how they differ from the ones made by other ruby implementations


>I understand from another comment that this is intended for embedded systems.

Nope, he said embedding. He means things like Lua where you have a scripting language embedded in a program that is running on a faster lnaguage. Common in video game dev.

>Does that mean running it on a microcontroller without OS?

Nope, not necessarily. It being portable means it's plausible but it's an unlikely usage scenario. More likely, it means being able to use it across a variety of POSIX derivatives.

>Cause the moment you can flash Linux, you can use Ruby MRI, no?

Also not true. What a micro-distribution of Linux can run on is not necessarily something MRI Ruby can also run on.


Okok, I was wrong. Now, what's mruby for?


Think of it as a replacement for Lua. Something you will be able to include as a scripting subsytem in most other languages.


But LuaJIT 2 is insanely fast, even the Heavy / Fast Ruby isn't even anywhere near its speed. So why would one choose mRuby over Lua?


Heavy Ruby is not designed for speed, and much of its heaviness causes slowness. It's entirely possible/likely that mruby will be in the same ballpark as luajit2 soon after release.


LuaJIT 2 is fast because the Lua world has Mike, who is a genius.

That said, Lua is fucking weird.


I've been waiting this for a long time. There's also TinyRB (http://code.macournoyer.com/tinyrb/) but it's too small subset of ruby to be useful and seems abandoned.

But my first impressions are not very positive (stripped x86_64 executables with -Os):

  -rwxr-xr-x 1 user group 708480 Apr 20 11:27 mrbc
  -rwxr-xr-x 1 user group 713056 Apr 20 11:27 mruby
  -rwxr-xr-x 1 user group 712128 Apr 20 11:27 mrubysample
compared to lua-5.2.0:

  -rwxr-xr-x 1 user group 147864 Apr 20 11:28 lua
  -rwxr-xr-x 1 user group  99168 Apr 20 11:28 luac
I'm not a big fan of lua as a language but it has been the only option to do scripting on small embedded systems. I've manged to compile size-optimized version of lua on arm to the size of about 80kb but mruby just might be too big for my embedded usage.


Honestly, I'm pretty impressed it's only 7-10 times the size. Ruby is a comparatively huge language, and the compiled size will more likely get smaller than larger from here.


Lua "cheats" by leaving out regular expressions and including a lightweight (but still powerful) matching facility.


Plus, no unicode support. This needs lots of code to support properly. Does mruby include it?


Why aren't you a fan of lua? From what I've seen, it looks great.


Just a quick list of annoying things:

  - comments start with --
  - no bitwise operations in language
  - default numeric data type is floating-point. it's possible to change it to
    integer but it raises uncertainty with compatibility of external libraries
  - OOP in lua is quite programmer-specific: everyone seems to have their own
    best practises
Of course lua has good features too, like coroutines and good C API. Squirrel (http://squirrel-lang.org/) also seems like a nicer alternative to lua but it requires a C++ compiler.

IMHO lua's best asset is the small and fast VM. I wish there would be other good, modern languages that target it.


for the comments: that's a matter of taste, IMHO.

for bitwise ops: look at 5.2, it has it now. 32-bit operations.

floating point arithmetic: in practice, I haven't seen it as a problem as soon as I stay within the 32-bit range - then the numbers can be represented exactly, so the abstraction works well.

OOP: can't say for it, I did not do it much.

For the "fast" - check luajit (http://luajit.org/) - it is near-native speed while remaining reasonably slow.

And the FFI in luajit is simply fantastic. Take a look at https://github.com/justincormack/ljsyscall which binds the syscalls.

The annoyance that I'd thought of is that the array indexing starts with one, not zero - this brings some headaches during the index calculations. But this also forces to rethink the logic to use more of iterators, and abstract away from the indices. So, after all, it is not that big of a deal.


oh yeah, the array indexing starting with one is the one I forgot from my list!

I'm developing for an arm processor with no floating point support. so it's best to avoid the software fallback at all costs.

I'm aware of luajit but "plain" lua is still fast enough for my uses. FFI is definitely a killer and beats SWIG hands down.

need to upgrade to 5.2 asap...


Oh on arm you will definitely will want to check out luajit precisely for the number performance - see this comment for details : http://news.ycombinator.com/item?id=2617835 - luajit will use integers where it can.

I did not experiment with this myself though, but hopefully it might ease your woes with no FPU - http://luajit.org/performance_arm.html shows 85x speedup for md5, which I suppose would be integer algorithm.

Out of curiosity, what is the platform, if not a secret ?


    -- Comment syntax is that a big deal?
    - bit wise: LuaJIT?
    - Just like in Python and Javascript, what's the issue?
      Doubles do just fine as integers if you code so that 
      you always wind up with other integers.
    - OOP - This I agree is a community fragmentation issue.


One issue is that it's easy to end up with things that aren't round numbers by mistake (if you do any sort of division, for example, or are getting results from an external library, etc., and strategies for reducing errors that rely on the programmer not screwing up are generally doomed to failure.) That has several problems: floats are imprecise, you introduce the potential for additional runtime errors if you're doing something like indexing into an array, etc.

Also, Python has separate integer and floating-point operations:

    >>> type(1)
    <type 'int'>
    >>> type(1.0)
    <type 'float'>


The GP mentioned arbitrary precision integers, which Python has. I believe they're called Long, and integers that overflow are cast to Long (represented as 123L).


What? No mention of indexing starting at 1, not 0? :)

I just started doing some Lua coding. So far nothing really off-putting, just a need to watch for habits picked up form other languages.

Biggest complaint is the lack of metaprogramming (e.g eval).


Agree strongly about the floating point being a problem. I much prefer languages like Erlang, Python, and Ruby where the default numeric type is arbitrary precision integers.


I see, thank you. None of this sounds like a show-stopper to me, but it's good to have a more complete view of a language I'm not intimately familiar with.


Yes, none are show stoppers. Lua suits perfectly for for the use it was designed: small embeddable scripting. I hope no one is writing millions of lines of lua code! For me even small amount just does not "feel right" the way for example ruby does. That's why I've been eagerly waiting for mruby but unfortunately it does not (yet) fill the void.


FYI: LuaJit comes with bitwise operations AFAIK. http://bitop.luajit.org/


I will release MobiRuby that's mRuby + iOS. http://mobiruby.org/


Would really love to see something like this.


Wow.. looks really clean


Looks great!


was Ruboto inspiration?


sounds awesome!


I am seeing this sort of thing frequently in GitHub - people start working on something and it gets "released" before they are ready with it and the authors have to scramble to say that this is not ready, ward off degrading comments etc.

The js.js blog post mentions this and in mrbuy , the README has just been updated. Is social coding being taken to the extreme?


Why don't they use something like bitbucket (free private repos) until it is ready to be launched?


I seriously doubt that whether the repositories were private was a financial consideration. More likely, they wanted others to be able to find the project and join in.

People who develop software of this caliber can easily afford the expense of a private Github repository if they want one.


>mRuby is the light-weighted implementation of ruby language complied with ISO standard to execute various environment. It can run as 'interpreter form' or 'compile and execute on vm form' according to its module construction.

Can anyone tell me how it's different from other ruby implementations? What does 'execute various environment' mean? Can I run it inside JVM like JRuby?



Is RiteVM related? The reddit faq mentions both embedded systems and embedding via C API, I don't know which is the goal of that project. (sorry if that was covered in the talk, I'd rather not watch youtube right now)



Matz talked about this in RubyConfIndia in March. Glad that it is here finally.


When I visit http://www.mruby.org Google translate tells me, "This domain has been captured by. Com name."

As an aside, this sent me on a little adventure to http://www.mruby.com which is ... quite a treat.


The domain registrar is basically "Name.com" in Japanese. Google translate often fails hard on Japanese to English.


And Onamae.com is one of the best registrars that we have here (for all its issues)


matz own mruby.org. and its page is under construction. matz said I pushed source code only, I'll build web site and docs later.


www.mruby.com

Matt Ruby, Comedian, writer, and 37signals’ first employee.

Probably not a coincidence.


Here's a blog post on using mruby as embedded language in a nosql database (AvocadoDB), like Lua within Redis.

http://www.avocadodb.org/2012/04/20/using-mruby-as-alternati...


Great job, i have been wondering ruby as an embedding/portable small language for a long time.


I am a big Ruby fan but I don't really see how this is enough of an improvement over Lua to pose a serious threat.


Depends on the audience. There are probably lots of people who know Ruby and would like to be able to use it where they currently can't. It might not be likely to win the hearts of the C++ game engine hackers, but that might not necessarily be the goal.


I thought the hivemind was that Lua was bloody awful?

Disclaimer: I have never even read some Lua, honest question


It's not elegant but it's incredibly compact and isolated. I embedded it as a language in an iPhone game (as have many others). Making it bridge with Objective-C was fairly straight-forward and the memory/speed footprint was acceptable for a mobile device.


I find it elegant. It's like Javascript with the warts removed.


It's like JavaScript with different warts. Examples: Bad at Unicode, arrays start at 1, regexps is a second-class citizen, weird OO, arrays are implemented as hash tables (like PHP), hash tables are weird, no int type, Java-like inflexibility wrt extensibility (no generalization for iteration, for example) etc.


Yeah, it's not bad. Though having array indices begin with 1 annoys me.


I've only dabbled a bit in Lua but I mostly read very positive things about it and there are tons of success stories of embedded Lua out there. Way more than any other embedded scripting language. Unlike Ruby or Python etc Lua was designed from the ground up for this.


As others have said, it is small, fast and flexible with a very permissive licence so it is the scripting language of choice for embedded and gaming applications.




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: