Skip to content

Conversation

remi6397
Copy link
Contributor

@remi6397 remi6397 commented Dec 8, 2021

Replaces #1006

This PR adds support for the Ruby programming language, or to be precise a lightweight implementation of Ruby called MRuby.

Resources


pre-0.90 Description This PR adds basic support for [Ruby](https://www.ruby-lang.org) scripting via [MRuby](https://mruby.org/).

I thought it'd be nice to have Ruby as an option for scripting, because it's widely used in WebDev (Rails, Sinatra, etc.), DevOps (Puppet, Chef, Vagrant), ITSec (Logstash, Metasploit) and probably in many more applications beyond my field of expertise (SketchUp being the first one to come to my mind).

If you decided to merge, Ruby would make the second most popular language of those available in TIC (right after JavaScript).

I've already tested this on Windows (10, x64) and Linux (openSUSE Tumbleweed) and it compiles without any problems. There are still macOS, Emscripten and Android left to test, but: 1) I'd have to install XCode my Mac; 2) I don't know how to x-compile for Emscripten; 3) I don't own any Android device.

Apart from that, everything seems to work flawlessly. 😉

EDIT: Ran build on my Mac, it works there too.

Jeremiasz Nelz added 24 commits December 4, 2021 11:05
* Mention Ruby in features
* Attribution
Current behavior assumes that comments comprise
exactly two characters, such as "--" or "//".

Many languages, such as Ruby and Python, use
a single character, such as the pound sign
or the ASCII quotation mark to signal
a single-line comment.
Github Actions seems to also prefer the UNIX-native
prefix on Windows CMake
Created a gembox containing only
useful gems
This reverts commit 1a8bf83.

It turns out that wrapping CMake's poor cross build support
was not a good idea after all.
CMake's env helper is broken on Windows OS :/
* Genericize cross compilation
* Clean mruby build artifacts with make/ninja clean
@remi6397 remi6397 mentioned this pull request Dec 8, 2021
CMakeLists.txt Outdated
${TIC80CORE_DIR}/api/lua.c
${TIC80CORE_DIR}/api/moonscript.c
${TIC80CORE_DIR}/api/fennel.c
${TIC80CORE_DIR}/api/wren.c
${TIC80CORE_DIR}/api/squirrel.c
${TIC80CORE_DIR}/api/mrb.c
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we name this mruby since that seems to be the name used everywhere else?

@@ -18,6 +18,7 @@ To make a retro styled game, the whole process of creation and execution takes p
- Multiple programming languages: [Lua](https://www.lua.org),
[Moonscript](https://moonscript.org),
[Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript),
[Ruby](https://www.ruby-lang.org/en/),
Copy link
Collaborator

@joshgoebel joshgoebel Dec 8, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be https://mruby.org

MRuby and Ruby are NOT quite the same project. It's certainly possible to embed Ruby also, but since we're not doing that we should be clear that we're using MRuby, at the very least the link here should point to MRuby I'd think.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I've been thinking of that too, there is some source-level incompatibility between the two, but at the same time we shouldn't create any more confusion to the end users.

IMO it's something worth mentioning in the documentation.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we shouldn't create any more confusion to the end users.

I think [Ruby](https://mruby.org) would solve the issue, no?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Ruby would solve the issue, no?

Ruby is the language, MRuby is just one of the available implementations.

Just like with Javascript (or should I say ECMAscript); duktape isn't perfectly compliant either:

   [Javascript](https://developer.mozilla.org/en-US/docs/Web/JavaScript), 

@joshgoebel
Copy link
Collaborator

This is MUCH cleaner PR. :) Nice!

@nesbox
Copy link
Owner

nesbox commented Dec 10, 2021

@remi6397 I see N3DS is fixed, how did you do it?
image

@remi6397
Copy link
Contributor Author

@remi6397 I see N3DS is fixed, how did you do it? image

That's because I got rid of IO-related gems, I think.

@nesbox
Copy link
Owner

nesbox commented Dec 10, 2021

Please try to add $(TIC80LIB)/libmruby.a \
here https://github.com/remi6397/TIC-80/blob/master/build/baremetalpi/Makefile#L23

LIBS :=  \
	$(TIC80LIB)/libtic80studio.a \
	$(TIC80LIB)/libtic80core.a \
	$(TIC80LIB)/libgiflib.a \
	$(TIC80LIB)/liblpeg.a \
 	$(TIC80LIB)/liblua.a \
	$(TIC80LIB)/libzip.a \
	$(TIC80LIB)/libblipbuf.a \
	$(TIC80LIB)/libsquirrel.a \
	$(TIC80LIB)/libwren.a \
	$(TIC80LIB)/libargparse.a \
	$(TIC80LIB)/libwave_writer.a \
	$(TIC80LIB)/libduktape.a \
	$(TIC80LIB)/libzlib.a \
	$(TIC80LIB)/libpng.a \
	$(NEWLIBDIR)/lib/libc.a \
        $(NEWLIBDIR)/lib/libcirclenewlib.a \
	$(CIRCLEHOME)/addon/vc4/sound/libvchiqsound.a \
        $(CIRCLEHOME)/addon/vc4/vchiq/libvchiq.a \
        $(CIRCLEHOME)/addon/linux/liblinuxemu.a \
 	$(CIRCLEHOME)/addon/SDCard/libsdcard.a \
 	$(CIRCLEHOME)/addon/fatfs/libfatfs.a \
  	$(CIRCLEHOME)/lib/usb/libusb.a \
 	$(CIRCLEHOME)/lib/input/libinput.a \
 	$(CIRCLEHOME)/lib/fs/fat/libfatfs.a \
 	$(CIRCLEHOME)/lib/fs/libfs.a \
  	$(CIRCLEHOME)/lib/net/libnet.a \
  	$(CIRCLEHOME)/lib/sched/libsched.a \
  	$(CIRCLEHOME)/lib/libcircle.a \
	$(NEWLIBDIR)/lib/libm.a

This will possibly fix the rpi-baremetal build.

@nesbox
Copy link
Owner

nesbox commented Dec 10, 2021

Left to win Android
image

@RobLoach
Copy link
Contributor

Would love to keep backwards compatibility when Rake isn't available. Here's a Pull Request that disables mruby if Rake isn't there: remi6397#6

@remi6397
Copy link
Contributor Author

And Bob's your uncle, everything builds successfully now! 🎉

Build Status

@nesbox
Copy link
Owner

nesbox commented Dec 11, 2021

Awesome, so we're ready to merge :)
Thanks for your persistence and for not abandoning the PR 👍

Copy link
Owner

@nesbox nesbox left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, the job well done 👍

for ARCH in arm arm64 x86 x86_64; do \
API=24; \
SYSROOT=$ANDROID_NDK_HOME/platforms/android-$API/arch-$ARCH; \
python3 "$ANDROID_NDK_HOME/build/tools/make_standalone_toolchain.py" \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to move this part to the Docker initialization part after merging the PR

@@ -588,7 +678,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
script: [lua, moon, fennel, js, wren, squirrel]
script: [lua, moon, fennel, mruby, js, wren, squirrel]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to rename it to ruby here or the export ruby %name% command won't work.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, we can use export mruby as a variant.
Any thoughts?

mrb_funcall(mrb, mrb_top_self(mrb), TicFunc, 0);
catcherr(machine);

if (mrb_respond_to(mrb, mrb_top_self(mrb), mrb_intern_cstr(mrb, OvrFunc)))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to call OVR() here for new languages, it's for compatibility, so we can remove this callback here.

@nesbox nesbox merged commit c656bdf into nesbox:master Dec 11, 2021
nesbox added a commit that referenced this pull request Dec 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants