https://github.com/chadowo/mruby-examples
Collection of sample MRuby programs
https://github.com/chadowo/mruby-examples
c example-code examples mruby ruby sample-code samples
Last synced: about 1 month ago
JSON representation
Collection of sample MRuby programs
- Host: GitHub
- URL: https://github.com/chadowo/mruby-examples
- Owner: chadowo
- License: mit
- Created: 2023-08-12T20:58:18.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2026-02-24T04:26:44.000Z (3 months ago)
- Last Synced: 2026-02-24T10:29:08.126Z (3 months ago)
- Topics: c, example-code, examples, mruby, ruby, sample-code, samples
- Language: C
- Homepage:
- Size: 104 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MRuby Examples

Collection of sample [MRuby](https://mruby.org/) programs.
## Build
### Get MRuby
Make sure you've got MRuby installed, see [here](https://github.com/mruby/mruby#how-to-get-mruby).
> [!TIP]
> If you are on Linux chances are MRuby is already in the package repositories of your favorite distro! then you'll need to use your distro specific package manager to install it. E.g:
APT:
```console
sudo apt install libmruby-dev
```
DNF:
```console
sudo dnf install mruby-devel
```
Pacman:
```console
sudo pacman -S mruby
```
### Other requirements
Some examples require SDL2. Install it:
```console
$ sudo apt install libsdl2-dev
```
or
```
$ sudo dnf install SDL2-devel
```
### Compiling
Use the followings commands:
```console
cmake -S . -B build
cmake --build build
```
## Summary
Examples included here:
### Basic
| Example | Description |
|:---------------------------------------------:| --------------------------------------------------------------- |
| [hello-world](src/hello-world/) | Classic hello world. |
| [hello-file](src/hello-file/) | Load and execute Ruby code from a file. |
| [pushing-variables](src/pushing-variables/) | Define various types of variables from C to Ruby. |
| [objects](src/objects/) | Create classes & objects from C. |
| [method-defined](src/method-defined/) | Check if a certain method is defined on Ruby. |
| [call-methods](src/call-methods/) | Call Ruby methods from C. |
| [using-cdata](src/using-cdata/) | Wrap C data inside a Ruby object. |
| [kwargs](src/kwargs/) | Parse keyword arguments. |
| [blocks](src/blocks/) | Interact with Ruby's block from C. |
| [compiling-bytecode](src/compiling-bytecode/) | Compile Ruby code into bytecode format and save it on the disk. |
### SDL2
| Example | Description |
|:------------------------------:| --------------------------------------------- |
| [sdl-wrapper](src/sdl-wrapper) | Basic wrapper around SDL2 to create a window. |
## Credits
Credits where due, here are some helpful articles/post/resources that helped
me to learn how to use MRuby:
- [Executing Ruby code with MRuby](https://mruby.org/docs/articles/executing-ruby-code-with-mruby.html)
- [MRuby GUI series](https://dev.to/roryo/a-new-smalltalk-style-environment-for-ruby-5f5c)
## License
All the examples found here are licensed under the [MIT License](/LICENSE).