diff options
| -rw-r--r-- | .gitmodules | 3 | ||||
| -rw-r--r-- | Makefile | 19 | ||||
| -rw-r--r-- | build_config.rb | 81 | ||||
| -rw-r--r-- | build_config.rb.lock | 4 | ||||
| -rw-r--r-- | mrb_gems/basic_example/LICENSE | 22 | ||||
| -rw-r--r-- | mrb_gems/basic_example/README.md | 2 | ||||
| -rw-r--r-- | mrb_gems/basic_example/mrbgem.rake | 4 | ||||
| -rw-r--r-- | mrb_gems/basic_example/mrblib/basic_example.rb | 7 | ||||
| -rw-r--r-- | mrb_gems/basic_example/src/basic_example.c | 30 | ||||
| m--------- | mruby | 0 | ||||
| -rw-r--r-- | test_suite.rb | 4 |
11 files changed, 176 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..d981030 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "mruby"] + path = mruby + url = https://github.com/mruby/mruby diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..1fd3017 --- /dev/null +++ b/Makefile @@ -0,0 +1,19 @@ + +.PHONY: all +all: mruby/build/host/bin/mruby + @echo " -- Done Building -- " + +.PHONY: mruby +mruby: mruby/build/host/bin/mruby + +mruby/build/host/bin/mruby: build_config.rb + @echo " -- Building mruby -- " + (cd mruby && MRUBY_CONFIG=../build_config.rb rake) + +.PHONY: clean +clean: + (cd mruby && rake clean) + +.PHONY: run +run: mruby/build/host/bin/mruby + ./mruby/build/host/bin/mruby test_suite.rb diff --git a/build_config.rb b/build_config.rb new file mode 100644 index 0000000..a4d6ddb --- /dev/null +++ b/build_config.rb @@ -0,0 +1,81 @@ +MRuby::Build.new do |conf| + # load specific toolchain settings + conf.toolchain + + # Use mrbgems + conf.gem './mrb_gems/basic_example' + # conf.gem 'examples/mrbgems/ruby_extension_example' + # conf.gem 'examples/mrbgems/c_extension_example' do |g| + # g.cc.flags << '-g' # append cflags in this gem + # end + # conf.gem 'examples/mrbgems/c_and_ruby_extension_example' + # conf.gem :core => 'mruby-eval' + # conf.gem :mgem => 'mruby-onig-regexp' + # conf.gem :github => 'mattn/mruby-onig-regexp' + # conf.gem :git => '[email protected]:mattn/mruby-onig-regexp.git', :branch => 'master', :options => '-v' + + # include the GEM box + conf.gembox 'default' + + # C compiler settings + # conf.cc do |cc| + # cc.command = ENV['CC'] || 'gcc' + # cc.flags = [ENV['CFLAGS'] || %w()] + # cc.include_paths = ["#{root}/include"] + # cc.defines = %w() + # cc.option_include_path = %q[-I"%s"] + # cc.option_define = '-D%s' + # cc.compile_options = %Q[%{flags} -MMD -o "%{outfile}" -c "%{infile}"] + # end + + # mrbc settings + # conf.mrbc do |mrbc| + # mrbc.compile_options = "-g -B%{funcname} -o-" # The -g option is required for line numbers + # end + + # Linker settings + # conf.linker do |linker| + # linker.command = ENV['LD'] || 'gcc' + # linker.flags = [ENV['LDFLAGS'] || []] + # linker.flags_before_libraries = [] + # linker.libraries = %w() + # linker.flags_after_libraries = [] + # linker.library_paths = [] + # linker.option_library = '-l%s' + # linker.option_library_path = '-L%s' + # linker.link_options = %Q[%{flags} -o "%{outfile}" %{objs} %{libs}] + # end + + # Archiver settings + # conf.archiver do |archiver| + # archiver.command = ENV['AR'] || 'ar' + # archiver.archive_options = 'rs "%{outfile}" %{objs}' + # end + + # Parser generator settings + # conf.yacc do |yacc| + # yacc.command = ENV['YACC'] || 'bison' + # yacc.compile_options = %q[-o "%{outfile}" "%{infile}"] + # end + + # gperf settings + # conf.gperf do |gperf| + # gperf.command = 'gperf' + # gperf.compile_options = %q[-L ANSI-C -C -p -j1 -i 1 -g -o -t -N mrb_reserved_word -k"1,3,$" "%{infile}" > "%{outfile}"] + # end + + # file extensions + # conf.exts do |exts| + # exts.object = '.o' + # exts.executable = '' # '.exe' if Windows + # exts.library = '.a' + # end + + # file separator + # conf.file_separator = '/' + + # Turn on `enable_debug` for better debugging + # conf.enable_debug + conf.enable_bintest + conf.enable_test +end diff --git a/build_config.rb.lock b/build_config.rb.lock new file mode 100644 index 0000000..0b289fd --- /dev/null +++ b/build_config.rb.lock @@ -0,0 +1,4 @@ +--- +mruby: + version: 3.1.0 + release_no: 30100 diff --git a/mrb_gems/basic_example/LICENSE b/mrb_gems/basic_example/LICENSE new file mode 100644 index 0000000..a632bdf --- /dev/null +++ b/mrb_gems/basic_example/LICENSE @@ -0,0 +1,22 @@ +The MIT License (MIT) + +Copyright (c) 2023 Tradam + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. + diff --git a/mrb_gems/basic_example/README.md b/mrb_gems/basic_example/README.md new file mode 100644 index 0000000..2c81a68 --- /dev/null +++ b/mrb_gems/basic_example/README.md @@ -0,0 +1,2 @@ +# BasicExample +An mruby gem created by Tradam using mruby_gem_scaffolding. diff --git a/mrb_gems/basic_example/mrbgem.rake b/mrb_gems/basic_example/mrbgem.rake new file mode 100644 index 0000000..dc0a436 --- /dev/null +++ b/mrb_gems/basic_example/mrbgem.rake @@ -0,0 +1,4 @@ +MRuby::Gem::Specification.new('basic_example') do |spec| + spec.license = 'MIT' + spec.author = 'Tradam' +end diff --git a/mrb_gems/basic_example/mrblib/basic_example.rb b/mrb_gems/basic_example/mrblib/basic_example.rb new file mode 100644 index 0000000..70ee644 --- /dev/null +++ b/mrb_gems/basic_example/mrblib/basic_example.rb @@ -0,0 +1,7 @@ +module BasicExample + class << self + def say_goodbye + puts "Goodbye" + end + end +end diff --git a/mrb_gems/basic_example/src/basic_example.c b/mrb_gems/basic_example/src/basic_example.c new file mode 100644 index 0000000..908acd2 --- /dev/null +++ b/mrb_gems/basic_example/src/basic_example.c @@ -0,0 +1,30 @@ +#include <mruby.h> +#include <stdio.h> + +// defining the function to be later bound to a ruby method +static mrb_value +hello_world(mrb_state *mrb, mrb_value self) +{ + printf("Hello World\n"); + + return mrb_nil_value(); // return null +} + +// gem initializer +void +mrb_basic_example_gem_init(mrb_state* mrb) { + struct RClass *basic_example_class = mrb_define_module(mrb, "BasicExample"); + mrb_define_class_method( + mrb, // Mruby VM state + basic_example_class, // Class we bind method to + "say_hello", // Name of method + hello_world, // Function we are binding as a method + MRB_ARGS_NONE() // How many arguments are optional/required + ); +} + +// gem finalizer +void +mrb_basic_example_gem_final(mrb_state* mrb) { + +} diff --git a/mruby b/mruby new file mode 160000 +Subproject 78141d17f17e4e543300607efdc54ace88ae1d3 diff --git a/test_suite.rb b/test_suite.rb new file mode 100644 index 0000000..b0a6b36 --- /dev/null +++ b/test_suite.rb @@ -0,0 +1,4 @@ +BasicExample.say_hello +BasicExample.say_goodbye + +puts "Reached end of test suite." |
