 Yeah, hi everyone, today I'm going to talk about M-Ruby. It's very nice to be here and talk about it for you because it's my first time here in Singapore and it's my first time here in Singapore Ruby Meetup. So yeah, let's start who I am. So I'm a full-time developer, mostly Rails and JavaScript. I'm working for Polish company Pilot.co, the Pilot.co remotely. And for that I'm traveling and cycling. This is my Twitter and github if anybody wants. And also I want to thank you Tinkerbox for hosting me in their office for two weeks, so yeah. Okay, so let's start with that. What is M-Ruby? Okay, it is the C-Ruby subset, which was created about two years ago, two or three. Yeah, it's supposed to be Lua alternative. The next thing is that it does not need Postics, it just needs C99, so it works for more platforms. It could be embedded in the C or C++ application. And it's mostly compatible with C-Ruby 2.1. It should work for the most cases. Okay, so let's start. So let's start with the M-Ruby 2 set, what we are getting after the installation of M-Ruby and what we can do with it. So yeah, this is what M-Ruby installs on our binary things which M-Ruby installs. MRBR, MRBC, MRDB, M-Ruby, M-Ruby Strip. Let's talk about each one. So yeah, MIRB is IRB for M-Ruby, like nothing special, just simple console. Yeah, MRBC. This is the nice thing because it let us compile the Ruby code into byte code. I hope you guys can see this. There's no problem with visible. So yeah, it's looking like that. We have the file test.rb, and it just puts OK. And we compile it with MRBC. And this is what we are getting, is how it's parsed with MRB. And this is what we are getting as our byte code. So basically what it says is OK, load self, then put string on top of everything, then send puts, and the puts is taking our OK string and stop applications. So basically that's all. There's another... There's a second example, which is like puts one, puts two. So as we can see, it's making pretty much the same thing. It's loading itself, then it's putting on top one, then adding two to it, and on the top we have three, and then we are sending puts. Yeah, basically that's all. We're also getting the MRDB. It's like MRB debugger, because we have to get some to debug, and basically that's how it's working. I hope it works. OK, this is when we compile the code and it's not having this optional flags for debugging. We cannot debug this kind of code. And when we cannot get debugging information, we have to add this minus g when we are compiling to the byte code. Yeah, this one. And this adds debugging information to our byte code. And then we can run our debugger. So what it gets like, we can get the lines, we can set breakpoints, we can have all some data, we can print some data, like normal debugger like gdb or something else. So we added here a breakpoint. We printed the value of the valve, it's like three. Then we evolved the value with 12. The add evolved, and now the value is 12. And when we continue the application, it will put us 12. This is the list. So when we try to continue our application, which was basically puts valve, it's put us 12 because we changed the value. OK. I don't know why I'm getting this white thing, I'm Ruby, I'm Ruby is like Ruby interpreter. So if you want to run this binary code, binary code, then we have to add minus b, and it will work. If not, just evolve it. OK. So what is the differences between Ruby and Ruby? OK. So firstly, we cannot require any file in Ruby, if we want to acquire an external jam or library, it has to be set in the config, not in our application. OK. We don't get any threads, so if you want to do some multi-processing, multi-thirds application, the M-Ruby won't work for this. There is like M-Ruby thread jam, but it's using the green threads, so it's not like system, but basically an app support, and we don't get native support of kernel sleep. OK. So how we can put our Ruby code into some embedded device, embedded code? OK. So Ruby is plus and c. OK. This is the basic example. So first of all, we start with this code which is shown on the top. Basically what it's doing is creating the Ruby context with M-Ruby state, and then we are evolving this code. It puts hello world one plus one in the context of state which we created, and then we are closing it. This is the command which compiles it, and when we run it, it's like running natively binary code, which we can push to the client. OK. So basically it was Ruby, but sometimes we want to use this bytecode feature and put this in the C. So how it will look like. First of all, we start with using MRBC, and we compile it with flag B, which creates us this binary test string hash, and then, yeah. OK. Then we create, same as the Ruby state, but instead of reading the string, we are reading this binary form of our code, and we start a new process with context which we created. So basically pretty much the same thing, and here it's supposed to be a code, but I don't know what we have here. This is why it's playing fresh pitch. Maybe try it. So this is how to compile it. Basically the same thing, and which we will get as output, we will get the binary thing, binary file which will work for us. So then when we have our process of development, we have to remember about that. We have to create, each time we're building our system new version, we have to create a new binary table with our Ruby code representation. OK. So how we can extend MRubio with gems. So this is the basic structure of the most basic gem I can imagine. It contains Ruby code and C code. So next. OK. It's MRbGem.reg file. The things, it's stolen from the documentation. It was easier. You just have to set license, auto and summary. This is the free basic stuff which we need. And then if we want to add dependency, we just do it that way. OK. So this is our Ruby code. If we want to add some Ruby code to our gem, we just put it in MRblib and it will be automatically added. OK. In SRC directory, we add our CRC++ code and how it's working basically. The most important two functions are this one and this one. The first one is saying what should happen after the gem is loaded. So in this case, we're creating new class, CRuby extension. And we are defining new method for this class. So as first we're getting our context, then we're getting this class, then we're saying what is the name, then we're setting what is the method and the last argument is saying how many arguments this function has. So for this case, it's zero. The next thing is final. Basically, if we want to destroy any objects or clean up what we created, we will be putting it here. And on the top, we have definition of our method. It's basically printing out the text. Nothing special. So that's all. It's like basic, basic gem. OK. So what are the examples of your M-Ruby? First of all, it's M-Ruby Web ERB. So it's pretty much working. It's wrought in JavaScript a little bit and mostly C, so it's compiled from the C to JavaScript and it's working full natively in the browser. Next thing is M-Ruby Arduino. So cool thing about this M-Ruby, we can install it on the R&M or different platforms. So it's not only for PC or Mac or different kinds of 64-bit architecture CPU, but it could run on different other. And this could be a great idea to introduce someone to the microcontrollers. Even not C, but given this Ruby interface of C, which is much, much more easier. We also have this Mobi Ruby. I know there's already working implementation of Ruby for iOS and Mac, but this is free one, an open source one. It's basically working as a M-Ruby wrapper over the Koka library. And here's some demo. If you go to the website, there's like source code of this. Pretty much a couple of lines. Okay, so if there's any questions about M-Ruby, yeah? Inside the gym you had the class definition and inside that the class definition is that itself a little bit a little bit? What? So back inside the gym you were showing us the Ruby example. Ruby or C code? Yeah? Why you got module C Ruby? I was like, there's another class. Yeah? It's not a class, it's just a module. Okay, anyone else? So thank you for your attention.