Skip to content

AaronC81/mruby

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13,639 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MRuby + Gosu

This is a fork of MRuby which is capable of running Gosu games, by statically linking against it through the mruby-gosu wrapper.

Thank you to Ruby2D for the baseline MRuby Emscripten build config!

Building

This is a bit complicated right now - sorry!

You will need the Emscripten SDK (specifically emcc).

Step 1. Setup

Check out this repository and my fork of Gosu in the same parent directory - that is, you should have mruby and gosu directories in the same directory:

src
|--- gosu
|    |--- ...
|    '--- emscripten-build
'--- mruby
     |--- ...
     '--- wasm_config.rb

Step 2. Build Gosu

cd into gosu and run the following to build the forked Gosu library:

./emscripten-build

When successful, it should drop a load of .o files into emscripten-output. Congratulations, you've compiled Gosu for the web!

Step 3. Build MRuby

cd back out of gosu and into mruby.

We need to use a slightly modified copy of the mruby-gosu wrapper. cd into mrbgems, check it out with git clone https://github.com/cyberarm/mruby-gosu, then cd into mruby-gosu and modify mrbgem.rake to remove the line:

linker.libraries << "gosu-ffi"

(This is because mruby-gosu expects Gosu installed as a system library, but we are going to manually link the object files into MRuby. This process should probably be automated in future!)

Now we're ready to build MRuby. cd back to just inside mruby, and run:

MRUBY_CONFIG=wasm_config.rb rake

If all goes well, you should get a build/emscripten/lib/libmruby.a binary.

Step 4. Build Your Game

To get an actual web page, we need to do one more build where we link everything together and provide a main implementation which starts the Ruby interpreter.

An example of how to do this is provided in the gosu-sample directory of this (MRuby) repository. To build it, cd into it and run ./build.sh.

When that's done, you should get an index.html generated! WebAssembly won't just work if you open this file in a browser - you need to host a local web server instead. If you have Python, you can run python -m http.server in the gosu-sample directory to do this, and then navigate to localhost:8000 in your browser. Hooray - you are seeing a Gosu game in your browser (hopefully)!

If you'd like to change the Ruby code which runs, you can modify gosu-sample/assets/main.rb. Please note that Ruby exceptions do not currently work properly, and will appear to hang/crash the interpreter instead! You may find it useful to wrap the body of every function in a begin/rescue which prints the exception if this appears to be happening.

About

MRuby fork capable of running Gosu on the web

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C 65.3%
  • Ruby 26.1%
  • Yacc 6.5%
  • C++ 2.1%
  • Shell 0.0%
  • Batchfile 0.0%