home shape

Towards an Interactive mruby Shell | ArangoDB Blog 2012

In my last post I investigated the possibility of using mruby as embedded language for AvocadoDB. As the first results look quite promising I decided to write a small interactive mruby shell. There is no better way to explore a new toy than to play with it.

(Un)fortunately “irb” from Ruby is written in Ruby itself, so one cannot just use it for mruby. So, instead I had to write a small C++ program using “readline” and the compile/execute functions from mruby. In order to implement a Read-Eval-Print-Loop, well, one needs the print. That in itself is more complicated than expected, see the discussion on github. So, a Read-Eval-Loop will have to do for the time being. In order to find out when a definition is finished I had to do a small patch to the mruby parser. So, if things break down horribly do not blame the mruby developers – it might be entirely my fault.

fceller@opensuse114:~/AvocadoDB-MASTER> ./avocirb 
                        _      _      
   __ ___   _____   ___(_)_ __| |__   
  / _` \ \ / / _ \ / __| | '__| '_ \  
 | (_| |\ V / (_) | (__| | |  | |_) | 
  \__,_| \_/ \___/ \___|_|_|  |_.__/  
                                      
Welcome to avocirb 0.3.12. Copyright (c) 2012 triAGENS GmbH.
Using MRUBY 0.0.0 engine. Copyright (c) 2012 mruby developers.
Using READLINE 6.1.

avocmrb> p 1 + 2
3
avocmrb> def hallo
.......>   p "Hallo World"
.......>   return 10
.......> end
avocmrb> $i = hallo
"Hallo World"
avocmrb> p $i
10

The source-code can be found on github. Please keep in mind that this is a snapshot of the mruby repository with modifications. Do not blame the mruby developers.

In case you are using homebrew, you can install it as follows:

fceller@kendenich:~> brew uninstall avocadodb
Uninstalling /usr/local/Cellar/avocadodb/HEAD...
fceller@kendenich:~> brew install --HEAD avocadodb
==> Installing avocadodb
...
fceller@kendenich:~> avocirb 
                        _      _      
   __ ___   _____   ___(_)_ __| |__   
  / _` \ \ / / _ \ / __| | '__| '_ \  
 | (_| |\ V / (_) | (__| | |  | |_) | 
  \__,_| \_/ \___/ \___|_|_|  |_.__/  
                                      
Welcome to avocirb 0.3.12. Copyright (c) 2012 triAGENS GmbH.
Using MRUBY 0.0.0 engine. Copyright (c) 2012 mruby developers.
Using READLINE 0x0402.hex.

avocirb> p "Hallo, my name is mruby"
"Hallo, my name is mruby"
avocirb> 

Again, this is currently just experimental program to play around with mruby. Still, I’ve you have any remarks or improvments, let me know.

Author

  • Frank Celler

    Frank is both entrepreneur and backend developer, developing mostly memory databases for two decades. He is the CTO and co-founder of ArangoDB. Try to challenge Frank asking him questions on C, C++ and MRuby. Besides Frank organizes Cologne’s NoSQL group & is an active member of NoSQL community.

Frank Celler

Frank Celler

Frank is both entrepreneur and backend developer, developing mostly memory databases for two decades. He is the CTO and co-founder of ArangoDB. Try to challenge Frank asking him questions on C, C++ and MRuby. Besides Frank organizes Cologne’s NoSQL group & is an active member of NoSQL community.

1 Comments

  1. Patrick Mulder on November 19 2012, at 2:04 pm

    Very nice!

    How would I access the db/collections with mruby?
    Also, maybe it would be nice to provide a built-in help class with some background on the possible default methods in the shell?

Leave a Comment





Get the latest tutorials, blog posts and news: