Skip to content

Commit 36a8a4b

Browse files
committed
Merge pull request #23 from bovi/article-adjustment
Article adjustment
2 parents 1cd6a14 + 527ec36 commit 36a8a4b

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

docs/articles/executing-ruby-code-with-mruby.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ an advanced updating mechanism
115115
## Bytecode (.mrb)
116116
117117
mruby provides a Java-like execution style by compiling to an
118-
intermediate representation form which then will be executed.
118+
intermediate representation form which will then be executed.
119119
120-
The first step is to compile source code to bytecode with the `mrbc` program:
120+
The first step is to compile the source code to bytecode with the `mrbc` program:
121121
122122
~~~
123123
$ mruby/bin/mrbc test_program.rb
@@ -139,7 +139,7 @@ $ hexdump -C test_program.mrb
139139
~~~
140140
141141
This file can be executed by the `mruby` program or the `mrb_load_irep_file()`
142-
function. The `-b` switch tells the program that the file is binary rather than
142+
function. The `-b` switch tells the program that the file is bytecode rather than
143143
plain Ruby code:
144144
145145
~~~
@@ -153,7 +153,7 @@ hello world
153153
154154
✔ no Ruby code has to be parsed
155155
156-
✔ bytecode can easily be updated by replacing the file
156+
✔ bytecode can easily be updated by replacing the .mrb file
157157
158158
✘ complex development cycle:
159159
programming → compiling (`mrbc`) → testing (`mruby`) → programming
@@ -196,8 +196,7 @@ test_symbol[] = {
196196
};
197197
~~~
198198

199-
To execute this bytecode the following boilerplate has to be written.
200-
It reads the array and executes the bytecode immediately:
199+
To execute this bytecode the following boilerplate has to be written:
201200

202201
~~~c
203202
#include "mruby.h"
@@ -213,6 +212,8 @@ main(void)
213212
}
214213
~~~
215214
215+
This will read the bytecode from the array and executes it immediately:
216+
216217
To compile and link:
217218
218219
~~~
@@ -242,3 +243,16 @@ integrating C code → compiling (`gcc`) → testing → programming
242243
243244
✘ updating the bytecode requires a recompilation of the C code or
244245
an advanced updating mechanism
246+
247+
## Fazit
248+
249+
The **REPL (mirb)** is mainly used during the early development.
250+
**Source code (.rb)** is the most common usage of mruby these
251+
days as it emphasises Ruby as a scripting language which can easily be
252+
modified by changing the source code on the machine. **Source code (.c)**
253+
is the easiest step to embed mruby into your own application.
254+
**Bytecode (.mrb)** provides the feeling of a Java application, which can
255+
be file based installed but doesn't provide access to the source code.
256+
**Bytecode (.c)** is quite likely for many people the most complex way to
257+
use mruby but at the same time it provides the most efficient way to
258+
execute mruby code inside of program.

0 commit comments

Comments
 (0)