├── .clang-format ├── .github ├── PULL_REQUEST_TEMPLATE.md └── workflows │ └── test.yml ├── .gitignore ├── .gitmodules ├── .travis.yml ├── .vscode └── c_cpp_properties.json ├── AUTHORS ├── Dockerfile ├── LEGAL ├── MITL ├── Makefile.in ├── README.md ├── Vagrantfile ├── apply-clang-format ├── build.sh ├── build_config.rb ├── config.in ├── configure ├── configure.in ├── dependence └── ngx_devel_kit │ ├── .gitignore │ ├── LICENSE │ ├── README.md │ ├── README_AUTO_LIB.md │ ├── auto │ ├── actions │ │ ├── array │ │ └── palloc │ ├── build │ ├── data │ │ ├── action_replacements │ │ ├── action_types │ │ ├── conf_args │ │ ├── conf_locs │ │ ├── conf_macros │ │ ├── contexts │ │ ├── header_files │ │ ├── headers │ │ ├── module_dependencies │ │ ├── modules_optional │ │ └── prefixes │ ├── src │ │ ├── array.h │ │ ├── conf_cmd_basic.h │ │ ├── conf_merge.h │ │ └── palloc.h │ └── text │ │ └── autogen │ ├── config │ ├── docs │ ├── core │ │ ├── action_macros │ │ └── conf_cmds │ ├── modules │ │ └── set_var │ ├── patches │ │ └── more_logging_info │ └── upstream │ │ └── list │ ├── examples │ ├── README │ └── http │ │ └── set_var │ │ ├── config │ │ └── ngx_http_set_var_examples_module.c │ ├── ngx_auto_lib_core │ ├── notes │ ├── CHANGES │ └── LICENSE │ ├── objs │ ├── ndk_array.h │ ├── ndk_conf_cmd_basic.h │ ├── ndk_conf_cmd_extra.h │ ├── ndk_conf_merge.h │ ├── ndk_config.c │ ├── ndk_config.h │ ├── ndk_includes.h │ └── ndk_palloc.h │ ├── patches │ ├── auto_config │ ├── expose_rewrite_functions │ └── rewrite_phase_handler │ └── src │ ├── hash │ ├── md5.h │ ├── murmurhash2.c │ └── sha.h │ ├── ndk.c │ ├── ndk.h │ ├── ndk_buf.c │ ├── ndk_buf.h │ ├── ndk_complex_path.c │ ├── ndk_complex_path.h │ ├── ndk_complex_value.c │ ├── ndk_complex_value.h │ ├── ndk_conf_file.c │ ├── ndk_conf_file.h │ ├── ndk_debug.c │ ├── ndk_debug.h │ ├── ndk_encoding.c │ ├── ndk_encoding.h │ ├── ndk_hash.c │ ├── ndk_hash.h │ ├── ndk_http.c │ ├── ndk_http.h │ ├── ndk_http_headers.h │ ├── ndk_log.c │ ├── ndk_log.h │ ├── ndk_parse.h │ ├── ndk_path.c │ ├── ndk_path.h │ ├── ndk_process.c │ ├── ndk_process.h │ ├── ndk_regex.c │ ├── ndk_regex.h │ ├── ndk_rewrite.c │ ├── ndk_rewrite.h │ ├── ndk_set_var.c │ ├── ndk_set_var.h │ ├── ndk_string.c │ ├── ndk_string.h │ ├── ndk_string_util.h │ ├── ndk_upstream_list.c │ ├── ndk_upstream_list.h │ ├── ndk_uri.c │ └── ndk_uri.h ├── docker ├── conf │ └── nginx.conf └── hook │ ├── proxy.rb │ └── test.rb ├── docs ├── DEVELOPMENT.md ├── README.md ├── class_and_method │ └── README.md ├── directives │ └── README.md ├── install │ └── README.md ├── test │ └── README.md └── use_case │ └── README.md ├── example ├── README.md ├── nginx.conf ├── proxy.rb ├── set.rb ├── set2.rb └── unified_hello.rb ├── misc ├── Dockerfile.travis_emulate ├── logo.png └── provision.sh ├── mrbgems ├── auto-ssl │ ├── mrbgem.rake │ ├── mrblib │ │ ├── mrb_auto_ssl_client.rb │ │ └── mrb_auto_ssl_dehydrated.rb │ └── test │ │ └── mrb_nginx.rb ├── ngx_mruby_mrblib │ ├── mrbgem.rake │ ├── mrblib │ │ └── mrb_nginx.rb │ └── test │ │ └── mrb_nginx.rb └── rack-based-api │ ├── mrbgem.rake │ ├── mrblib │ └── rack.rb │ └── test │ └── mrb_nginx.rb ├── mruby ├── .dockerignore ├── .editorconfig ├── .git-blame-ignore-revs ├── .gitattributes ├── .github │ ├── dependabot.yml │ ├── labeler.yml │ ├── linters │ │ ├── .ecrc │ │ ├── .markdown-lint.yml │ │ └── .yaml-lint.yml │ └── workflows │ │ ├── build.yml │ │ ├── labeler.yml │ │ ├── lint.yml │ │ ├── oss-fuzz.yml │ │ └── super-linter.yml ├── .gitignore ├── .pre-commit-config.yaml ├── .prettierrc ├── .travis.yml ├── .yardopts ├── AUTHORS ├── CODEOWNERS ├── CONTRIBUTING.md ├── Dockerfile ├── Doxyfile ├── Gemfile ├── Gemfile.lock ├── LEGAL ├── LICENSE ├── Makefile ├── NEWS ├── README.md ├── Rakefile ├── SECURITY.md ├── TODO.md ├── appveyor.yml ├── benchmark │ ├── bm_ao_render.rb │ ├── bm_app_lc_fizzbuzz.rb │ ├── bm_fib.rb │ ├── bm_so_lists.rb │ └── plot.gpl ├── build_config.rb ├── build_config │ ├── ArduinoDue.rb │ ├── IntelEdison.rb │ ├── IntelGalileo.rb │ ├── RX630.rb │ ├── android_arm64_v8a.rb │ ├── android_armeabi_v7a_neon_hard.rb │ ├── bench.rb │ ├── boxing.rb │ ├── chipKITMax32.rb │ ├── ci │ │ ├── gcc-clang.rb │ │ └── msvc.rb │ ├── clang-asan.rb │ ├── cross-32bit.rb │ ├── cross-mingw-winetest.rb │ ├── cross-mingw.rb │ ├── default.rb │ ├── dreamcast_shelf.rb │ ├── gameboyadvance.rb │ ├── helpers │ │ └── wine_runner.rb │ ├── host-cxx.rb │ ├── host-debug.rb │ ├── host-f32.rb │ ├── host-gprof.rb │ ├── host-m32.rb │ ├── host-nofloat.rb │ ├── host-shared.rb │ ├── i586-pc-msdosdjgpp.rb │ ├── minimal.rb │ ├── mrbc.rb │ ├── nintendo_switch.rb │ ├── nintendo_wii.rb │ └── serenity.rb ├── codespell.txt ├── doc │ ├── guides │ │ ├── compile.md │ │ ├── debugger.md │ │ ├── gc-arena-howto.md │ │ ├── link.md │ │ ├── memory.md │ │ ├── mrbconf.md │ │ ├── mrbgems.md │ │ └── symbol.md │ ├── internal │ │ ├── boxing.md │ │ └── opcode.md │ ├── limitations.md │ ├── mruby3.0.md │ ├── mruby3.1.md │ ├── mruby3.2.md │ ├── mruby3.3.md │ └── mruby_logo_red_icon.png ├── docker-compose.yml ├── examples │ └── mrbgems │ │ ├── c_and_ruby_extension_example │ │ ├── README.md │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── example.rb │ │ ├── src │ │ │ └── example.c │ │ └── test │ │ │ └── example.rb │ │ ├── c_extension_example │ │ ├── README.md │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── example.c │ │ └── test │ │ │ ├── example.c │ │ │ └── example.rb │ │ ├── cdata_extension_example │ │ ├── README.md │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── example.c │ │ └── test │ │ │ └── example.c │ │ ├── mruby-YOUR-bigint │ │ ├── TODO-HINT.md │ │ ├── core │ │ │ └── bigint.c │ │ └── mrbgem.rake │ │ └── ruby_extension_example │ │ ├── README.md │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ └── example.rb │ │ └── test │ │ └── example.rb ├── include │ ├── mrbconf.h │ ├── mruby.h │ └── mruby │ │ ├── array.h │ │ ├── boxing_nan.h │ │ ├── boxing_no.h │ │ ├── boxing_word.h │ │ ├── class.h │ │ ├── common.h │ │ ├── compile.h │ │ ├── data.h │ │ ├── debug.h │ │ ├── dump.h │ │ ├── endian.h │ │ ├── error.h │ │ ├── gc.h │ │ ├── hash.h │ │ ├── internal.h │ │ ├── irep.h │ │ ├── istruct.h │ │ ├── khash.h │ │ ├── numeric.h │ │ ├── object.h │ │ ├── opcode.h │ │ ├── ops.h │ │ ├── presym.h │ │ ├── presym │ │ ├── disable.h │ │ ├── enable.h │ │ └── scanning.h │ │ ├── proc.h │ │ ├── range.h │ │ ├── re.h │ │ ├── string.h │ │ ├── throw.h │ │ ├── value.h │ │ ├── variable.h │ │ └── version.h ├── lib │ └── mruby │ │ ├── build.rb │ │ ├── build │ │ ├── command.rb │ │ └── load_gems.rb │ │ ├── core_ext.rb │ │ ├── doc.rb │ │ ├── gem.rb │ │ ├── lockfile.rb │ │ ├── presym.rb │ │ └── source.rb ├── minirake ├── mrbgems │ ├── default-no-fpu.gembox │ ├── default-no-stdio.gembox │ ├── default.gembox │ ├── full-core.gembox │ ├── math.gembox │ ├── metaprog.gembox │ ├── mruby-array-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── array.rb │ │ ├── src │ │ │ └── array.c │ │ └── test │ │ │ └── array.rb │ ├── mruby-bigint │ │ ├── README-fgmp.md │ │ ├── README.md │ │ ├── core │ │ │ ├── bigint.c │ │ │ └── bigint.h │ │ ├── mrbgem.rake │ │ └── test │ │ │ └── bigint.rb │ ├── mruby-bin-config │ │ ├── mrbgem.rake │ │ ├── mruby-config │ │ └── mruby-config.bat │ ├── mruby-bin-debugger │ │ ├── bintest │ │ │ ├── mrdb.rb │ │ │ └── print.rb │ │ ├── mrbgem.rake │ │ └── tools │ │ │ └── mrdb │ │ │ ├── apibreak.c │ │ │ ├── apibreak.h │ │ │ ├── apilist.c │ │ │ ├── apilist.h │ │ │ ├── apiprint.c │ │ │ ├── apiprint.h │ │ │ ├── apistring.c │ │ │ ├── apistring.h │ │ │ ├── cmdbreak.c │ │ │ ├── cmdmisc.c │ │ │ ├── cmdprint.c │ │ │ ├── cmdrun.c │ │ │ ├── mrdb.c │ │ │ ├── mrdb.h │ │ │ ├── mrdbconf.h │ │ │ └── mrdberror.h │ ├── mruby-bin-mirb │ │ ├── bintest │ │ │ └── mirb.rb │ │ ├── mrbgem.rake │ │ └── tools │ │ │ └── mirb │ │ │ └── mirb.c │ ├── mruby-bin-mrbc │ │ ├── bintest │ │ │ └── mrbc.rb │ │ ├── mrbgem.rake │ │ └── tools │ │ │ └── mrbc │ │ │ ├── mrbc.c │ │ │ └── stub.c │ ├── mruby-bin-mruby │ │ ├── bintest │ │ │ └── mruby.rb │ │ ├── mrbgem.rake │ │ └── tools │ │ │ └── mruby │ │ │ └── mruby.c │ ├── mruby-bin-strip │ │ ├── bintest │ │ │ └── mruby-strip.rb │ │ ├── mrbgem.rake │ │ └── tools │ │ │ └── mruby-strip │ │ │ └── mruby-strip.c │ ├── mruby-binding │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── binding.c │ │ └── test │ │ │ ├── binding.c │ │ │ └── binding.rb │ ├── mruby-catch │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── catch.rb │ │ ├── src │ │ │ └── catch.c │ │ └── test │ │ │ └── catch.rb │ ├── mruby-class-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── module.rb │ │ ├── src │ │ │ └── class.c │ │ └── test │ │ │ ├── class.rb │ │ │ └── module.rb │ ├── mruby-cmath │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── cmath.c │ │ └── test │ │ │ └── cmath.rb │ ├── mruby-compar-ext │ │ ├── mrbgem.rake │ │ └── mrblib │ │ │ └── compar.rb │ ├── mruby-compiler │ │ ├── core │ │ │ ├── codegen.c │ │ │ ├── keywords │ │ │ ├── lex.def │ │ │ ├── node.h │ │ │ ├── parse.y │ │ │ └── y.tab.c │ │ └── mrbgem.rake │ ├── mruby-complex │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── complex.rb │ │ ├── src │ │ │ └── complex.c │ │ └── test │ │ │ └── complex.rb │ ├── mruby-data │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── data.c │ │ └── test │ │ │ └── data.rb │ ├── mruby-dir │ │ ├── README.md │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── dir.rb │ │ ├── src │ │ │ ├── Win │ │ │ │ └── dirent.c │ │ │ └── dir.c │ │ └── test │ │ │ ├── dir.rb │ │ │ └── dirtest.c │ ├── mruby-enum-chain │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── chain.rb │ │ └── test │ │ │ └── enum_chain.rb │ ├── mruby-enum-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── enum.rb │ │ └── test │ │ │ └── enum.rb │ ├── mruby-enum-lazy │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── lazy.rb │ │ └── test │ │ │ └── lazy.rb │ ├── mruby-enumerator │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── enumerator.rb │ │ └── test │ │ │ └── enumerator.rb │ ├── mruby-errno │ │ ├── README.md │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── errno.rb │ │ ├── src │ │ │ ├── errno.c │ │ │ ├── gen.rb │ │ │ ├── known_errors.def │ │ │ └── known_errors_def.cstub │ │ └── test │ │ │ └── errno.rb │ ├── mruby-error │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── exception.c │ │ └── test │ │ │ ├── exception.c │ │ │ └── exception.rb │ ├── mruby-eval │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── eval.c │ │ └── test │ │ │ ├── binding.rb │ │ │ └── eval.rb │ ├── mruby-exit │ │ ├── mrbgem.rake │ │ └── src │ │ │ └── mruby-exit.c │ ├── mruby-fiber │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── fiber.c │ │ └── test │ │ │ ├── fiber.rb │ │ │ ├── fiber2.rb │ │ │ └── fibertest.c │ ├── mruby-hash-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── hash.rb │ │ ├── src │ │ │ └── hash-ext.c │ │ └── test │ │ │ └── hash.rb │ ├── mruby-io │ │ ├── README.md │ │ ├── include │ │ │ └── mruby │ │ │ │ └── ext │ │ │ │ └── io.h │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ ├── file.rb │ │ │ ├── file_constants.rb │ │ │ ├── io.rb │ │ │ └── kernel.rb │ │ ├── src │ │ │ ├── file.c │ │ │ ├── file_test.c │ │ │ ├── io.c │ │ │ └── mruby_io_gem.c │ │ └── test │ │ │ ├── file.rb │ │ │ ├── file_test.rb │ │ │ ├── io.rb │ │ │ └── mruby_io_test.c │ ├── mruby-kernel-ext │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── kernel.c │ │ └── test │ │ │ └── kernel.rb │ ├── mruby-math │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── math.c │ │ └── test │ │ │ └── math.rb │ ├── mruby-metaprog │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── metaprog.c │ │ └── test │ │ │ └── metaprog.rb │ ├── mruby-method │ │ ├── README.md │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── method.rb │ │ ├── src │ │ │ └── method.c │ │ └── test │ │ │ └── method.rb │ ├── mruby-numeric-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── numeric_ext.rb │ │ ├── src │ │ │ └── numeric_ext.c │ │ └── test │ │ │ └── numeric.rb │ ├── mruby-object-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── object.rb │ │ ├── src │ │ │ └── object.c │ │ └── test │ │ │ ├── nil.rb │ │ │ └── object.rb │ ├── mruby-objectspace │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── mruby_objectspace.c │ │ └── test │ │ │ └── objectspace.rb │ ├── mruby-os-memsize │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── memsize.c │ │ └── test │ │ │ └── memsize.rb │ ├── mruby-pack │ │ ├── README.md │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── pack.c │ │ └── test │ │ │ └── pack.rb │ ├── mruby-print │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── print.rb │ │ └── src │ │ │ └── print.c │ ├── mruby-proc-binding │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── proc-binding.c │ │ └── test │ │ │ ├── proc-binding.c │ │ │ └── proc-binding.rb │ ├── mruby-proc-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── proc.rb │ │ ├── src │ │ │ └── proc.c │ │ └── test │ │ │ ├── proc.c │ │ │ └── proc.rb │ ├── mruby-random │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── random.c │ │ └── test │ │ │ └── random.rb │ ├── mruby-range-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── range.rb │ │ ├── src │ │ │ └── range.c │ │ └── test │ │ │ └── range.rb │ ├── mruby-rational │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── rational.rb │ │ ├── src │ │ │ └── rational.c │ │ └── test │ │ │ └── rational.rb │ ├── mruby-set │ │ ├── LICENSE │ │ ├── README.md │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── set.rb │ │ ├── mruby-set.gem │ │ └── test │ │ │ └── set.rb │ ├── mruby-sleep │ │ ├── README.md │ │ ├── example │ │ │ └── sleep.rb │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── sleep.c │ │ └── test │ │ │ └── sleep_test.rb │ ├── mruby-socket │ │ ├── README.md │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── socket.rb │ │ ├── src │ │ │ ├── const.cstub │ │ │ ├── const.def │ │ │ ├── gen.rb │ │ │ └── socket.c │ │ └── test │ │ │ ├── addrinfo.rb │ │ │ ├── basicsocket.rb │ │ │ ├── ipsocket.rb │ │ │ ├── socket.rb │ │ │ ├── sockettest.c │ │ │ ├── tcpsocket.rb │ │ │ ├── udpsocket.rb │ │ │ └── unix.rb │ ├── mruby-sprintf │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── string.rb │ │ ├── src │ │ │ └── sprintf.c │ │ └── test │ │ │ └── sprintf.rb │ ├── mruby-string-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── string.rb │ │ ├── src │ │ │ └── string.c │ │ └── test │ │ │ ├── numeric.rb │ │ │ ├── range.rb │ │ │ └── string.rb │ ├── mruby-struct │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── struct.rb │ │ ├── src │ │ │ └── struct.c │ │ └── test │ │ │ └── struct.rb │ ├── mruby-symbol-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── symbol.rb │ │ ├── src │ │ │ └── symbol.c │ │ └── test │ │ │ └── symbol.rb │ ├── mruby-test-inline-struct │ │ ├── mrbgem.rake │ │ └── test │ │ │ ├── inline.c │ │ │ └── inline.rb │ ├── mruby-test │ │ ├── README.md │ │ ├── driver.c │ │ ├── mrbgem.rake │ │ └── vformat.c │ ├── mruby-time │ │ ├── include │ │ │ └── mruby │ │ │ │ └── time.h │ │ ├── mrbgem.rake │ │ ├── src │ │ │ └── time.c │ │ └── test │ │ │ └── time.rb │ ├── mruby-toplevel-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── toplevel.rb │ │ └── test │ │ │ └── toplevel.rb │ ├── stdlib-ext.gembox │ ├── stdlib-io.gembox │ └── stdlib.gembox ├── mrblib │ ├── 00class.rb │ ├── 00kernel.rb │ ├── 10error.rb │ ├── array.rb │ ├── compar.rb │ ├── enum.rb │ ├── hash.rb │ ├── kernel.rb │ ├── numeric.rb │ ├── range.rb │ ├── string.rb │ └── symbol.rb ├── mruby-source.gemspec ├── oss-fuzz │ ├── config │ │ ├── mruby.dict │ │ ├── mruby_fuzzer.options │ │ └── mruby_proto_fuzzer.options │ ├── mruby_fuzzer.c │ ├── mruby_proto_fuzzer.cpp │ ├── proto_to_ruby.cpp │ ├── proto_to_ruby.h │ └── ruby.proto ├── src │ ├── allocf.c │ ├── array.c │ ├── backtrace.c │ ├── cdump.c │ ├── class.c │ ├── codedump.c │ ├── debug.c │ ├── dump.c │ ├── enum.c │ ├── error.c │ ├── error.h │ ├── etc.c │ ├── fmt_fp.c │ ├── gc.c │ ├── hash.c │ ├── init.c │ ├── kernel.c │ ├── load.c │ ├── numeric.c │ ├── numops.c │ ├── object.c │ ├── opcode.h │ ├── pool.c │ ├── print.c │ ├── proc.c │ ├── range.c │ ├── readfloat.c │ ├── readint.c │ ├── readnum.c │ ├── state.c │ ├── string.c │ ├── symbol.c │ ├── value_array.h │ ├── variable.c │ ├── version.c │ └── vm.c ├── tasks │ ├── benchmark.rake │ ├── bin.rake │ ├── core.rake │ ├── doc.rake │ ├── install.rake │ ├── libmruby.rake │ ├── mrbgems.rake │ ├── mrblib.rake │ ├── presym.rake │ ├── test.rake │ └── toolchains │ │ ├── android.rake │ │ ├── clang.rake │ │ ├── gcc.rake │ │ ├── openwrt.rake │ │ └── visualcpp.rake └── test │ ├── assert.rb │ ├── bintest.rb │ └── t │ ├── argumenterror.rb │ ├── array.rb │ ├── basicobject.rb │ ├── bs_block.rb │ ├── bs_literal.rb │ ├── class.rb │ ├── codegen.rb │ ├── comparable.rb │ ├── ensure.rb │ ├── enumerable.rb │ ├── exception.rb │ ├── false.rb │ ├── float.rb │ ├── gc.rb │ ├── hash.rb │ ├── indexerror.rb │ ├── integer.rb │ ├── iterations.rb │ ├── kernel.rb │ ├── lang.rb │ ├── literals.rb │ ├── localjumperror.rb │ ├── methods.rb │ ├── module.rb │ ├── nameerror.rb │ ├── nil.rb │ ├── nomethoderror.rb │ ├── numeric.rb │ ├── object.rb │ ├── proc.rb │ ├── range.rb │ ├── rangeerror.rb │ ├── regexperror.rb │ ├── runtimeerror.rb │ ├── standarderror.rb │ ├── string.rb │ ├── superclass.rb │ ├── symbol.rb │ ├── syntax.rb │ ├── true.rb │ ├── typeerror.rb │ ├── unicode.rb │ └── vformat.rb ├── nginx_version ├── src ├── http │ ├── ngx_http_mruby_async.c │ ├── ngx_http_mruby_async.h │ ├── ngx_http_mruby_connection.c │ ├── ngx_http_mruby_connection.h │ ├── ngx_http_mruby_core.c │ ├── ngx_http_mruby_core.h │ ├── ngx_http_mruby_filter.c │ ├── ngx_http_mruby_filter.h │ ├── ngx_http_mruby_init.c │ ├── ngx_http_mruby_init.h │ ├── ngx_http_mruby_module.c │ ├── ngx_http_mruby_module.h │ ├── ngx_http_mruby_request.c │ ├── ngx_http_mruby_request.h │ ├── ngx_http_mruby_server.c │ ├── ngx_http_mruby_server.h │ ├── ngx_http_mruby_ssl.c │ ├── ngx_http_mruby_ssl.h │ ├── ngx_http_mruby_upstream.c │ ├── ngx_http_mruby_upstream.h │ ├── ngx_http_mruby_var.c │ └── ngx_http_mruby_var.h └── stream │ ├── ngx_stream_mruby_async.c │ ├── ngx_stream_mruby_async.h │ ├── ngx_stream_mruby_connection.c │ ├── ngx_stream_mruby_connection.h │ ├── ngx_stream_mruby_core.c │ ├── ngx_stream_mruby_core.h │ ├── ngx_stream_mruby_init.c │ ├── ngx_stream_mruby_init.h │ ├── ngx_stream_mruby_module.c │ └── ngx_stream_mruby_module.h ├── test.sh ├── test ├── conf │ ├── auto-ssl │ │ ├── dehydrated │ │ ├── dehydrated.conf │ │ ├── dehydrated_out │ │ │ └── .gitkeep │ │ ├── nginx.conf.client_example │ │ ├── nginx.conf.dehydrated_example │ │ └── ngx_mruby-hook.sh │ ├── nginx.conf │ └── nginx.stream.conf ├── html │ ├── add_handler.rb │ ├── backtrace.rb │ ├── exit_worker.rb │ ├── filter_dynamic_arg.rb │ ├── header_filter.rb │ ├── hoge.rb │ ├── image │ │ └── matsumotory.png │ ├── init_worker.rb │ ├── issue-210.rb │ ├── issue_172 │ │ └── index.html │ ├── issue_172_2 │ │ └── index.html │ ├── output_filter_builtin_header │ │ └── index.html │ ├── output_filter_header │ │ └── index.html │ ├── proxy.rb │ ├── set.rb │ ├── set2.rb │ ├── set_ssl_cert_and_key.rb │ ├── stream_lb.rb │ └── unified_hello.rb └── t │ ├── issue-268-test.rb │ └── ngx_mruby.rb ├── update-devkit-subtree └── update-mruby-subtree /.clang-format: -------------------------------------------------------------------------------- 1 | # requires clang-format >= 6.0 2 | BasedOnStyle: "LLVM" 3 | IndentWidth: 2 4 | ColumnLimit: 120 5 | BreakBeforeBraces: Linux 6 | AllowShortFunctionsOnASingleLine: None 7 | SortIncludes: false 8 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | @matsumotory Please review. 2 | 3 | ## Pull-Request Check List 4 | 5 | - [ ] Add patches into `src/`. 6 | - [ ] Add test into `test/`. Please see about [test docs](https://github.com/matsumotory/ngx_mruby/tree/master/docs/test). 7 | - [ ] Add docs into `docs/` if you change the features such as [build system](https://github.com/matsumotory/ngx_mruby/tree/master/docs/install), [Ruby methods, class](https://github.com/matsumotory/ngx_mruby/tree/master/docs/class_and_method) and [nginx directives](https://github.com/matsumotory/ngx_mruby/tree/master/docs/directives). 8 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | GPATH 2 | GRTAGS 3 | GTAGS 4 | GSYMS 5 | mrbgems_config 6 | mrbgems_config_dynamic 7 | Makefile 8 | config 9 | config.status 10 | config.log 11 | tags 12 | *.swp 13 | *~ 14 | build/ 15 | build_dynamic/ 16 | autom4te.cache/ 17 | .openssl_build_done 18 | .openssl_configure_done 19 | .mruby_version 20 | .vagrant/ 21 | build_config.rb.lock 22 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/ngx_mruby/bed251036c0f273fb42fa9e84c00767b15983956/.gitmodules -------------------------------------------------------------------------------- /.vscode/c_cpp_properties.json: -------------------------------------------------------------------------------- 1 | { 2 | "configurations": [ 3 | { 4 | "name": "Mac", 5 | "includePath": [ 6 | "${workspaceFolder}/**" 7 | ], 8 | "defines": [], 9 | "macFrameworkPath": [], 10 | "compilerPath": "/usr/local/bin/gcc-8", 11 | "cStandard": "gnu18", 12 | "cppStandard": "gnu++14", 13 | "intelliSenseMode": "gcc-x64" 14 | } 15 | ], 16 | "version": 4 17 | } -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Original Authors "ngx_mruby developers" are: 2 | MATSUMOTO Ryosuke 3 | Tatsuhiko Kubo 4 | SHIBATA Hiroshi 5 | SAWANOBORI Yukihiko 6 | OKUMURA Takahiro 7 | Yuji Yamano 8 | Kazuhiko Yamashita 9 | -------------------------------------------------------------------------------- /LEGAL: -------------------------------------------------------------------------------- 1 | LEGAL NOTICE INFORMATION 2 | ------------------------ 3 | 4 | All the files in this distribution are covered under the MIT license 5 | (see the file MITL) except some files mentioned below: 6 | -------------------------------------------------------------------------------- /MITL: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 ngx_mruby developers 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure("2") do |config| 2 | config.vm.box = "bento/ubuntu-18.04" 3 | config.vm.provision "shell", :path => "misc/provision.sh", :privileged => false 4 | end 5 | -------------------------------------------------------------------------------- /apply-clang-format: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | for f in `ls src/{http,stream}/*.{c,h}` 6 | do 7 | clang-format -i $f 8 | done 9 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/.gitignore: -------------------------------------------------------------------------------- 1 | tags 2 | cscope.* 3 | *~ 4 | *.swp 5 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010-2018, Marcus Clyne 2 | 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 6 | 7 | 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 8 | 9 | 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 10 | 11 | 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 14 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/actions/array: -------------------------------------------------------------------------------- 1 | 2 | array_create (a,pl,n,sz) a = %1%_array_create (pl,n,sz); if (a == NULL) %A% 3 | array_init (a,pl,n,sz) if (%1%_array_init (a,pl,n,sz) == %E%) %A% 4 | array_push (p,a) p = %1%_array_push (a); if (p == NULL) %A% 5 | array_push_clean (p,a) p = %1%_array_push (a); if (p == NULL) %A%; %2%_zerop (p) 6 | array_push_n (p,a,n) p = %1%_array_push_n (a,n); if (p == NULL) %A% 7 | array_push_n_clean (p,a,n) p = %1%_array_push_n (a,n); if (p == NULL) %A%; %2%_zeropn (p,n) 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/actions/palloc: -------------------------------------------------------------------------------- 1 | 2 | palloc (p,pl,sz) p = %1%_palloc (pl,sz); if (p == NULL) %A% 3 | pallocp (p,pl) %2%_pallocp (p,pl); if (p == NULL) %A% 4 | pallocpn (p,pl,n) %2%_pallocpn (p,pl,n); if (p == NULL) %A% 5 | pcalloc (p,pl,sz) p = %1%_pcalloc (pl,sz); if (p == NULL) %A% 6 | pcallocp (p,pl) %2%_pcallocp (p,pl); if (p == NULL) %A% 7 | pcallocpn (p,pl,n) %2%_pcallocpn (p,pl,n); if (p == NULL) %A% 8 | 9 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/data/action_replacements: -------------------------------------------------------------------------------- 1 | 2 | OK NGX_OK 3 | E NGX_ERROR 4 | CE NGX_CONF_ERROR 5 | COK NGX_CONF_OK 6 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/data/action_types: -------------------------------------------------------------------------------- 1 | r0 return 0 2 | r1 return 1 3 | r_1 return -1 4 | rok return %OK% 5 | rce return %CE% 6 | rcok return %COK% 7 | re return %E% 8 | rn return NULL 9 | rse {ngx_script_error (e); return;} 10 | sce {ngx_script_configure_error (c); return;} 11 | g(_lb) goto _lb 12 | ge goto error 13 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/data/conf_args: -------------------------------------------------------------------------------- 1 | 2 | TAKE1 3 | TAKE2 4 | TAKE3 5 | TAKE4 6 | TAKE5 7 | TAKE6 8 | TAKE7 9 | TAKE8 10 | TAKE12 11 | TAKE13 12 | TAKE23 13 | TAKE123 14 | TAKE1234 15 | 1MORE 16 | 2MORE 17 | ANY 18 | FLAG 19 | BLOCK 20 | MULTI 21 | ARGS_NUMBER 22 | 23 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/data/conf_locs: -------------------------------------------------------------------------------- 1 | 2 | HTTP_MAIN HTTP_MAIN main 3 | HTTP_SRV HTTP_SRV srv 4 | HTTP_SIF HTTP_SRV srv 5 | HTTP_LOC HTTP_LOC loc 6 | HTTP_LIF HTTP_LOC loc 7 | 8 | HTTP_MAIN_SRV HTTP_SRV srv 9 | HTTP_MAIN_SIF HTTP_SRV srv 10 | HTTP_MAIN_LOC HTTP_LOC loc 11 | HTTP_MAIN_LIF HTTP_LOC loc 12 | 13 | HTTP_SRV_LOC HTTP_LOC loc 14 | HTTP_SRV_LIF HTTP_LOC loc 15 | HTTP_SIF_LOC HTTP_LOC loc 16 | HTTP_SIF_LIF HTTP_LOC loc 17 | 18 | HTTP_MAIN_SRV_LOC HTTP_LOC loc 19 | HTTP_MAIN_SRV_LIF HTTP_LOC loc 20 | HTTP_MAIN_SIF_LOC HTTP_LOC loc 21 | HTTP_MAIN_SRV_SIF_LOC HTTP_LOC loc 22 | HTTP HTTP_LOC loc 23 | HTTP_UPS HTTP_LOC loc 24 | HTTP_ANY HTTP_LOC loc 25 | ANY HTTP_LOC loc 26 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/data/conf_macros: -------------------------------------------------------------------------------- 1 | 2 | BITMASK 1MORE bitmask 3 | BUFS TAKE1 bufs 4 | COMPLEX_KEYVAL TAKE2 http_complex_keyval 5 | COMPLEX_PATH TAKE1 http_complex_path 6 | COMPLEX_VALUE TAKE1 http_complex_value 7 | COMPLEX_VALUE_ARRAY 1MORE http_complex_value_array 8 | ENCODING TAKE1 encoding 9 | ENUM TAKE1 enum 10 | FALSE NOARGS false 11 | FULL_PATH TAKE1 full_path 12 | KEYVAL TAKE2 keyval 13 | KEYVAL1 TAKE2 keyval1 14 | MSEC TAKE1 msec 15 | NULL NOARGS null 16 | NUM TAKE1 num 17 | NUM64 TAKE1 num64 18 | NUM_FLAG TAKE1 num_flag 19 | ONOFF FLAG flag 20 | OFF TAKE1 off 21 | PATH TAKE1 split_path 22 | REXEX TAKE1 regex 23 | REGEX_CL TAKE1 regex_caseless 24 | REGEX_ARRAY 1MORE regex_array 25 | REGEX_ARRAY_CL 1MORE regex_array_caseless 26 | PTR NOARGS ptr 27 | SEC TAKE1 sec 28 | SEC_FLAG TAKE2 sec_flag 29 | SIZE TAKE1 size 30 | STR TAKE1 str 31 | STR_ARRAY 1MORE str_array_multi 32 | STR_ARRAY1 TAKE1 str_array 33 | TRUE NOARGS true 34 | 35 | 36 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/data/contexts: -------------------------------------------------------------------------------- 1 | 2 | MAIN 3 | SRV 4 | SIF 5 | LOC 6 | LIF 7 | 8 | MAIN_SRV 9 | MAIN_SIF 10 | MAIN_LOC 11 | MAIN_LIF 12 | SRV_LOC 13 | SRV_LIF 14 | SIF_LOC 15 | SIF_LIF 16 | 17 | MAIN_SRV_LOC 18 | MAIN_SRV_LIF 19 | MAIN_SIF_LOC 20 | MAIN_SIF_LIF 21 | ANY_MAIN 22 | 23 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/data/header_files: -------------------------------------------------------------------------------- 1 | array 2 | palloc 3 | 4 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/data/headers: -------------------------------------------------------------------------------- 1 | http_headers 2 | log 3 | parse 4 | string_util 5 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/data/module_dependencies: -------------------------------------------------------------------------------- 1 | complex_path complex_value path 2 | conf_file string 3 | hash string 4 | set_var rewrite 5 | upstream_list http_create_main_conf 6 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/data/modules_optional: -------------------------------------------------------------------------------- 1 | buf 2 | complex_path 3 | complex_value 4 | conf_file 5 | encoding 6 | hash 7 | http 8 | path 9 | process 10 | regex 11 | rewrite 12 | set_var 13 | string 14 | upstream_list * 15 | uri 16 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/data/prefixes: -------------------------------------------------------------------------------- 1 | ngx 2 | ndk 3 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/src/array.h: -------------------------------------------------------------------------------- 1 | 2 | #define %2%_array_count(a) ((a)->nelts) 3 | #define %2%_array_get_first(a) ((a)->elts) 4 | #define %2%_array_get_index(a,n) ((void*) ((char*) (a)->elts + (a)->size * n)) 5 | #define %2%_array_get_last(a) ((void*) ((char*) (a)->elts + (a)->size * ((a)->nelts - 1))) 6 | #define %2%_array_get_reverse_index(a,n) ((void*) ((char*) (a)->elts + (a)->size * ((a)->nelts - 1 - n))) 7 | #define %2%_array_push_clean(p,a) {p = %1%_array_push (a); %2%_zerop (p);} 8 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/src/palloc.h: -------------------------------------------------------------------------------- 1 | 2 | #define %2%_pallocp(p,pl) p = %1%_palloc (pl,sizeof(*p)) 3 | #define %2%_pallocpn(p,pl,n) p = %1%_palloc (pl,sizeof(*p)*(n)) 4 | 5 | #define %2%_pcallocp(p,pl) p = %1%_pcalloc (pl,sizeof(*p)) 6 | #define %2%_pcallocpn(p,pl,n) p = %1%_pcalloc (pl,sizeof(*p)*(n)) 7 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/auto/text/autogen: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 2010 (C) Marcus Clyne 4 | * 5 | * DO NOT EDIT THIS FILE MANUALLY 6 | * ------------------------------ 7 | * This file has been generated automatically from scripts in the $base/auto dir and 8 | * data in the $base/auto/data dir. If you wish to edit the output of this file, then 9 | * you should edit these files instead. 10 | * 11 | */ 12 | 13 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/docs/upstream/list: -------------------------------------------------------------------------------- 1 | 2 | NDK_UPSTREAM_LIST 3 | ----------------- 4 | 5 | This submodule provides a directive that creates a list of upstreams, with 6 | optional weighting. This list can then be used by other modules to hash over 7 | the upstreams however they choose. 8 | 9 | 10 | USAGE IN CONF FILE 11 | ------------------ 12 | 13 | e.g. upstream_list name backend1 4:backend2 3:backend3; 14 | 15 | 16 | 17 | USAGE WITH OTHER MODULES 18 | ------------------------ 19 | 20 | Add a line like 21 | 22 | CFLAGS="$CFLAGS -DNDK_UPSTREAM_LIST" 23 | 24 | to the config file of your module. 25 | 26 | 27 | 28 | INTEGRATING WITH YOUR MODULE 29 | ---------------------------- 30 | 31 | The upstream lists are stored in the array given in the lists.h file, which is 32 | an array of ndk_upstream_list_t elts. The elts are currently all pointers to 33 | strings which have been distributed according to the weight - so if there are 34 | two backends, with weight 3 and 4 respectively, there will be 7 pointers in 35 | total with the first 3 pointing to the first backend and the last 4 to the 36 | second. 37 | 38 | 39 | 40 | TODO 41 | ---- 42 | - replace strings with pointers to upstreams if they are available (and if 43 | this is possible) 44 | - add additional 'http://' to strings if necessary 45 | - improve this documentation 46 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/examples/README: -------------------------------------------------------------------------------- 1 | 2 | 2010 (C) Marcus Clyne 3 | 4 | 5 | Examples 6 | -------- 7 | 8 | In this section there are a number of examples of the various features of the tools 9 | module. These have been given in the form of dummy modules, to make it easier to 10 | use as templates for your own module should you choose to do so. 11 | 12 | 13 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/examples/http/set_var/config: -------------------------------------------------------------------------------- 1 | ngx_addon_name=ngx_http_set_var_examples_module 2 | HTTP_MODULES="$HTTP_MODULES ngx_http_set_var_examples_module" 3 | NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_set_var_examples_module.c" 4 | have=NDK_SET_VAR . auto/have -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/notes/CHANGES: -------------------------------------------------------------------------------- 1 | Changelog 2 | --------- 3 | 4 | 0.1 feature : set_var functions 5 | 0.1.1 feature : upstream_list directive and functions 6 | 0.2 feature : conf merge functions 7 | feature : conf command macros 8 | feature : 'action' macros 9 | 0.2.1 bugfix : ndk_map_uri_to_path_add_suffix 10 | 0.2.2 feature : regex conf functions 11 | 0.2.3 feature : version number 12 | 0.2.4 change : the auto/build script is now executed automatically on compilation 13 | 0.2.9 feature : ngx_auto_lib included with source 14 | 0.2.11 bugfix : hash functions did not display properly 15 | 0.2.12 feature : patches for rewrite functions and rewrite phase handler 16 | 0.2.13 change : revert to old behaviour rewrite functions 17 | change : pre-generated config and macro files now provided -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/objs/ndk_includes.h: -------------------------------------------------------------------------------- 1 | /* optional includes */ 2 | 3 | #if (NDK_BUF) 4 | #include 5 | #endif 6 | #if (NDK_COMPLEX_PATH) 7 | #include 8 | #endif 9 | #if (NDK_COMPLEX_VALUE) 10 | #include 11 | #endif 12 | #if (NDK_CONF_FILE) 13 | #include 14 | #endif 15 | #if (NDK_ENCODING) 16 | #include 17 | #endif 18 | #if (NDK_HASH) 19 | #include 20 | #endif 21 | #if (NDK_HTTP) 22 | #include 23 | #endif 24 | #if (NDK_PATH) 25 | #include 26 | #endif 27 | #if (NDK_PROCESS) 28 | #include 29 | #endif 30 | #if (NDK_REGEX) 31 | #include 32 | #endif 33 | #if (NDK_REWRITE) 34 | #include 35 | #endif 36 | #if (NDK_SET_VAR) 37 | #include 38 | #endif 39 | #if (NDK_STRING) 40 | #include 41 | #endif 42 | #if (NDK_UPSTREAM_LIST) 43 | #include 44 | #endif 45 | #if (NDK_URI) 46 | #include 47 | #endif 48 | 49 | 50 | /* non-optional includes */ 51 | 52 | #include 53 | #include 54 | #include 55 | #include 56 | 57 | 58 | /* auto-generated headers */ 59 | 60 | #include 61 | #include 62 | #include 63 | #include 64 | #include 65 | 66 | 67 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/patches/auto_config: -------------------------------------------------------------------------------- 1 | diff -pNr a/src/core/ngx_config.h b/src/core/ngx_config.h 2 | *** a/src/core/ngx_config.h 2008-09-19 13:47:13.000000000 +0100 3 | --- b/src/core/ngx_config.h 2010-10-09 17:14:13.000000000 +0100 4 | *************** typedef intptr_t ngx_flag_t; 5 | *** 127,131 **** 6 | #define NGX_MAX_UINT32_VALUE (uint32_t) 0xffffffff 7 | #endif 8 | 9 | ! 10 | #endif /* _NGX_CONFIG_H_INCLUDED_ */ 11 | --- 127,131 ---- 12 | #define NGX_MAX_UINT32_VALUE (uint32_t) 0xffffffff 13 | #endif 14 | 15 | ! #include 16 | #endif /* _NGX_CONFIG_H_INCLUDED_ */ 17 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/patches/rewrite_phase_handler: -------------------------------------------------------------------------------- 1 | diff -p -r a/src/http/ngx_http_core_module.c b/src/http/ngx_http_core_module.c 2 | *** a/src/http/ngx_http_core_module.c 2010-09-27 12:48:12.000000000 +0100 3 | --- b/src/http/ngx_http_core_module.c 2010-10-09 13:44:09.000000000 +0100 4 | *************** ngx_http_core_rewrite_phase(ngx_http_req 5 | *** 910,915 **** 6 | --- 910,922 ---- 7 | return NGX_AGAIN; 8 | } 9 | 10 | + #if defined(nginx_version) && nginx_version >= 8042 && (NDK_REWRITE_PHASE) 11 | + 12 | + if (rc == NGX_AGAIN || rc == NGX_DONE) { 13 | + return NGX_OK; 14 | + } 15 | + 16 | + #endif 17 | /* rc == NGX_OK || rc == NGX_ERROR || rc == NGX_HTTP_... */ 18 | 19 | ngx_http_finalize_request(r, rc); 20 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk.h: -------------------------------------------------------------------------------- 1 | 2 | /* 3 | * 2010 (C) Marcus Clyne 4 | */ 5 | 6 | 7 | #ifndef NDK_H 8 | #define NDK_H 9 | 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | 16 | #define ndk_version 2015 17 | #define NDK_VERSION "0.2.15" 18 | 19 | 20 | #if (NGX_DEBUG) 21 | #ifndef NDK_DEBUG 22 | #define NDK_DEBUG 1 23 | #endif 24 | #else 25 | #ifndef NDK_DEBUG 26 | #define NDK_DEBUG 0 27 | #endif 28 | #endif 29 | 30 | 31 | #if !(NDK) 32 | #error At least one module requires the Nginx Development Kit to be compiled with \ 33 | the source (add --with-module=/path/to/devel/kit/src to configure command) 34 | #endif 35 | 36 | #include 37 | 38 | 39 | #if (NDK_HTTP_CREATE_MAIN_CONF) 40 | 41 | #define ndk_http_conf_get_main_conf(cf) ngx_http_conf_get_module_main_conf (cf, ndk_http_module) 42 | #define ndk_http_get_main_conf(r) ngx_http_get_module_main_conf (r, ndk_http_module) 43 | 44 | typedef struct { 45 | #if (NDK_UPSTREAM_LIST) 46 | ngx_array_t *upstreams; 47 | #endif 48 | } ndk_http_main_conf_t; 49 | 50 | #endif /* NDK_HTTP_CREATE_MAIN_CONF */ 51 | 52 | #include 53 | 54 | 55 | extern ngx_module_t ndk_http_module; 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_buf.c: -------------------------------------------------------------------------------- 1 | 2 | ngx_int_t 3 | ndk_copy_chain_to_str (ngx_pool_t *pool, ngx_chain_t *in, ngx_str_t *str) 4 | { 5 | ngx_chain_t *cl; 6 | size_t len; 7 | u_char *p; 8 | ngx_buf_t *b; 9 | 10 | len = 0; 11 | for (cl = in; cl; cl = cl->next) 12 | len += ngx_buf_size (cl->buf); 13 | 14 | ndk_palloc_re (p, pool, len + 1); 15 | 16 | str->data = p; 17 | str->len = len; 18 | 19 | for (cl = in; cl; cl = cl->next) { 20 | 21 | b = cl->buf; 22 | 23 | if (ngx_buf_in_memory (b)) { 24 | p = ngx_cpymem (p, b->pos, b->last - b->pos); 25 | } 26 | } 27 | 28 | *p = '\0'; 29 | 30 | return NGX_OK; 31 | } 32 | 33 | 34 | char * 35 | ndk_copy_chain_to_charp (ngx_pool_t *pool, ngx_chain_t *in) 36 | { 37 | ngx_str_t str; 38 | 39 | if (ndk_copy_chain_to_str (pool, in, &str) != NGX_OK) 40 | return NULL; 41 | 42 | return (char *) str.data; 43 | } -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_buf.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | ngx_int_t ndk_copy_chain_to_str (ngx_pool_t *pool, ngx_chain_t *in, ngx_str_t *str); 4 | char * ndk_copy_chain_to_charp (ngx_pool_t *pool, ngx_chain_t *in); 5 | 6 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_complex_path.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | typedef struct { 4 | ngx_array_t *a; 5 | ngx_uint_t prefix; 6 | } ndk_http_complex_path_t; 7 | 8 | typedef struct { 9 | ngx_http_complex_value_t val; 10 | ngx_flag_t dynamic; 11 | } ndk_http_complex_path_elt_t; 12 | 13 | typedef struct { 14 | ngx_str_t val; 15 | ngx_flag_t dynamic; 16 | } ndk_http_complex_path_value_t; 17 | 18 | typedef struct { 19 | ndk_http_complex_path_value_t *elts; 20 | ngx_uint_t nelts; 21 | } ndk_http_complex_path_values_t; 22 | 23 | 24 | extern ndk_http_complex_path_value_t ndk_empty_http_complex_path_value; 25 | 26 | 27 | ngx_array_t * ndk_http_complex_path_create_compile (ngx_conf_t *cf, ngx_str_t *path, ngx_uint_t prefix); 28 | ngx_int_t ndk_http_complex_path_value_compile (ngx_conf_t *cf, ngx_http_complex_value_t *cv, 29 | ngx_str_t *value, ngx_uint_t prefix); 30 | char * ndk_conf_set_http_complex_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 31 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_complex_value.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | typedef struct { 4 | ngx_str_t key; 5 | ngx_http_complex_value_t value; 6 | } ndk_http_complex_keyval_t; 7 | 8 | 9 | 10 | /* create/compile functions */ 11 | 12 | ngx_int_t ndk_http_complex_value_compile (ngx_conf_t *cf, ngx_http_complex_value_t *cv, ngx_str_t *value); 13 | ngx_array_t * ndk_http_complex_value_array_create (ngx_conf_t *cf, char **s, ngx_int_t n); 14 | ngx_int_t ndk_http_complex_value_array_compile (ngx_conf_t *cf, ngx_array_t *a); 15 | 16 | 17 | /* conf set slot functions */ 18 | 19 | char * ndk_conf_set_http_complex_keyval_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 20 | char * ndk_conf_set_http_complex_value_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 21 | char * ndk_conf_set_http_complex_value_array_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 22 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_encoding.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | char * 5 | ndk_conf_set_encoding_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf) 6 | { 7 | char *p = conf; 8 | 9 | ndk_encoding_t *ep; 10 | ngx_str_t *value; 11 | size_t len; 12 | iconv_t ic; 13 | 14 | ep = (ndk_encoding_t *) (p + cmd->offset); 15 | if (ep->from && ep->to) 16 | return "is duplicate"; 17 | 18 | value = cf->args->elts; 19 | 20 | 21 | if (ep->from) { 22 | 23 | ep->to = (char *) value[1].data; 24 | len = strlen (ep->from); 25 | 26 | } else if (ep->to) { 27 | 28 | ep->from = (char *) value[1].data; 29 | len = strlen (ep->to); 30 | 31 | } else { 32 | return "has no base encoding"; 33 | } 34 | 35 | 36 | if (len == value[1].len && !strncasecmp (ep->to, ep->from, len)) { 37 | 38 | ngx_log_error (NGX_LOG_WARN, cf->log, 0, 39 | "\"%V\" '%V' encoding is ignored (no conversion)", &value[0], &value[1]); 40 | 41 | return NGX_CONF_OK; 42 | } 43 | 44 | 45 | ic = iconv_open (ep->to, ep->from); 46 | if (ic == (iconv_t)-1) 47 | return "has an invalid encoding"; 48 | 49 | 50 | if (iconv_close (ic)) { 51 | ngx_log_error (NGX_LOG_EMERG, cf->log, errno, "iconv_close()"); 52 | return NGX_CONF_ERROR; 53 | } 54 | 55 | return NGX_CONF_OK; 56 | } 57 | 58 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_encoding.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include 4 | 5 | typedef struct { 6 | char *from; 7 | char *to; 8 | } ndk_encoding_t; 9 | 10 | 11 | char * ndk_conf_set_encoding_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 12 | 13 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_hash.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef NDK_HASH_H 3 | #define NDK_HASH_H 4 | 5 | #ifdef NDK_HASH_ALL 6 | 7 | #ifndef NDK_MD5 8 | #define NDK_MD5 9 | #endif 10 | 11 | #ifndef NDK_MURMUR2 12 | #define NDK_MURMUR2 13 | #endif 14 | 15 | #ifndef NDK_SHA1 16 | #define NDK_SHA1 17 | #endif 18 | 19 | #endif 20 | 21 | #include 22 | #include 23 | typedef void (*ndk_hash_pt) (u_char *p, char *data, size_t len); 24 | 25 | 26 | #ifdef NDK_MD5 27 | #include 28 | void ndk_md5_hash (u_char *p, char *data, size_t len); 29 | void ndk_md5_hash_upper (u_char *p, char *data, size_t len); 30 | #endif 31 | 32 | #ifdef NDK_MURMUR2 33 | #define MURMURHASH2_DIGEST_LENGTH 4 34 | void ndk_murmur2_hash (u_char *p, char *data, size_t len); 35 | void ndk_murmur2_hash_upper (u_char *p, char *data, size_t len); 36 | #endif 37 | 38 | #ifdef NDK_SHA1 39 | #include 40 | void ndk_sha1_hash (u_char *p, char *data, size_t len); 41 | void ndk_sha1_hash_upper (u_char *p, char *data, size_t len); 42 | #endif 43 | 44 | #endif /* NDK_HASH_H */ 45 | 46 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_http.h: -------------------------------------------------------------------------------- 1 | 2 | ngx_uint_t ndk_http_count_phase_handlers (ngx_http_core_main_conf_t *cmcf); 3 | ngx_uint_t ndk_http_parse_request_method (ngx_str_t *m); 4 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_log.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* TODO : the required functions if the compiler does not have variadic macros */ 4 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_path.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* path conversion functions */ 4 | 5 | void ndk_clean_path (ngx_str_t *path, ngx_uint_t complex, size_t off); 6 | void ndk_path_to_dir_safe (ngx_str_t *path, ngx_uint_t complex, size_t off); 7 | 8 | /* path create functions */ 9 | 10 | ngx_array_t * ndk_split_path_create (ngx_conf_t *cf, ngx_str_t *path); 11 | ngx_array_t * ndk_split_path_create_raw (ngx_conf_t *cf, char *path); 12 | 13 | /* conf set functions */ 14 | 15 | char * ndk_conf_set_full_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 16 | char * ndk_conf_set_split_path_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 17 | 18 | /* conf set post functions */ 19 | 20 | char * ndk_conf_set_full_path (ngx_conf_t *cf, void *data, ngx_str_t *path); 21 | char * ndk_conf_set_full_conf_path (ngx_conf_t *cf, void *data, ngx_str_t *path); 22 | 23 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_process.c: -------------------------------------------------------------------------------- 1 | 2 | ngx_int_t 3 | ndk_init_signals (ngx_signal_t *sig, ngx_log_t *log) 4 | { 5 | struct sigaction sa; 6 | 7 | for ( ; sig->signo != 0; sig++) { 8 | ndk_zerov (sa); 9 | sa.sa_handler = sig->handler; 10 | sigemptyset (&sa.sa_mask); 11 | 12 | if (sigaction (sig->signo, &sa, NULL) == -1) { 13 | ngx_log_error (NGX_LOG_EMERG, log, ngx_errno, 14 | "sigaction(%s) failed", sig->signame); 15 | return NGX_ERROR; 16 | } 17 | } 18 | 19 | return NGX_OK; 20 | } 21 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_process.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | typedef struct { 4 | int signo; 5 | char *signame; 6 | char *name; 7 | void (*handler)(int signo); 8 | } ngx_signal_t; 9 | 10 | 11 | ngx_int_t ndk_init_signals (ngx_signal_t *sig, ngx_log_t *log); 12 | 13 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_regex.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | char * ndk_conf_set_regex_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 4 | char * ndk_conf_set_regex_caseless_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 5 | char * ndk_conf_set_regex_array_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 6 | char * ndk_conf_set_regex_array_caseless_slot (ngx_conf_t *cf, ngx_command_t *cmd, void *conf); 7 | 8 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_rewrite.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* TODO : should remove this when not needed */ 4 | 5 | 6 | 7 | /* used for plugging into the rewrite module (taken from the rewrite module) */ 8 | 9 | typedef struct { 10 | ngx_array_t *codes; /* uintptr_t */ 11 | ngx_uint_t stack_size; 12 | ngx_flag_t log; 13 | ngx_flag_t uninitialized_variable_warn; 14 | } ndk_http_rewrite_loc_conf_t; 15 | 16 | 17 | extern ngx_module_t ngx_http_rewrite_module; 18 | extern uintptr_t ndk_http_script_exit_code; 19 | 20 | char * ndk_http_rewrite_value (ngx_conf_t *cf, ndk_http_rewrite_loc_conf_t *lcf, 21 | ngx_str_t *value); 22 | ngx_int_t ndk_http_rewrite_var (ngx_http_request_t *r, 23 | ngx_http_variable_value_t *v, uintptr_t data); 24 | 25 | #define ndk_http_script_exit (u_char *) &ndk_http_script_exit_code 26 | 27 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_string.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #if 1 4 | /* TODO : set ndk_hex_dump for older versions of Nginx */ 5 | #define ndk_hex_dump ngx_hex_dump 6 | #endif 7 | 8 | typedef struct { 9 | size_t len; 10 | u_char *data; 11 | ngx_flag_t escaped; 12 | } ndk_estr_t; 13 | 14 | int64_t ndk_atoi64 (u_char *line, size_t n); 15 | 16 | ngx_int_t ndk_strcntc (ngx_str_t *s, char c); 17 | ngx_int_t ndk_strccnt (char *s, char c); 18 | ngx_array_t * ndk_str_array_create (ngx_pool_t *pool, char **s, ngx_int_t n); 19 | u_char * ndk_catstrf (ngx_pool_t *pool, ngx_str_t *dest, const char *fmt, ...); 20 | ngx_int_t ndk_cmpstr (ngx_str_t *s1, ngx_str_t *s2); 21 | u_char * ndk_dupstr (ngx_pool_t *pool, ngx_str_t *dest, ngx_str_t *src); 22 | 23 | static ngx_inline void 24 | ndk_strtoupper (u_char *p, size_t len) 25 | { 26 | u_char *e = p + len; 27 | for ( ; pdata = (u_char*) s; (ns)->len = sizeof (s) - 1;} 5 | 6 | #define ndk_zero(p,sz) memset (p,'\0',sz) 7 | #define ndk_zerop(p) ndk_zero (p,sizeof(*p)) 8 | #define ndk_zeropn(p,n) ndk_zero (p,sizeof(*p)*(n)) 9 | #define ndk_zerov(v) ndk_zero (&v,sizeof(v)) 10 | 11 | #define ngx_null_enum { ngx_null_string, 0 } 12 | 13 | #define ndk_memcpyp(d,s) ngx_memcpy(d,s,sizeof(s)) 14 | 15 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_upstream_list.h: -------------------------------------------------------------------------------- 1 | 2 | #if (NDK_UPSTREAM_LIST_CMDS) 3 | 4 | /* TODO : use the generated commands */ 5 | 6 | { 7 | ngx_string ("upstream_list"), 8 | NGX_HTTP_MAIN_CONF|NGX_HTTP_SRV_CONF|NGX_CONF_2MORE, 9 | ndk_upstream_list, 10 | 0, 11 | 0, 12 | NULL 13 | }, 14 | 15 | #else 16 | 17 | typedef struct { 18 | ngx_str_t **elts; 19 | ngx_uint_t nelts; 20 | ngx_str_t name; 21 | } ndk_upstream_list_t; 22 | 23 | 24 | ndk_upstream_list_t * 25 | ndk_get_upstream_list (ndk_http_main_conf_t *mcf, u_char *data, size_t len); 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_uri.c: -------------------------------------------------------------------------------- 1 | 2 | 3 | /* TODO : check that this is correct */ 4 | 5 | u_char * 6 | ndk_map_uri_to_path_add_suffix (ngx_http_request_t *r, ngx_str_t *path, ngx_str_t *suffix, ngx_int_t dot) 7 | { 8 | size_t root_size; 9 | u_char *p; 10 | 11 | if (suffix->len) { 12 | 13 | if (dot) { 14 | 15 | p = ngx_http_map_uri_to_path (r, path, &root_size, suffix->len + 1); 16 | 17 | if (p == NULL) 18 | return NULL; 19 | 20 | *p = '.'; 21 | p++; 22 | 23 | } else { 24 | 25 | p = ngx_http_map_uri_to_path (r, path, &root_size, suffix->len); 26 | 27 | if (p == NULL) 28 | return NULL; 29 | } 30 | 31 | path->len--; 32 | 33 | p = ngx_cpymem (p, suffix->data, suffix->len); 34 | *p = '\0'; 35 | 36 | return p; 37 | } 38 | 39 | p = ngx_http_map_uri_to_path (r, path, &root_size, 0); 40 | 41 | path->len--; 42 | 43 | return p; 44 | } 45 | 46 | -------------------------------------------------------------------------------- /dependence/ngx_devel_kit/src/ndk_uri.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | u_char * ndk_map_uri_to_path_add_suffix (ngx_http_request_t *r, ngx_str_t *path, ngx_str_t *suffix, ngx_int_t dot); 5 | 6 | 7 | -------------------------------------------------------------------------------- /docker/hook/proxy.rb: -------------------------------------------------------------------------------- 1 | # location /proxy { 2 | # mruby_set $backend "/path/to/proxy.rb"; 3 | # proxy_pass http://$backend; 4 | # } 5 | 6 | backends = [ 7 | "127.0.0.1:80", 8 | ] 9 | 10 | unless ENV["PROXY1_PORT_80_TCP_ADDR"].nil? 11 | backends << ENV["PROXY1_PORT_80_TCP_ADDR"] + ":" + ENV["PROXY1_PORT_80_TCP_PORT"] 12 | end 13 | 14 | unless ENV["PROXY2_PORT_80_TCP_ADDR"].nil? 15 | backends << ENV["PROXY2_PORT_80_TCP_ADDR"] + ":" + ENV["PROXY2_PORT_80_TCP_PORT"] 16 | end 17 | 18 | unless ENV["PROXY3_PORT_80_TCP_ADDR"].nil? 19 | backends << ENV["PROXY3_PORT_80_TCP_ADDR"] + ":" + ENV["PROXY3_PORT_80_TCP_PORT"] 20 | end 21 | 22 | uri = '/mruby-hello' 23 | 24 | backends[rand(backends.length)] + uri 25 | -------------------------------------------------------------------------------- /docker/hook/test.rb: -------------------------------------------------------------------------------- 1 | Nginx.echo "This is test for ngx_mruby" 2 | -------------------------------------------------------------------------------- /docs/test/README.md: -------------------------------------------------------------------------------- 1 | ngx_mruby test uses mruby test. 2 | ngx_mruby test is very earlier and experimental version. 3 | 4 | Welcome pull-request! 5 | ## Add test 6 | ##### Add location config to ``test/conf/nginx.conf`` 7 | ```nginx 8 | # Nginx.hello test 9 | location /mruby { 10 | mruby_content_handler build/nginx/html/unified_hello.rb cache; 11 | } 12 | ``` 13 | ##### Add hook script into ``test/html/`` if you need the script for location config 14 | ```ruby 15 | # test/htdocs/unified_hello.rb 16 | if server_name == "NGINX" 17 | Server = Nginx 18 | elsif server_name == "Apache" 19 | Server = Apache 20 | end 21 | 22 | Server::rputs "Hello #{Server::module_name}/#{Server::module_version} world!" 23 | ``` 24 | ##### Add test code to ``test/t/ngx_mruby.rb`` 25 | ```ruby 26 | assert('ngx_mruby', 'location /mruby') do 27 | res = HttpRequest.new.get base + '/mruby' 28 | assert_equal 'Hello ngx_mruby/0.0.1 world!', res["body"] 29 | end 30 | ``` 31 | ## Testing 32 | ##### build nginx into ``./build/nginx`` and test on ``./build/nginx`` 33 | ``` 34 | sh test.sh 35 | ``` 36 | 37 | If you want to run with valgrind, set the environment variables `NGINX_RUNNER` and `NGINX_HEATTIME`. 38 | 39 | ```console 40 | $ NGINX_RUNNER=valgrind NGINX_HEATTIME=10 sh test.sh 41 | ``` 42 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Example 2 | ```bash 3 | cp set.rb set2.rb unified_hello.rb ${DOCROOT}/. 4 | cp nginx.conf ${NGINX_CONF_DIR}/. 5 | ``` 6 | access some locations in nginx.conf 7 | -------------------------------------------------------------------------------- /example/proxy.rb: -------------------------------------------------------------------------------- 1 | # location /proxy { 2 | # mruby_set $backend "/path/to/proxy.rb"; 3 | # proxy_pass http://$backend; 4 | # } 5 | 6 | backends = [ 7 | "test1", 8 | "test2", 9 | "test3", 10 | ] 11 | 12 | r = Redis.new "192.168.12.251", 6379 13 | r.get backends[rand(backends.length)] 14 | -------------------------------------------------------------------------------- /example/set.rb: -------------------------------------------------------------------------------- 1 | r = Nginx::Request.new 2 | 3 | r.var.fuga.to_i * 2 4 | -------------------------------------------------------------------------------- /example/set2.rb: -------------------------------------------------------------------------------- 1 | r = Nginx::Request.new 2 | 3 | Nginx.rputs "fuga => #{r.var.fuga} " 4 | Nginx.rputs "hoge => #{r.var.hoge} " 5 | 6 | r.var.set "hoge", r.var.hoge.to_i * 2 7 | Nginx.rputs "hoge => #{r.var.hoge} " 8 | 9 | -------------------------------------------------------------------------------- /example/unified_hello.rb: -------------------------------------------------------------------------------- 1 | # Unified Ruby Code between Apache(mod_mruby) and nginx(ngx_mruby) 2 | # for Web server extensions. 3 | # 4 | # Apache httpd.conf by mod_mruby 5 | # 6 | # 7 | # mrubyHandlerMiddle "/path/to/unified_hello.rb" 8 | # 9 | # 10 | # nginx nginx.conf by ngx_mruby 11 | # 12 | # location /mruby { 13 | # mruby_content_handler "/path/to/unified_hello.rb"; 14 | # } 15 | # 16 | 17 | if server_name == "NGINX" 18 | Server = Nginx 19 | elsif server_name == "Apache" 20 | Server = Apache 21 | end 22 | 23 | Server::rputs "Hello #{Server::module_name}/#{Server::module_version} world!" 24 | # mod_mruby => "Hello mod_mruby/0.9.3 world!" 25 | # ngx_mruby => "Hello ngx_mruby/0.0.1 world!" 26 | -------------------------------------------------------------------------------- /misc/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/ngx_mruby/bed251036c0f273fb42fa9e84c00767b15983956/misc/logo.png -------------------------------------------------------------------------------- /mrbgems/auto-ssl/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('auto-ssl') do |spec| 2 | spec.license = 'MIT' 3 | spec.authors = 'MATSUMOTO Ryosuke' 4 | spec.add_dependency('mruby-io', :github => 'iij/mruby-io') 5 | spec.add_dependency('mruby-acme-client', :github => 'pyama86/mruby-acme-client') 6 | spec.add_dependency('mruby-sleep', :github => 'matsumotory/mruby-sleep') 7 | end 8 | -------------------------------------------------------------------------------- /mrbgems/auto-ssl/test/mrb_nginx.rb: -------------------------------------------------------------------------------- 1 | ## 2 | ## Nginx Test 3 | ## 4 | 5 | -------------------------------------------------------------------------------- /mrbgems/ngx_mruby_mrblib/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-ngx-mruby-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.authors = 'MATSUMOTO Ryosuke' 4 | end 5 | -------------------------------------------------------------------------------- /mrbgems/ngx_mruby_mrblib/test/mrb_nginx.rb: -------------------------------------------------------------------------------- 1 | ## 2 | ## Nginx Test 3 | ## 4 | 5 | -------------------------------------------------------------------------------- /mrbgems/rack-based-api/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('rack-based-api') do |spec| 2 | spec.license = 'MIT' 3 | spec.authors = 'MATSUMOTO Ryosuke' 4 | spec.add_dependency('mruby-stringio', :github => 'ksss/mruby-stringio') 5 | end 6 | -------------------------------------------------------------------------------- /mrbgems/rack-based-api/test/mrb_nginx.rb: -------------------------------------------------------------------------------- 1 | ## 2 | ## Nginx Test 3 | ## 4 | 5 | -------------------------------------------------------------------------------- /mruby/.dockerignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | .idea 3 | .vscode 4 | *.bak 5 | *.iml 6 | *.ipr 7 | *.swp 8 | *.tmp 9 | 10 | /.yardoc 11 | /bin 12 | /build 13 | /doc/api 14 | /doc/capi 15 | -------------------------------------------------------------------------------- /mruby/.editorconfig: -------------------------------------------------------------------------------- 1 | # About this file, see: 2 | # Website: https://editorconfig.org/ 3 | # For Emacs users: https://github.com/editorconfig/editorconfig-emacs 4 | # For Vim users: https://github.com/editorconfig/editorconfig-vim 5 | 6 | root = true 7 | 8 | [*] 9 | charset = utf-8 10 | end_of_line = lf 11 | indent_size = 2 12 | indent_style = space 13 | insert_final_newline = true 14 | tab_width = 8 15 | trim_trailing_whitespace = true 16 | 17 | [{Makefile,Makefile.*,makefile,*.mk}] 18 | indent_style = tab 19 | #max_line_length = 80 20 | 21 | #[*.{c,cc,C,cxx,cpp,h,hh,H,hxx,hpp,inc,y}] 22 | #max_line_length = 120 23 | 24 | #[{*.rb,Rakefile,rakefile,*.rake,*.gemspec,*.gembox}] 25 | #max_line_length = 120 26 | 27 | # limitation to US-ASCII 28 | [*.bat] 29 | end_of_line = crlf 30 | #max_line_length = 80 31 | 32 | #[*.{yaml,yml}] 33 | 34 | #[*.md] 35 | -------------------------------------------------------------------------------- /mruby/.git-blame-ignore-revs: -------------------------------------------------------------------------------- 1 | # Extend the tab with 8 whitespace 2 | 6fc5dc986a5ffc1a74c63ad0617ea1dcc10d3cdd 3 | # reformatted doc/opcode.md 4 | 61e8a540869c57ebddac53cf9d243db407d57fff 5 | # reindent parse.y 6 | 650ffb9d8410e1ae2206890ef6e2a8643c600454 7 | -------------------------------------------------------------------------------- /mruby/.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | *.bat text eol=crlf 3 | *.cmd text eol=crlf 4 | *.png binary 5 | -------------------------------------------------------------------------------- /mruby/.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # Basic set up 2 | version: 2 3 | updates: 4 | # Maintain dependencies for Ruby 5 | - package-ecosystem: "bundler" 6 | directory: "/" 7 | schedule: 8 | interval: "daily" 9 | # Maintain dependencies for GitHub Actions 10 | - package-ecosystem: "github-actions" 11 | directory: "/" 12 | schedule: 13 | interval: "daily" 14 | -------------------------------------------------------------------------------- /mruby/.github/linters/.ecrc: -------------------------------------------------------------------------------- 1 | { 2 | "verbose": false, 3 | "ignore_defaults": false, 4 | "exclude": ["oss-fuzz/", "src/"], 5 | "disable": { 6 | "end_of_line": false, 7 | "trim_trailing_whitespace": false, 8 | "insert_final_newline": false, 9 | "indent_size": true, 10 | "indent_style": true 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /mruby/.github/linters/.markdown-lint.yml: -------------------------------------------------------------------------------- 1 | # https://github.com/DavidAnson/markdownlint#rules--aliases 2 | # markdownlint -c .github/linters/.markdown-lint.yml . 3 | 4 | # MD001 heading-increment/header-increment - Heading levels should only increment by one level at a time 5 | MD001: false 6 | 7 | # MD013 line-length - Line length 8 | MD013: false 9 | 10 | # MD014 commands-show-output - Dollar signs used before commands without showing output 11 | MD014: false 12 | 13 | # MD024 no-duplicate-heading/no-duplicate-header - Multiple headings with the same content 14 | MD024: false 15 | 16 | # MD025 single-title/single-h1 - Multiple top-level headings in the same document 17 | MD025: false 18 | 19 | # MD026 no-trailing-punctuation - Trailing punctuation in heading 20 | MD026: false 21 | 22 | # MD033/no-inline-html - Inline HTML 23 | MD033: false 24 | 25 | # MD040 fenced-code-language - Fenced code blocks should have a language specified 26 | MD040: false 27 | 28 | # MD041 first-line-heading/first-line-h1 - First line in a file should be a top-level heading 29 | MD041: false 30 | -------------------------------------------------------------------------------- /mruby/.github/linters/.yaml-lint.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # https://yamllint.readthedocs.io/en/stable/ 3 | # yamllint --strict -c .github/linters/.yaml-lint.yml . 4 | extends: default 5 | 6 | rules: 7 | comments: 8 | min-spaces-from-content: 1 9 | document-start: disable 10 | line-length: disable 11 | truthy: false 12 | -------------------------------------------------------------------------------- /mruby/.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | # https://github.com/actions/labeler 2 | name: Pull Request Labeler 3 | on: 4 | - pull_request_target 5 | jobs: 6 | triage: 7 | permissions: 8 | contents: read 9 | pull-requests: write 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/labeler@v5 13 | with: 14 | repo-token: "${{ secrets.GITHUB_TOKEN }}" 15 | sync-labels: true 16 | -------------------------------------------------------------------------------- /mruby/.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | # https://pre-commit.com/ 2 | name: Lint 3 | 4 | on: [pull_request] 5 | 6 | permissions: 7 | contents: read 8 | 9 | jobs: 10 | pre-commit: 11 | name: Run pre-commit 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" 15 | uses: actions/checkout@v4 16 | - name: Install 17 | run: | 18 | python -m pip install --upgrade pip 19 | pip install pre-commit 20 | - name: Set PY 21 | run: echo "PY=$(python -VV | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV 22 | - uses: actions/cache@v4 23 | with: 24 | path: ~/.cache/pre-commit 25 | key: pre-commit|${{ env.PY }}|${{ hashFiles('.pre-commit-config.yaml') }} 26 | - name: Run pre-commit 27 | run: pre-commit run --all-files 28 | -------------------------------------------------------------------------------- /mruby/.github/workflows/oss-fuzz.yml: -------------------------------------------------------------------------------- 1 | # https://github.com/google/oss-fuzz 2 | name: CIFuzz 3 | on: [pull_request] 4 | permissions: 5 | contents: read 6 | 7 | jobs: 8 | Fuzzing: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Build Fuzzers 12 | uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master 13 | with: 14 | oss-fuzz-project-name: "mruby" 15 | dry-run: false 16 | - name: Run Fuzzers 17 | uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master 18 | with: 19 | oss-fuzz-project-name: "mruby" 20 | fuzz-seconds: 600 21 | dry-run: false 22 | - name: Upload Crash 23 | uses: actions/upload-artifact@v4 24 | if: failure() 25 | with: 26 | name: artifacts 27 | path: ./out/artifacts 28 | -------------------------------------------------------------------------------- /mruby/.github/workflows/super-linter.yml: -------------------------------------------------------------------------------- 1 | # https://github.com/super-linter/super-linter 2 | name: Super-Linter 3 | 4 | on: [pull_request] 5 | 6 | permissions: 7 | contents: read 8 | 9 | jobs: 10 | build: 11 | permissions: 12 | contents: read # for actions/checkout to fetch code 13 | statuses: write # for github/super-linter/slim to mark status of each linter run 14 | name: Lint Code Base 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: "Checkout ${{ github.ref }} ( ${{ github.sha }} )" 18 | uses: actions/checkout@v4 19 | with: 20 | # Full git history is needed to get a proper list of changed files within `super-linter` 21 | fetch-depth: 0 22 | - name: Lint Code Base 23 | uses: super-linter/super-linter/slim@v6.0.0 24 | env: 25 | VALIDATE_BASH: true 26 | # VALIDATE_BASH_EXEC: true 27 | # VALIDATE_EDITORCONFIG: true 28 | # VALIDATE_SHELL_SHFMT: true 29 | DEFAULT_BRANCH: master 30 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 31 | VALIDATE_ALL_CODEBASE: false 32 | -------------------------------------------------------------------------------- /mruby/.gitignore: -------------------------------------------------------------------------------- 1 | *.bak 2 | *.bc 3 | *.d 4 | *.i 5 | *.lock 6 | *.o 7 | *.orig 8 | *.pdb 9 | *.rej 10 | *.s 11 | *.sav 12 | *.swp 13 | *.tmp 14 | *~ 15 | .DS_Store 16 | .ccls* 17 | .ccmalloc 18 | .svn 19 | .vscode 20 | .yardoc 21 | /.git 22 | /benchmark/**/*.dat 23 | /benchmark/*.pdf 24 | /benchmark/*.png 25 | /bin 26 | /build 27 | /doc/api 28 | /doc/capi 29 | /mruby-source-*.gem 30 | compile_commands.json 31 | compile_flags.txt 32 | cscope.files 33 | cscope.out 34 | node_modules 35 | tags 36 | !Gemfile.lock 37 | -------------------------------------------------------------------------------- /mruby/.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "bracketSpacing": false 3 | } 4 | -------------------------------------------------------------------------------- /mruby/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | jobs: 4 | - os: linux 5 | - os: osx 6 | 7 | env: 8 | - MRUBY_CONFIG=ci/gcc-clang 9 | 10 | script: 11 | - rake -m test:build && rake test:run 12 | -------------------------------------------------------------------------------- /mruby/.yardopts: -------------------------------------------------------------------------------- 1 | --markup markdown 2 | --plugin mruby 3 | --plugin coderay 4 | --output-dir doc/api 5 | 6 | src/**/*.c 7 | mrblib/**/*.rb 8 | include/**/*.h 9 | 10 | mrbgems/*/src/**/*.c 11 | mrbgems/*/mrblib/**/*.rb 12 | mrbgems/*/include/**/*.h 13 | - 14 | CONTRIBUTING.md 15 | SECURITY.md 16 | TODO.md 17 | doc/*.md 18 | doc/guides/*.md 19 | doc/internal/*.md 20 | AUTHORS 21 | LEGAL 22 | LICENSE 23 | NEWS 24 | -------------------------------------------------------------------------------- /mruby/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @matz 2 | -------------------------------------------------------------------------------- /mruby/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM ruby:3.2.2-bullseye 2 | 3 | RUN apt-get update && apt-get install --no-install-recommends -y python3-pip shellcheck \ 4 | && apt-get clean \ 5 | && rm -rf /var/lib/apt/lists/* 6 | 7 | WORKDIR /app 8 | 9 | COPY Gemfile Gemfile.lock .pre-commit-config.yaml ./ 10 | 11 | RUN bundle install && pip3 install pre-commit && git init . && pre-commit install-hooks 12 | 13 | COPY . . 14 | -------------------------------------------------------------------------------- /mruby/Gemfile: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | source 'https://rubygems.org' 4 | 5 | gem 'rake' 6 | gem 'yard' 7 | gem 'yard-coderay' 8 | gem 'yard-mruby' 9 | -------------------------------------------------------------------------------- /mruby/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | coderay (1.1.3) 5 | rake (13.0.6) 6 | webrick (1.7.0) 7 | yard (0.9.28) 8 | webrick (~> 1.7.0) 9 | yard-coderay (0.1.0) 10 | coderay 11 | yard 12 | yard-mruby (0.3.0) 13 | yard (~> 0.9.0) 14 | 15 | PLATFORMS 16 | ruby 17 | x86_64-darwin-21 18 | x86_64-linux 19 | 20 | DEPENDENCIES 21 | rake 22 | yard 23 | yard-coderay 24 | yard-mruby 25 | 26 | BUNDLED WITH 27 | 2.4.10 28 | -------------------------------------------------------------------------------- /mruby/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2010- mruby developers 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a 4 | copy of this software and associated documentation files (the "Software"), 5 | to deal in the Software without restriction, including without limitation 6 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 7 | and/or sell copies of the Software, and to permit persons to whom the 8 | Software is furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 18 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 19 | DEALINGS IN THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /mruby/Makefile: -------------------------------------------------------------------------------- 1 | # mruby is using Rake (https://ruby.github.io/rake/) as a build tool. 2 | 3 | RAKE = rake 4 | 5 | all : 6 | $(RAKE) 7 | .PHONY : all 8 | 9 | test : all 10 | $(RAKE) test 11 | .PHONY : test 12 | 13 | clean : 14 | $(RAKE) clean 15 | .PHONY : clean 16 | 17 | check : 18 | pre-commit run --all-files 19 | .PHONY : check 20 | 21 | checkinstall : 22 | pre-commit install 23 | .PHONY : checkinstall 24 | 25 | checkupdate : 26 | pre-commit autoupdate 27 | .PHONY : checkupdate 28 | 29 | composecheck : 30 | docker-compose -p mruby run test pre-commit run --all-files 31 | .PHONY : composecheck 32 | 33 | composetest : 34 | docker-compose -p mruby run test 35 | .PHONY : composetest 36 | -------------------------------------------------------------------------------- /mruby/SECURITY.md: -------------------------------------------------------------------------------- 1 | # Security Policy 2 | 3 | ## Reporting a Vulnerability 4 | 5 | If you have any security concern, contact . 6 | 7 | ## Scope 8 | 9 | We consider the following issues as vulnerabilities: 10 | 11 | - Remote code execution 12 | - Crash caused by a valid Ruby script 13 | 14 | We _don't_ consider the following issues as vulnerabilities: 15 | 16 | - Runtime C undefined behavior (including integer overflow) 17 | - Crash caused by misused API 18 | - Crash caused by modified compiled binary 19 | - ASAN/Valgrind warning for too big memory allocation 20 | mruby assumes `malloc(3)` returns `NULL` for too big allocations 21 | -------------------------------------------------------------------------------- /mruby/TODO.md: -------------------------------------------------------------------------------- 1 | # Things to Do in the future 2 | 3 | # After mruby 3.1 4 | 5 | - parser and code generator independent from `mrb_state` (picoruby?) 6 | - variable sized AST node 7 | - iv/hash entry cache 8 | - more peephole optimization (if possible) 9 | 10 | # Things to do (Things we need to consider) 11 | 12 | - `begin ... end while cond` to behave as CRuby 13 | - special variables ($1,$2..) 14 | -------------------------------------------------------------------------------- /mruby/benchmark/bm_fib.rb: -------------------------------------------------------------------------------- 1 | def fib n 2 | return n if n < 2 3 | fib(n-2) + fib(n-1) 4 | end 5 | 6 | puts fib(37) 7 | -------------------------------------------------------------------------------- /mruby/benchmark/bm_so_lists.rb: -------------------------------------------------------------------------------- 1 | # from http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby 2 | # which is lost long time ago. The past content can be retrieved from 3 | # https://web.archive.org/web/20040805115204/http://www.bagley.org/~doug/shootout/bench/lists/lists.ruby 4 | 5 | NUM = 300 6 | SIZE = 10000 7 | 8 | def test_lists 9 | # create a list of integers (Li1) from 1 to SIZE 10 | li1 = (1..SIZE).to_a 11 | # copy the list to li2 (not by individual items) 12 | li2 = li1.dup 13 | # remove each individual item from left side of li2 and 14 | # append to right side of li3 (preserving order) 15 | li3 = Array.new 16 | while (not li2.empty?) 17 | li3.push(li2.shift) 18 | end 19 | # li2 must now be empty 20 | # remove each individual item from right side of li3 and 21 | # append to right side of li2 (reversing list) 22 | until li3.empty? 23 | li2.push(li3.pop) 24 | end 25 | # li3 must now be empty 26 | # reverse li1 in place 27 | li1.reverse! 28 | # check that first item is now SIZE 29 | if li1[0] != SIZE 30 | p "not SIZE" 31 | 0 32 | else 33 | # compare li1 and li2 for equality 34 | if li1 != li2 35 | return(0) 36 | else 37 | # return the length of the list 38 | li1.length 39 | end 40 | end 41 | end 42 | 43 | i = 0 44 | while i 'arm64-v8a', 5 | :sdk_version => 33, 6 | :toolchain => :clang 7 | } 8 | toolchain :android, params 9 | 10 | conf.gembox 'default' 11 | end 12 | -------------------------------------------------------------------------------- /mruby/build_config/android_armeabi_v7a_neon_hard.rb: -------------------------------------------------------------------------------- 1 | # Requires Android NDK r13 or later. 2 | MRuby::CrossBuild.new('android-armeabi-v7a-neon-hard') do |conf| 3 | params = { 4 | :arch => 'armeabi-v7a', 5 | :mfpu => 'neon', 6 | :mfloat_abi => 'hard', 7 | :sdk_version => 33, 8 | :toolchain => :clang 9 | } 10 | toolchain :android, params 11 | 12 | conf.gembox 'default' 13 | end 14 | -------------------------------------------------------------------------------- /mruby/build_config/bench.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new('bench') do |conf| 2 | # Gets set by the VS command prompts. 3 | if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] 4 | toolchain :visualcpp 5 | else 6 | toolchain :gcc 7 | conf.cc.flags << '-O3' 8 | end 9 | 10 | conf.gembox 'default' 11 | end 12 | -------------------------------------------------------------------------------- /mruby/build_config/boxing.rb: -------------------------------------------------------------------------------- 1 | boxings = %w[no word nan] 2 | bits = [64, 32] 3 | ints = [64, 32] 4 | 5 | boxings.product(bits, ints) do |boxing, bit, int| 6 | MRuby::Build.new("boxing-#{boxing}-m#{bit}-i#{int}") do |conf| 7 | conf.toolchain :gcc 8 | conf.gembox 'full-core' 9 | conf.compilers.each do |c| 10 | c.defines << "MRB_#{boxing.upcase}_BOXING" 11 | c.defines << "MRB_INT#{int}" 12 | c.flags << "-m#{bit}" 13 | end 14 | conf.linker.flags << "-m#{bit}" 15 | conf.enable_debug 16 | conf.enable_test 17 | conf.enable_bintest 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /mruby/build_config/ci/gcc-clang.rb: -------------------------------------------------------------------------------- 1 | STDOUT.sync = STDERR.sync = true unless Rake.application.options.always_multitask 2 | 3 | MRuby::Build.new('full-debug') do |conf| 4 | conf.toolchain 5 | conf.enable_debug 6 | 7 | # include all core GEMs 8 | conf.gembox 'full-core' 9 | conf.cc.defines += %w(MRB_GC_STRESS MRB_USE_DEBUG_HOOK MRB_UTF8_STRING) 10 | 11 | conf.enable_test 12 | end 13 | 14 | MRuby::Build.new do |conf| 15 | conf.toolchain 16 | 17 | # include all core GEMs 18 | conf.gembox 'full-core' 19 | conf.gem :core => 'mruby-bin-debugger' 20 | conf.compilers.each do |c| 21 | c.defines += %w(MRB_GC_FIXED_ARENA MRB_UTF8_STRING) 22 | end 23 | conf.enable_bintest 24 | conf.enable_test 25 | end 26 | 27 | MRuby::Build.new('cxx_abi') do |conf| 28 | conf.toolchain 29 | 30 | conf.gembox 'full-core' 31 | conf.cc.flags += %w(-fpermissive -std=gnu++03) 32 | conf.compilers.each do |c| 33 | c.defines += %w(MRB_GC_FIXED_ARENA MRB_UTF8_STRING) 34 | end 35 | conf.enable_test 36 | 37 | conf.enable_cxx_abi 38 | 39 | conf.build_mrbc_exec 40 | end 41 | -------------------------------------------------------------------------------- /mruby/build_config/ci/msvc.rb: -------------------------------------------------------------------------------- 1 | STDOUT.sync = STDERR.sync = true unless Rake.application.options.always_multitask 2 | 3 | def setup_option(conf) 4 | conf.cc.compile_options.sub!(%r{/Zi }, "") unless ENV['CFLAGS'] 5 | conf.cxx.compile_options.sub!(%r{/Zi }, "") unless ENV['CFLAGS'] || ENV['CXXFLAGS'] 6 | conf.linker.flags << "/DEBUG:NONE" unless ENV['LDFLAGS'] 7 | end 8 | 9 | MRuby::Build.new do |conf| 10 | conf.toolchain :visualcpp 11 | 12 | # include all core GEMs 13 | conf.gembox 'full-core' 14 | conf.compilers.each do |c| 15 | c.defines += %w(MRB_GC_FIXED_ARENA) 16 | end 17 | setup_option(conf) 18 | conf.enable_bintest 19 | conf.enable_test 20 | end 21 | -------------------------------------------------------------------------------- /mruby/build_config/clang-asan.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | conf.toolchain :clang 3 | # include the GEM box 4 | conf.gembox 'full-core' 5 | 6 | # Turn on `enable_debug` for better debugging 7 | conf.enable_sanitizer "address,undefined" 8 | conf.enable_debug 9 | conf.enable_bintest 10 | conf.enable_test 11 | end 12 | -------------------------------------------------------------------------------- /mruby/build_config/cross-32bit.rb: -------------------------------------------------------------------------------- 1 | # Define cross build settings 2 | MRuby::CrossBuild.new('cross-32bit') do |conf| 3 | conf.toolchain :gcc 4 | 5 | conf.cc.flags << "-m32" 6 | conf.linker.flags << "-m32" 7 | 8 | # conf.build_mrbtest_lib_only 9 | 10 | conf.gem :core => "mruby-bin-mruby" 11 | conf.gem "#{MRUBY_ROOT}/examples/mrbgems/c_and_ruby_extension_example" 12 | 13 | conf.test_runner.command = 'env' 14 | end 15 | -------------------------------------------------------------------------------- /mruby/build_config/cross-mingw.rb: -------------------------------------------------------------------------------- 1 | # 2 | # Ubuntu 20.04 requires at least `gcc-mingw-w64-x86-64` package as a 3 | # cross compiler. 4 | # 5 | 6 | MRuby::CrossBuild.new("cross-mingw") do |conf| 7 | conf.toolchain :gcc 8 | conf.host_target = "x86_64-w64-mingw32" # required for `for_windows?` used by `mruby-socket` gem 9 | conf.cc.command = "#{conf.host_target}-gcc-posix" 10 | conf.linker.command = conf.cc.command 11 | conf.archiver.command = "#{conf.host_target}-gcc-ar" 12 | conf.exts.executable = ".exe" 13 | conf.gembox "default" 14 | end 15 | -------------------------------------------------------------------------------- /mruby/build_config/host-cxx.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | conf.toolchain 3 | 4 | # include the default GEMs 5 | conf.gembox 'default' 6 | 7 | # C compiler settings 8 | conf.cc.defines = %w(MRB_USE_DEBUG_HOOK) 9 | conf.enable_debug 10 | conf.enable_cxx_abi 11 | conf.enable_test 12 | end 13 | -------------------------------------------------------------------------------- /mruby/build_config/host-debug.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new('host') do |conf| 2 | # load specific toolchain settings 3 | conf.toolchain 4 | 5 | conf.enable_debug 6 | 7 | # include the default GEMs 8 | conf.gembox 'full-core' 9 | 10 | # C compiler settings 11 | conf.cc.defines = %w(MRB_USE_DEBUG_HOOK MRB_NO_BOXING MRB_UTF8_STRING) 12 | 13 | # Generate mruby debugger command (require mruby-eval) 14 | conf.gem :core => "mruby-bin-debugger" 15 | 16 | # test 17 | conf.enable_test 18 | # bintest 19 | conf.enable_bintest 20 | end 21 | -------------------------------------------------------------------------------- /mruby/build_config/host-f32.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | # load specific toolchain settings 3 | toolchain :gcc 4 | 5 | # include the GEM box 6 | conf.gembox 'full-core' 7 | 8 | conf.cc.defines << 'MRB_USE_FLOAT32' 9 | 10 | # Turn on `enable_debug` for better debugging 11 | conf.enable_debug 12 | conf.enable_test 13 | conf.enable_bintest 14 | end 15 | -------------------------------------------------------------------------------- /mruby/build_config/host-gprof.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | # load specific toolchain settings 3 | toolchain :gcc 4 | 5 | # include the GEM box 6 | conf.gembox 'full-core' 7 | 8 | conf.cc.flags << '-pg' 9 | conf.linker.flags << '-pg' 10 | 11 | # Turn on `enable_debug` for better debugging 12 | conf.enable_debug 13 | conf.enable_test 14 | end 15 | -------------------------------------------------------------------------------- /mruby/build_config/host-m32.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | # load specific toolchain settings 3 | toolchain :gcc 4 | 5 | # include the GEM box 6 | conf.gembox 'full-core' 7 | 8 | conf.cc.flags << '-m32' 9 | conf.linker.flags << '-m32' 10 | 11 | # Turn on `enable_debug` for better debugging 12 | conf.enable_debug 13 | conf.enable_test 14 | conf.enable_bintest 15 | end 16 | -------------------------------------------------------------------------------- /mruby/build_config/host-nofloat.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | # load specific toolchain settings 3 | toolchain :gcc 4 | 5 | # include the GEM box 6 | conf.gembox "stdlib" 7 | conf.gembox "stdlib-ext" 8 | conf.gembox "stdlib-io" 9 | conf.gembox "metaprog" 10 | 11 | conf.gem :core => 'mruby-bin-mruby' 12 | conf.gem :core => 'mruby-bin-mirb' 13 | 14 | # Add configuration 15 | conf.compilers.each do |c| 16 | c.defines << "MRB_NO_FLOAT" 17 | end 18 | 19 | conf.enable_debug 20 | conf.enable_test 21 | conf.enable_bintest 22 | end 23 | -------------------------------------------------------------------------------- /mruby/build_config/host-shared.rb: -------------------------------------------------------------------------------- 1 | # NOTE: Currently, this configuration file does not support VisualC++! 2 | # Your help is needed! 3 | 4 | MRuby::Build.new do |conf| 5 | # load specific toolchain settings 6 | conf.toolchain 7 | 8 | # include the GEM box 9 | conf.gembox 'default' 10 | 11 | # C compiler settings 12 | conf.compilers.each do |cc| 13 | cc.flags << '-fPIC' 14 | end 15 | 16 | conf.archiver do |archiver| 17 | archiver.command = cc.command 18 | archiver.archive_options = '-shared -o %{outfile} %{objs}' 19 | end 20 | 21 | # file extensions 22 | conf.exts do |exts| 23 | exts.library = '.so' 24 | end 25 | 26 | # file separator 27 | # conf.file_separator = '/' 28 | 29 | # enable this if better compatibility with C++ is desired 30 | #conf.enable_cxx_exception 31 | 32 | # Turn on `enable_debug` for better debugging 33 | conf.enable_debug 34 | conf.enable_bintest 35 | conf.enable_test 36 | end 37 | -------------------------------------------------------------------------------- /mruby/build_config/minimal.rb: -------------------------------------------------------------------------------- 1 | MRuby::CrossBuild.new('minimal') do |conf| 2 | conf.toolchain :gcc 3 | conf.cc.defines << 'MRB_NO_STDIO' 4 | end 5 | -------------------------------------------------------------------------------- /mruby/build_config/mrbc.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] 3 | conf.toolchain :visualcpp 4 | else 5 | conf.toolchain :gcc 6 | end 7 | 8 | conf.build_mrbc_exec 9 | conf.disable_libmruby 10 | conf.disable_presym 11 | end 12 | -------------------------------------------------------------------------------- /mruby/build_config/serenity.rb: -------------------------------------------------------------------------------- 1 | # Cross compiling configuration for SerenityOS 2 | # Graphical Unix-like operating system for x86 computers. 3 | # https://github.com/SerenityOS/serenity 4 | # 5 | # Should be built using the SerenityOS Ports system 6 | # https://github.com/SerenityOS/serenity/tree/master/Ports 7 | # 8 | # As of 2021/08/20, SERENITY_ARCH is defined in the SerenityOS Ports 9 | # build script to always be either "i686" or "x86_64" 10 | 11 | MRuby::CrossBuild.new('serenity') do |conf| 12 | conf.toolchain :gcc 13 | 14 | conf.archiver.command = "#{ENV['SERENITY_ARCH']}-pc-serenity-ar" 15 | conf.linker.command = "#{ENV['SERENITY_ARCH']}-pc-serenity-g++" 16 | 17 | conf.cxx.command = "#{ENV['SERENITY_ARCH']}-pc-serenity-g++" 18 | conf.cxx.defines << (ENV['SERENITY_ARCH'].include?('64') ? 'MRB_64BIT' : 'MRB_32BIT') 19 | 20 | conf.cc.command = "#{ENV['SERENITY_ARCH']}-pc-serenity-gcc" 21 | conf.cc.defines << (ENV['SERENITY_ARCH'].include?('64') ? 'MRB_64BIT' : 'MRB_32BIT') 22 | 23 | conf.gembox 'full-core' 24 | 25 | conf.test_runner.command = 'env' 26 | end 27 | -------------------------------------------------------------------------------- /mruby/codespell.txt: -------------------------------------------------------------------------------- 1 | ans 2 | celler 3 | clen 4 | delet 5 | disabl 6 | filetest 7 | fo 8 | hel 9 | ist 10 | nd 11 | quitt 12 | remore 13 | runn 14 | sting 15 | strin 16 | wronly 17 | -------------------------------------------------------------------------------- /mruby/doc/mruby_logo_red_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/ngx_mruby/bed251036c0f273fb42fa9e84c00767b15983956/mruby/doc/mruby_logo_red_icon.png -------------------------------------------------------------------------------- /mruby/docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: "3.8" 2 | services: 3 | test: 4 | build: 5 | context: . 6 | command: sh -c 'rake deep_clean && rake -m test:build && rake test:run' 7 | environment: 8 | - MRUBY_CONFIG=ci/gcc-clang 9 | - CC=gcc 10 | - CXX=g++ 11 | - LD=gcc 12 | - SKIP=check-executables-have-shebangs 13 | working_dir: /app 14 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_and_ruby_extension_example/README.md: -------------------------------------------------------------------------------- 1 | # C and Ruby Extension Example 2 | 3 | This is an example gem which implements a C and Ruby extension. 4 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_and_ruby_extension_example/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('c_and_ruby_extension_example') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | 5 | # Add compile flags 6 | # spec.cc.flags << '' 7 | 8 | # Add cflags to all 9 | # spec.mruby.cc.flags << '-g' 10 | 11 | # Add libraries 12 | # spec.linker.libraries << 'external_lib' 13 | 14 | # Default build files 15 | # spec.rbfiles = Dir.glob("#{dir}/mrblib/*.rb") 16 | # spec.objs = Dir.glob("#{dir}/src/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) } 17 | # spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb") 18 | # spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) } 19 | # spec.test_preload = 'test/assert.rb' 20 | 21 | # Values accessible as TEST_ARGS inside test scripts 22 | # spec.test_args = {'tmp_dir' => Dir::tmpdir} 23 | end 24 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb: -------------------------------------------------------------------------------- 1 | module CRubyExtension 2 | def CRubyExtension.ruby_method 3 | puts "#{self}: A Ruby Extension" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_and_ruby_extension_example/src/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static mrb_value 6 | mrb_c_method(mrb_state *mrb, mrb_value self) 7 | { 8 | mrb_ensure_string_type(mrb, self); 9 | printf("%s: A C Extension\n", mrb_str_to_cstr(mrb, self)); 10 | 11 | return self; 12 | } 13 | 14 | void 15 | mrb_c_and_ruby_extension_example_gem_init(mrb_state* mrb) { 16 | struct RClass *class_cextension = mrb_define_module(mrb, "CRubyExtension"); 17 | mrb_define_class_method(mrb, class_cextension, "c_method", mrb_c_method, MRB_ARGS_NONE()); 18 | } 19 | 20 | void 21 | mrb_c_and_ruby_extension_example_gem_final(mrb_state* mrb) { 22 | /* finalizer */ 23 | } 24 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_and_ruby_extension_example/test/example.rb: -------------------------------------------------------------------------------- 1 | assert('C and Ruby Extension Example 1') do 2 | CRubyExtension.respond_to? :c_method 3 | end 4 | 5 | assert('C and Ruby Extension Example 2') do 6 | CRubyExtension.respond_to? :ruby_method 7 | end 8 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_extension_example/README.md: -------------------------------------------------------------------------------- 1 | # C Extension Example 2 | 3 | This is an example gem which implements a C extension. 4 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_extension_example/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('c_extension_example') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | 5 | # Add compile flags 6 | # spec.cc.flags << '-g' 7 | 8 | # Add cflags to all 9 | # spec.mruby.cc.flags << '-g' 10 | 11 | # Add libraries 12 | # spec.linker.libraries << 'external_lib' 13 | 14 | # Default build files 15 | # spec.rbfiles = Dir.glob("#{dir}/mrblib/*.rb") 16 | # spec.objs = Dir.glob("#{dir}/src/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) } 17 | # spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb") 18 | # spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) } 19 | # spec.test_preload = 'test/assert.rb' 20 | 21 | # Values accessible as TEST_ARGS inside test scripts 22 | # spec.test_args = {'tmp_dir' => Dir::tmpdir} 23 | end 24 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_extension_example/src/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | static mrb_value 6 | mrb_c_method(mrb_state *mrb, mrb_value self) 7 | { 8 | mrb_ensure_string_type(mrb, self); 9 | printf("%s: A C Extension\n", mrb_str_to_cstr(mrb, self)); 10 | 11 | return self; 12 | } 13 | 14 | void 15 | mrb_c_extension_example_gem_init(mrb_state* mrb) { 16 | struct RClass *class_cextension = mrb_define_module(mrb, "CExtension"); 17 | mrb_define_class_method(mrb, class_cextension, "c_method", mrb_c_method, MRB_ARGS_NONE()); 18 | } 19 | 20 | void 21 | mrb_c_extension_example_gem_final(mrb_state* mrb) { 22 | /* finalizer */ 23 | } 24 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_extension_example/test/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void 4 | mrb_c_extension_example_gem_test(mrb_state *mrb) 5 | { 6 | /* test initializer in C */ 7 | } 8 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_extension_example/test/example.rb: -------------------------------------------------------------------------------- 1 | assert('C Extension Example') do 2 | CExtension.respond_to? :c_method 3 | end 4 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/cdata_extension_example/README.md: -------------------------------------------------------------------------------- 1 | # C Data Extension Example 2 | 3 | This is an example gem which implements a C extension with Data. 4 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/cdata_extension_example/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('cdata_extension_example') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | 5 | # Add compile flags 6 | # spec.cc.flags << '-g' 7 | 8 | # Add cflags to all 9 | # spec.mruby.cc.flags << '-g' 10 | 11 | # Add libraries 12 | # spec.linker.libraries << 'external_lib' 13 | 14 | # Default build files 15 | # spec.rbfiles = Dir.glob("#{dir}/mrblib/*.rb") 16 | # spec.objs = Dir.glob("#{dir}/src/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) } 17 | # spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb") 18 | # spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) } 19 | # spec.test_preload = 'test/assert.rb' 20 | 21 | # Values accessible as TEST_ARGS inside test scripts 22 | # spec.test_args = {'tmp_dir' => Dir::tmpdir} 23 | end 24 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/cdata_extension_example/test/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void 4 | mrb_cdata_extension_example_gem_test(mrb_state *mrb) 5 | { 6 | /* test initializer in C */ 7 | } 8 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/mruby-YOUR-bigint/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-bigint') do |spec| 2 | spec.author = 'YOUR-NAME-HERE' 3 | spec.license = 'YOUR-LICENSE-HERE' 4 | spec.summary = 'Yet another multi-precision Integer extension' 5 | spec.homepage = 'https://gem.example/for/mruby-YOUR-bigint' 6 | spec.build.defines << 'MRB_USE_BIGINT' 7 | #spec.build.linker.libraries << 'gmp' # when uses libgmp 8 | 9 | spec.build.libmruby_core_objs << Dir.glob(File.join(__dir__, 'core/**/*.c')).map { |fn| 10 | objfile(fn.relative_path_from(__dir__).pathmap("#{spec.build_dir}/%X")) 11 | } 12 | end 13 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/ruby_extension_example/README.md: -------------------------------------------------------------------------------- 1 | # Pure Ruby Extension Example 2 | 3 | This is an example gem which implements a pure Ruby extension. 4 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/ruby_extension_example/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('ruby_extension_example') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | 5 | # Add compile flags 6 | # spec.cc.flags << '' 7 | 8 | # Add cflags to all 9 | # spec.mruby.cc.flags << '-g' 10 | 11 | # Add libraries 12 | # spec.linker.libraries << 'external_lib' 13 | 14 | spec.add_dependency('mruby-print', :core => 'mruby-print') 15 | 16 | # Default build files 17 | # spec.rbfiles = Dir.glob("#{dir}/mrblib/*.rb") 18 | # spec.objs = Dir.glob("#{dir}/src/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) } 19 | # spec.test_rbfiles = Dir.glob("#{dir}/test/*.rb") 20 | # spec.test_objs = Dir.glob("#{dir}/test/*.{c,cpp,m,asm,S}").map { |f| objfile(f.relative_path_from(dir).pathmap("#{build_dir}/%X")) } 21 | # spec.test_preload = 'test/assert.rb' 22 | 23 | # Values accessible as TEST_ARGS inside test scripts 24 | # spec.test_args = {'tmp_dir' => Dir::tmpdir} 25 | end 26 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/ruby_extension_example/mrblib/example.rb: -------------------------------------------------------------------------------- 1 | class RubyExtension 2 | def RubyExtension.ruby_method 3 | puts "#{self}: A Ruby Extension" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/ruby_extension_example/test/example.rb: -------------------------------------------------------------------------------- 1 | assert('Ruby Extension Example') do 2 | RubyExtension.respond_to? :ruby_method 3 | end 4 | -------------------------------------------------------------------------------- /mruby/include/mruby/endian.h: -------------------------------------------------------------------------------- 1 | /** 2 | ** @file mruby/endian.h - detect endian-ness 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #ifndef MRUBY_ENDIAN_H 8 | #define MRUBY_ENDIAN_H 9 | 10 | #include 11 | 12 | MRB_BEGIN_DECL 13 | 14 | #if !defined(BYTE_ORDER) && defined(__BYTE_ORDER__) 15 | # define BYTE_ORDER __BYTE_ORDER__ 16 | #endif 17 | #if !defined(BIG_ENDIAN) && defined(__ORDER_BIG_ENDIAN__) 18 | # define BIG_ENDIAN __ORDER_BIG_ENDIAN__ 19 | #endif 20 | #if !defined(LITTLE_ENDIAN) && defined(__ORDER_LITTLE_ENDIAN__) 21 | # define LITTLE_ENDIAN __ORDER_LITTLE_ENDIAN__ 22 | #endif 23 | 24 | #ifdef BYTE_ORDER 25 | # if BYTE_ORDER == BIG_ENDIAN 26 | # define littleendian 0 27 | # elif BYTE_ORDER == LITTLE_ENDIAN 28 | # define littleendian 1 29 | # endif 30 | #endif 31 | #ifndef littleendian 32 | /* can't distinguish endian in compile time */ 33 | static inline int 34 | check_little_endian(void) 35 | { 36 | unsigned int n = 1; 37 | return (*(unsigned char*)&n == 1); 38 | } 39 | # define littleendian check_little_endian() 40 | #endif 41 | 42 | MRB_END_DECL 43 | 44 | #endif /* MRUBY_ENDIAN_H */ 45 | -------------------------------------------------------------------------------- /mruby/include/mruby/istruct.h: -------------------------------------------------------------------------------- 1 | /** 2 | ** @file mruby/istruct.h - Inline structures 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #ifndef MRUBY_ISTRUCT_H 8 | #define MRUBY_ISTRUCT_H 9 | 10 | #include "common.h" 11 | #include 12 | 13 | /** 14 | * Inline structures that fit in RVALUE 15 | * 16 | * They cannot have finalizer, and cannot have instance variables. 17 | */ 18 | MRB_BEGIN_DECL 19 | 20 | #define ISTRUCT_DATA_SIZE (sizeof(void*) * 3) 21 | 22 | struct RIStruct { 23 | MRB_OBJECT_HEADER; 24 | union { 25 | intptr_t inline_alignment[3]; 26 | char inline_data[ISTRUCT_DATA_SIZE]; 27 | }; 28 | }; 29 | 30 | #define RISTRUCT(obj) ((struct RIStruct*)(mrb_ptr(obj))) 31 | #define ISTRUCT_PTR(obj) (RISTRUCT(obj)->inline_data) 32 | 33 | MRB_INLINE mrb_int mrb_istruct_size() 34 | { 35 | return ISTRUCT_DATA_SIZE; 36 | } 37 | 38 | MRB_INLINE void* mrb_istruct_ptr(mrb_value object) 39 | { 40 | return ISTRUCT_PTR(object); 41 | } 42 | 43 | MRB_INLINE void mrb_istruct_copy(mrb_value dest, mrb_value src) 44 | { 45 | memcpy(ISTRUCT_PTR(dest), ISTRUCT_PTR(src), ISTRUCT_DATA_SIZE); 46 | } 47 | 48 | MRB_END_DECL 49 | 50 | #endif /* MRUBY_ISTRUCT_H */ 51 | -------------------------------------------------------------------------------- /mruby/include/mruby/object.h: -------------------------------------------------------------------------------- 1 | /** 2 | ** @file mruby/object.h - mruby object definition 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #ifndef MRUBY_OBJECT_H 8 | #define MRUBY_OBJECT_H 9 | 10 | #define MRB_OBJECT_HEADER \ 11 | struct RClass *c; \ 12 | struct RBasic *gcnext; \ 13 | enum mrb_vtype tt:8; \ 14 | uint32_t color:3; \ 15 | uint32_t flags:21 16 | 17 | #define MRB_FLAG_TEST(obj, flag) ((obj)->flags & (flag)) 18 | 19 | struct RBasic { 20 | MRB_OBJECT_HEADER; 21 | }; 22 | #define mrb_basic_ptr(v) ((struct RBasic*)(mrb_ptr(v))) 23 | 24 | #define MRB_FL_OBJ_IS_FROZEN (1 << 20) 25 | #define MRB_FROZEN_P(o) ((o)->flags & MRB_FL_OBJ_IS_FROZEN) 26 | #define MRB_SET_FROZEN_FLAG(o) ((o)->flags |= MRB_FL_OBJ_IS_FROZEN) 27 | #define MRB_UNSET_FROZEN_FLAG(o) ((o)->flags &= ~MRB_FL_OBJ_IS_FROZEN) 28 | #define mrb_frozen_p(o) MRB_FROZEN_P(o) 29 | 30 | struct RObject { 31 | MRB_OBJECT_HEADER; 32 | struct iv_tbl *iv; 33 | }; 34 | #define mrb_obj_ptr(v) ((struct RObject*)(mrb_ptr(v))) 35 | 36 | #define mrb_special_const_p(x) mrb_immediate_p(x) 37 | 38 | struct RFiber { 39 | MRB_OBJECT_HEADER; 40 | struct mrb_context *cxt; 41 | }; 42 | 43 | #define mrb_static_assert_object_size(st) \ 44 | mrb_static_assert(sizeof(st) <= sizeof(void*) * 6, \ 45 | #st " size must be within 6 words") 46 | 47 | #endif /* MRUBY_OBJECT_H */ 48 | -------------------------------------------------------------------------------- /mruby/include/mruby/presym/enable.h: -------------------------------------------------------------------------------- 1 | /** 2 | ** @file mruby/presym/enable.h - Enable Preallocated Symbols 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #ifndef MRUBY_PRESYM_ENABLE_H 8 | #define MRUBY_PRESYM_ENABLE_H 9 | 10 | #include 11 | 12 | #define MRB_OPSYM(name) MRB_OPSYM__##name 13 | #define MRB_CVSYM(name) MRB_CVSYM__##name 14 | #define MRB_IVSYM(name) MRB_IVSYM__##name 15 | #define MRB_SYM_B(name) MRB_SYM_B__##name 16 | #define MRB_SYM_Q(name) MRB_SYM_Q__##name 17 | #define MRB_SYM_E(name) MRB_SYM_E__##name 18 | #define MRB_SYM(name) MRB_SYM__##name 19 | 20 | #define MRB_OPSYM_2(mrb, name) MRB_OPSYM__##name 21 | #define MRB_CVSYM_2(mrb, name) MRB_CVSYM__##name 22 | #define MRB_IVSYM_2(mrb, name) MRB_IVSYM__##name 23 | #define MRB_SYM_B_2(mrb, name) MRB_SYM_B__##name 24 | #define MRB_SYM_Q_2(mrb, name) MRB_SYM_Q__##name 25 | #define MRB_SYM_E_2(mrb, name) MRB_SYM_E__##name 26 | #define MRB_SYM_2(mrb, name) MRB_SYM__##name 27 | 28 | #define MRB_PRESYM_DEFINE_VAR_AND_INITER(name, size, ...) \ 29 | static const mrb_sym name[] = {__VA_ARGS__}; 30 | 31 | #define MRB_PRESYM_INIT_SYMBOLS(mrb, name) (void)(mrb) 32 | 33 | /* use MRB_SYM() for E_RUNTIME_ERROR etc. */ 34 | #undef MRB_ERROR_SYM 35 | #define MRB_ERROR_SYM(sym) MRB_SYM(sym) 36 | 37 | #endif /* MRUBY_PRESYM_ENABLE_H */ 38 | -------------------------------------------------------------------------------- /mruby/include/mruby/re.h: -------------------------------------------------------------------------------- 1 | /** 2 | ** @file mruby/re.h - Regexp class 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #ifndef MRUBY_RE_H 8 | #define MRUBY_RE_H 9 | 10 | MRB_BEGIN_DECL 11 | 12 | #define REGEXP_CLASS "Regexp" 13 | 14 | MRB_END_DECL 15 | 16 | #endif /* RE_H */ 17 | -------------------------------------------------------------------------------- /mruby/minirake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | exec "rake", *ARGV 3 | -------------------------------------------------------------------------------- /mruby/mrbgems/default-no-fpu.gembox: -------------------------------------------------------------------------------- 1 | MRuby::GemBox.new do |conf| 2 | conf.gembox "stdlib" 3 | end 4 | -------------------------------------------------------------------------------- /mruby/mrbgems/default-no-stdio.gembox: -------------------------------------------------------------------------------- 1 | MRuby::GemBox.new do |conf| 2 | conf.gembox "stdlib" 3 | conf.gembox "math" 4 | end 5 | -------------------------------------------------------------------------------- /mruby/mrbgems/default.gembox: -------------------------------------------------------------------------------- 1 | MRuby::GemBox.new do |conf| 2 | conf.gembox "stdlib" 3 | conf.gembox "stdlib-ext" 4 | conf.gembox "stdlib-io" 5 | conf.gembox "math" 6 | conf.gembox "metaprog" 7 | 8 | # Generate mrbc command 9 | conf.gem :core => "mruby-bin-mrbc" 10 | 11 | # Generate mrdb command 12 | conf.gem :core => "mruby-bin-debugger" 13 | 14 | # Generate mirb command 15 | conf.gem :core => "mruby-bin-mirb" 16 | 17 | # Generate mruby command 18 | conf.gem :core => "mruby-bin-mruby" 19 | 20 | # Generate mruby-strip command 21 | conf.gem :core => "mruby-bin-strip" 22 | 23 | # Generate mruby-config command 24 | conf.gem :core => "mruby-bin-config" 25 | end 26 | -------------------------------------------------------------------------------- /mruby/mrbgems/full-core.gembox: -------------------------------------------------------------------------------- 1 | MRuby::GemBox.new do |conf| 2 | Dir.glob("#{root}/mrbgems/mruby-*/mrbgem.rake") do |x| 3 | g = File.basename(File.dirname(x)) 4 | conf.gem :core => g unless g =~ /^mruby-(?:bin-debugger|test)$/ 5 | end 6 | end 7 | -------------------------------------------------------------------------------- /mruby/mrbgems/math.gembox: -------------------------------------------------------------------------------- 1 | # It also works with MRB_NO_STDIO. 2 | 3 | MRuby::GemBox.new do |conf| 4 | # Use standard Math module 5 | conf.gem :core => "mruby-math" 6 | 7 | # Use Rational/Complex numbers 8 | conf.gem :core => "mruby-rational" 9 | conf.gem :core => "mruby-complex" 10 | # Use Complex math functions in CMath module 11 | conf.gem :core => "mruby-cmath" 12 | # Use Multi-precision Integer 13 | conf.gem :core => "mruby-bigint" 14 | end 15 | -------------------------------------------------------------------------------- /mruby/mrbgems/metaprog.gembox: -------------------------------------------------------------------------------- 1 | # It also works with MRB_NO_STDIO and MRB_NO_FLOAT. 2 | 3 | MRuby::GemBox.new do |conf| 4 | # Meta-programming features 5 | conf.gem :core => "mruby-metaprog" 6 | 7 | # Use Method/UnboundMethod class 8 | conf.gem :core => "mruby-method" 9 | 10 | # Use eval() 11 | conf.gem :core => "mruby-eval" 12 | 13 | # Use mruby-compiler to build other mrbgems 14 | conf.gem :core => "mruby-compiler" 15 | end 16 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-array-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-array-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Array class extension' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bigint/README.md: -------------------------------------------------------------------------------- 1 | # Multi-precision Integer extension for mruby 2 | 3 | This extension uses fgmp, which is a public domain implementation of a subset of the GNU gmp library by Mark Henderson . 4 | But it's heavily modified to fit with mruby. You can get the original source code from . 5 | You can read the original README for fgmp in [README-fgmp.md](README-fgmp.md). 6 | 7 | If you want to create your own Multi-precision Integer GEM, see [examples/mrbgems/mruby-YOUR-bigint/TODO-HINT.md](../../examples/mrbgems/mruby-YOUR-bigint/TODO-HINT.md). 8 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bigint/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-bigint') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Integer class extension to multiple-precision' 5 | spec.build.defines << "MRB_USE_BIGINT" 6 | 7 | spec.build.libmruby_core_objs << Dir.glob(File.join(__dir__, "core/**/*.c")).map { |fn| 8 | objfile(fn.relative_path_from(__dir__).pathmap("#{spec.build_dir}/%X")) 9 | } 10 | end 11 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bigint/test/bigint.rb: -------------------------------------------------------------------------------- 1 | assert 'Bigint basic' do 2 | n = 1<<65 3 | assert_equal 36893488147419103232, n 4 | assert_equal 36893488147419104229, n+997 5 | assert_equal 36893488147419102235, n-997 6 | assert_equal 36782807682976845922304, n*997 7 | assert_equal 37004501652376231, n.div(997) 8 | end 9 | 10 | assert 'Bigint to_s' do 11 | n = 1197857166996989179607278372168909873645893814254642585755536286462800958278984531968 12 | assert_equal n, "11978_571669_96989179607278372168909873645893814254642585755536286462800958278984531968".to_i 13 | assert_equal(-n, "-11978_571669_96989179607278372168909873645893814254642585755536286462800958278984531968".to_i) 14 | n = 0x1197857166996989179607278372168909873645893814254642585755536286462800958278984531968 15 | assert_equal n, "1197857166996989179607278372168909873645893814254642585755536286462800958278984531968".to_i(16) 16 | end 17 | 18 | assert 'Bigint pow' do 19 | n = 18446744073709551616 20 | assert_equal n, 2 ** 64 21 | assert_equal n, 1 << 64 22 | assert_equal 2, n >> 63 23 | end 24 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-debugger/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-bin-debugger') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'mruby debugger command' 5 | spec.build.defines << "MRB_USE_DEBUG_HOOK" 6 | spec.add_dependency('mruby-eval', :core => 'mruby-eval') 7 | 8 | spec.bins = %w(mrdb) 9 | end 10 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** apibreak.h 3 | ** 4 | */ 5 | 6 | #ifndef APIBREAK_H_ 7 | #define APIBREAK_H_ 8 | 9 | #include 10 | #include "mrdb.h" 11 | 12 | int32_t mrb_debug_set_break_line(mrb_state*, mrb_debug_context*, const char*, uint16_t); 13 | int32_t mrb_debug_set_break_method(mrb_state*, mrb_debug_context*, const char*, const char*); 14 | int32_t mrb_debug_get_breaknum(mrb_state*, mrb_debug_context*); 15 | int32_t mrb_debug_get_break_all(mrb_state*, mrb_debug_context*, uint32_t, mrb_debug_breakpoint bp[]); 16 | int32_t mrb_debug_get_break(mrb_state*, mrb_debug_context*, uint32_t, mrb_debug_breakpoint*); 17 | int32_t mrb_debug_delete_break(mrb_state*, mrb_debug_context*, uint32_t); 18 | int32_t mrb_debug_delete_break_all(mrb_state*, mrb_debug_context*); 19 | int32_t mrb_debug_enable_break(mrb_state*, mrb_debug_context*, uint32_t); 20 | int32_t mrb_debug_enable_break_all(mrb_state*, mrb_debug_context*); 21 | int32_t mrb_debug_disable_break(mrb_state*, mrb_debug_context*, uint32_t); 22 | int32_t mrb_debug_disable_break_all(mrb_state*, mrb_debug_context*); 23 | int32_t mrb_debug_check_breakpoint_line(mrb_state*, mrb_debug_context*, const char*, uint16_t); 24 | int32_t mrb_debug_check_breakpoint_method(mrb_state*, mrb_debug_context*, struct RClass*, mrb_sym, mrb_bool*); 25 | 26 | #endif /* APIBREAK_H_ */ 27 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apilist.h: -------------------------------------------------------------------------------- 1 | /* 2 | * apilist.h 3 | */ 4 | 5 | #ifndef APILIST_H_ 6 | #define APILIST_H_ 7 | 8 | #include 9 | #include "mrdb.h" 10 | 11 | int32_t mrb_debug_list(mrb_state*, mrb_debug_context*, char*, uint16_t, uint16_t); 12 | char* mrb_debug_get_source(mrb_state*, mrdb_state*, const char*, const char *); 13 | 14 | #endif /* APILIST_H_ */ 15 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apiprint.h: -------------------------------------------------------------------------------- 1 | /* 2 | * apiprint.h 3 | */ 4 | 5 | #ifndef APIPRINT_H_ 6 | #define APIPRINT_H_ 7 | 8 | #include 9 | #include "mrdb.h" 10 | 11 | mrb_value mrb_debug_eval(mrb_state*, mrb_debug_context*, const char*, size_t, mrb_bool*, int); 12 | 13 | #endif /* APIPRINT_H_ */ 14 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apistring.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** apistring.c 3 | ** 4 | */ 5 | 6 | #include 7 | #include "apistring.h" 8 | 9 | static size_t 10 | mrb_debug_strnlen(const char *s, size_t maxlen) 11 | { 12 | const char *p = (const char*)memchr(s, '\0', maxlen); 13 | return p != NULL ? (size_t)(p - s) : maxlen; 14 | } 15 | 16 | char* 17 | mrdb_strndup(mrb_state *mrb, const char *s, size_t size) 18 | { 19 | size_t l = mrb_debug_strnlen(s, size); 20 | char *d = (char*)mrb_malloc_simple(mrb, l + 1); 21 | if (d != NULL) { 22 | memcpy(d, s, l); 23 | d[l] = '\0'; 24 | } 25 | return d; 26 | } 27 | 28 | char* 29 | mrdb_strdup(mrb_state *mrb, const char *s) 30 | { 31 | size_t z = strlen(s) + 1; 32 | char *d = (char*)mrb_malloc_simple(mrb, z); 33 | return d != NULL ? (char*)memcpy(d, s, z) : NULL; 34 | } 35 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-debugger/tools/mrdb/apistring.h: -------------------------------------------------------------------------------- 1 | /* 2 | * apistring.h 3 | */ 4 | 5 | #ifndef APISTRING_H_ 6 | #define APISTRING_H_ 7 | 8 | #include "mruby.h" 9 | 10 | /* both functions return a null pointer on failure */ 11 | char *mrdb_strndup(mrb_state *mrb, const char *s, size_t size); 12 | char *mrdb_strdup(mrb_state *mrb, const char *s); 13 | 14 | #endif /* APISTRING_H_ */ 15 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdbconf.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** mrdbconf.h - mruby debugger configuration 3 | ** 4 | */ 5 | 6 | #ifndef MRDBCONF_H 7 | #define MRDBCONF_H 8 | 9 | #ifndef MRB_USE_DEBUG_HOOK 10 | # error mruby-bin-debugger need 'MRB_USE_DEBUG_HOOK' in your build configuration 11 | #endif 12 | 13 | #ifdef MRB_NO_STDIO 14 | # error mruby-bin-debugger conflicts 'MRB_NO_STDIO' in your build configuration 15 | #endif 16 | 17 | /* configuration options: */ 18 | /* maximum size for command buffer */ 19 | #define MAX_COMMAND_LINE 1024 20 | 21 | /* maximum number of setable breakpoint */ 22 | #define MAX_BREAKPOINT 5 23 | 24 | #endif 25 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-debugger/tools/mrdb/mrdberror.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** mrdberror.h - mruby debugger error code 3 | ** 4 | */ 5 | 6 | #ifndef MRDBERROR_H 7 | #define MRDBERROR_H 8 | 9 | #define MRB_DEBUG_OK (0) 10 | #define MRB_DEBUG_NOBUF (-1) 11 | #define MRB_DEBUG_INVALID_ARGUMENT (-2) 12 | 13 | #define MRB_DEBUG_BREAK_INVALID_LINENO (-11) 14 | #define MRB_DEBUG_BREAK_INVALID_FILE (-12) 15 | #define MRB_DEBUG_BREAK_INVALID_NO (-13) 16 | #define MRB_DEBUG_BREAK_NUM_OVER (-14) 17 | #define MRB_DEBUG_BREAK_NO_OVER (-15) 18 | 19 | #endif 20 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-mrbc/bintest/mrbc.rb: -------------------------------------------------------------------------------- 1 | require 'tempfile' 2 | 3 | assert('Compiling multiple files without new line in last line. #2361') do 4 | a, b, out = Tempfile.new('a.rb'), Tempfile.new('b.rb'), Tempfile.new('out.mrb') 5 | a.write('module A; end') 6 | a.flush 7 | b.write('module B; end') 8 | b.flush 9 | result = `#{cmd('mrbc')} -c -o #{out.path} #{a.path} #{b.path} 2>&1` 10 | assert_equal "#{cmd_bin('mrbc')}:#{a.path}:Syntax OK", result.chomp 11 | assert_equal 0, $?.exitstatus 12 | end 13 | 14 | assert('parsing function with void argument') do 15 | a, out = Tempfile.new('a.rb'), Tempfile.new('out.mrb') 16 | a.write('f ()') 17 | a.flush 18 | result = `#{cmd('mrbc')} -c -o #{out.path} #{a.path} 2>&1` 19 | assert_equal "#{cmd_bin('mrbc')}:#{a.path}:Syntax OK", result.chomp 20 | assert_equal 0, $?.exitstatus 21 | end 22 | 23 | assert('embedded document with invalid terminator') do 24 | a, out = Tempfile.new('a.rb'), Tempfile.new('out.mrb') 25 | a.write("=begin\n=endx\n") 26 | a.flush 27 | result = `#{cmd('mrbc')} -c -o #{out.path} #{a.path} 2>&1` 28 | assert_equal "#{a.path}:3:0: embedded document meets end of file", result.chomp 29 | assert_equal 1, $?.exitstatus 30 | end 31 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-mrbc/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new 'mruby-bin-mrbc' do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'mruby compiler executable' 5 | spec.add_dependency 'mruby-compiler', :core => 'mruby-compiler' 6 | 7 | exec = exefile("#{build.build_dir}/bin/mrbc") 8 | mrbc_objs = Dir.glob("#{spec.dir}/tools/mrbc/*.c").map { |f| objfile(f.pathmap("#{spec.build_dir}/tools/mrbc/%n")) } 9 | 10 | file exec => mrbc_objs << build.libmruby_core_static do |t| 11 | build.linker.run t.name, t.prerequisites 12 | end 13 | 14 | build.bins << 'mrbc' 15 | end 16 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-mruby/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-bin-mruby') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'mruby command' 5 | spec.bins = %w(mruby) 6 | spec.add_dependency('mruby-compiler', :core => 'mruby-compiler') 7 | spec.add_test_dependency('mruby-print', :core => 'mruby-print') 8 | 9 | if build.cxx_exception_enabled? 10 | build.compile_as_cxx("#{spec.dir}/tools/mruby/mruby.c") 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-strip/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-bin-strip') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'irep dump debug section remover command' 5 | spec.add_dependency 'mruby-compiler', :core => 'mruby-compiler' 6 | spec.bins = %w(mruby-strip) 7 | end 8 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-binding/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-binding') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Binding class (core features only)' 5 | 6 | spec.add_test_dependency('mruby-proc-ext', :core => 'mruby-proc-ext') 7 | end 8 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-binding/test/binding.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static mrb_value 5 | binding_in_c(mrb_state *mrb, mrb_value self) 6 | { 7 | return mrb_funcall_argv(mrb, mrb_obj_value(mrb->object_class), MRB_SYM(binding), 0, NULL); 8 | } 9 | 10 | void 11 | mrb_mruby_binding_gem_test(mrb_state *mrb) 12 | { 13 | mrb_define_method(mrb, mrb->object_class, "binding_in_c", binding_in_c, MRB_ARGS_NONE()); 14 | } 15 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-catch/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-catch') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Catch / Throw non-local Jump' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-catch/mrblib/catch.rb: -------------------------------------------------------------------------------- 1 | class UncaughtThrowError < ArgumentError 2 | attr_reader :tag, :value 3 | def initialize(tag, value) 4 | @tag = tag 5 | @value = value 6 | super("uncaught throw #{tag.inspect}") 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-class-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-class-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'class/module extension' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-class-ext/test/class.rb: -------------------------------------------------------------------------------- 1 | assert 'Class#subclasses' do 2 | a = Class.new 3 | b = Class.new(a) 4 | c = Class.new(b) 5 | d = Class.new(a) 6 | 7 | a_sub = a.subclasses 8 | assert_equal(2, a_sub.size) 9 | assert_true(a_sub.include?(b)) 10 | assert_true(a_sub.include?(d)) 11 | assert_equal([c], b.subclasses) 12 | assert_equal([], c.subclasses) 13 | end 14 | 15 | assert 'Class#attached_object' do 16 | foo = Class.new 17 | foo_s = class < 'mruby-complex' 8 | end 9 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-cmath/test/cmath.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # CMath Test 3 | 4 | def assert_complex(c1, c2) 5 | assert('assert_complex') do 6 | assert_float(c1.real, c2.real) 7 | assert_float(c1.imaginary, c2.imaginary) 8 | end 9 | end 10 | 11 | assert('CMath.exp') do 12 | assert_float(1.0, CMath.exp(0)) 13 | assert_complex(-1+0i, CMath.exp(Math::PI.i)) 14 | assert_complex((-1.1312043837568135+2.4717266720048188i), CMath.exp(1+2i)) 15 | end 16 | 17 | assert('CMath.log') do 18 | assert_float(0, CMath.log(1)) 19 | assert_float(3.0, CMath.log(8,2)) 20 | assert_complex((1.092840647090816-0.42078724841586035i), CMath.log(-8,-2)) 21 | end 22 | 23 | assert('CMath.sqrt') do 24 | assert_complex(Complex(0,2), CMath.sqrt(-4.0)) 25 | assert_complex(Complex(0,3), CMath.sqrt(-9.0)) 26 | end 27 | 28 | assert('CMath trigonometric_functions') do 29 | assert_complex(Math.sinh(2).i, CMath.sin(2i)) 30 | assert_complex(Math.cosh(2)+0i, CMath.cos(2i)) 31 | assert_complex(Math.tanh(2).i, CMath.tan(2i)) 32 | assert_complex(Math.sin(2).i, CMath.sinh(2i)) 33 | assert_complex(Math.cos(2)+0i, CMath.cosh(2i)) 34 | assert_complex(Math.tan(2).i, CMath.tanh(2i)) 35 | assert_complex(1+1i, CMath.sin(CMath.asin(1+1i))) 36 | assert_complex(1+1i, CMath.cos(CMath.acos(1+1i))) 37 | assert_complex(1+1i, CMath.tan(CMath.atan(1+1i))) 38 | assert_complex(1+1i, CMath.sinh(CMath.asinh(1+1i))) 39 | assert_complex(1+1i, CMath.cosh(CMath.acosh(1+1i))) 40 | assert_complex(1+1i, CMath.tanh(CMath.atanh(1+1i))) 41 | end 42 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-compar-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-compar-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Comparable module extension' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-compiler/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new 'mruby-compiler' do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'mruby compiler library' 5 | 6 | objs = %w[codegen y.tab].map do |name| 7 | src = "#{dir}/core/#{name}.c" 8 | if build.cxx_exception_enabled? 9 | build.compile_as_cxx(src) 10 | else 11 | objfile(src.pathmap("#{build_dir}/core/%n")) 12 | end 13 | end 14 | build.libmruby_core_objs << objs 15 | end 16 | 17 | if MRuby::Build.current.name == "host" 18 | dir = __dir__ 19 | lex_def = "#{dir}/core/lex.def" 20 | 21 | # Parser 22 | file "#{dir}/core/y.tab.c" => ["#{dir}/core/parse.y", lex_def] do |t| 23 | MRuby.targets["host"].yacc.run t.name, t.prerequisites.first 24 | replace_line_directive(t.name) 25 | end 26 | 27 | # Lexical analyzer 28 | file lex_def => "#{dir}/core/keywords" do |t| 29 | MRuby.targets["host"].gperf.run t.name, t.prerequisites.first 30 | replace_line_directive(t.name) 31 | end 32 | 33 | def replace_line_directive(path) 34 | content = File.read(path).gsub(%r{ 35 | ^\#line\s+\d+\s+"\K.*(?="$) | # #line directive 36 | ^/\*\s+Command-line:.*\s\K\S+(?=\s+\*/$) # header comment in lex.def 37 | }x, &:relative_path) 38 | File.write(path, content) 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-complex/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-complex') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Complex class' 5 | spec.build.defines << "MRB_USE_COMPLEX" 6 | spec.add_dependency 'mruby-math', core: 'mruby-math' 7 | end 8 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-data/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-data') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'standard Data class' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-dir/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-dir') do |spec| 2 | spec.license = 'MIT and MIT-like license' 3 | spec.authors = ['Internet Initiative Japan Inc.', 'Kevlin Henney'] 4 | end 5 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-dir/mrblib/dir.rb: -------------------------------------------------------------------------------- 1 | class Dir 2 | include Enumerable 3 | 4 | def each(&block) 5 | while s = self.read 6 | block.call(s) 7 | end 8 | self 9 | end 10 | 11 | alias each_child each 12 | alias pos tell 13 | alias pos= seek 14 | 15 | class << self 16 | def entries(path) 17 | a = [] 18 | self.open(path) do |d| 19 | while s = d.read 20 | a << s 21 | end 22 | end 23 | a 24 | end 25 | alias children entries 26 | 27 | def foreach(path, &block) 28 | self.open(path) do |d| 29 | d.each(&block) 30 | end 31 | end 32 | 33 | def open(path, &block) 34 | if block 35 | d = self.new(path) 36 | begin 37 | block.call(d) 38 | ensure 39 | begin 40 | d.close 41 | rescue IOError 42 | end 43 | end 44 | else 45 | self.new(path) 46 | end 47 | end 48 | 49 | def chdir(path, &block) 50 | if block 51 | wd = self.getwd 52 | begin 53 | self._chdir(path) 54 | block.call(path) 55 | ensure 56 | self._chdir(wd) 57 | end 58 | else 59 | self._chdir(path) 60 | end 61 | end 62 | 63 | alias exists? exist? 64 | alias pwd getwd 65 | alias rmdir delete 66 | alias unlink delete 67 | end 68 | end 69 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-enum-chain/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-enum-chain') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Enumerator::Chain class' 5 | spec.add_dependency('mruby-enumerator', :core => 'mruby-enumerator') 6 | end 7 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-enum-chain/mrblib/chain.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # chain.rb Enumerator::Chain class 3 | # See Copyright Notice in mruby.h 4 | 5 | module Enumerable 6 | def chain(*args) 7 | Enumerator::Chain.new(self, *args) 8 | end 9 | end 10 | 11 | class Enumerator 12 | def +(other) 13 | Chain.new(self, other) 14 | end 15 | 16 | class Chain 17 | include Enumerable 18 | 19 | def initialize(*args) 20 | @enums = args.freeze 21 | @pos = -1 22 | end 23 | 24 | def each(&block) 25 | return to_enum unless block 26 | 27 | i = 0 28 | while i < @enums.size 29 | @pos = i 30 | @enums[i].each(&block) 31 | i += 1 32 | end 33 | 34 | self 35 | end 36 | 37 | def size 38 | @enums.reduce(0) do |a, e| 39 | return nil unless e.respond_to?(:size) 40 | a + e.size 41 | end 42 | end 43 | 44 | def rewind 45 | while 0 <= @pos && @pos < @enums.size 46 | e = @enums[@pos] 47 | e.rewind if e.respond_to?(:rewind) 48 | @pos -= 1 49 | end 50 | 51 | self 52 | end 53 | 54 | def +(other) 55 | self.class.new(self, other) 56 | end 57 | 58 | def inspect 59 | "#<#{self.class}: #{@enums.inspect}>" 60 | end 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-enum-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-enum-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Enumerable module extension' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-enum-lazy/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-enum-lazy') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Enumerator::Lazy class' 5 | spec.add_dependency('mruby-enumerator', :core => 'mruby-enumerator') 6 | spec.add_dependency('mruby-enum-ext', :core => 'mruby-enum-ext') 7 | end 8 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-enum-lazy/test/lazy.rb: -------------------------------------------------------------------------------- 1 | assert("Enumerator::Lazy") do 2 | a = [1, 2] 3 | assert_equal Enumerator::Lazy, a.lazy.class 4 | end 5 | 6 | assert("Enumerator::Lazy laziness") do 7 | a = Object.new 8 | def a.each 9 | return to_enum :each unless block_given? 10 | self.b << 10 11 | yield 1 12 | self.b << 20 13 | yield 2 14 | self.b << 30 15 | yield 3 16 | self.b << 40 17 | yield 4 18 | self.b << 50 19 | yield 5 20 | end 21 | def a.b(b=nil) 22 | @b = b if b 23 | @b 24 | end 25 | 26 | a.b([]) 27 | assert_equal [1,2], a.each.lazy.take(2).force 28 | assert_equal [10,20], a.b 29 | 30 | a.b([]) 31 | assert_equal [2,4], a.each.lazy.select{|x|x%2==0}.take(2).force 32 | assert_equal [10,20,30,40], a.b 33 | 34 | a.b([]) 35 | assert_equal [1], a.each.lazy.take_while{|x|x<2}.take(1).force 36 | assert_equal [10], a.b 37 | 38 | a.b([]) 39 | assert_equal [1], a.each.lazy.take_while{|x|x<2}.take(4).force 40 | assert_equal [10,20], a.b 41 | end 42 | 43 | assert("Enumerator::Lazy#to_enum") do 44 | lazy_enum = (0..).lazy.to_enum(:each_slice, 2) 45 | assert_kind_of Enumerator::Lazy, lazy_enum 46 | assert_equal [0*1, 2*3, 4*5, 6*7], lazy_enum.map { |a| a.first * a.last }.first(4) 47 | end 48 | 49 | assert("Enumerator::Lazy#zip with cycle") do 50 | e1 = [1, 2, 3].cycle 51 | e2 = [:a, :b].cycle 52 | assert_equal [[1,:a],[2,:b],[3,:a]], e1.lazy.zip(e2).first(3) 53 | end 54 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-enumerator/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-enumerator') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.add_dependency('mruby-fiber', :core => 'mruby-fiber') 5 | spec.summary = 'Enumerator class' 6 | end 7 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-errno/README.md: -------------------------------------------------------------------------------- 1 | # mruby-errno 2 | 3 | Errno module for mruby 4 | 5 | ## License 6 | 7 | Copyright (c) 2013 Internet Initiative Japan Inc. 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a 10 | copy of this software and associated documentation files (the "Software"), 11 | to deal in the Software without restriction, including without limitation 12 | the rights to use, copy, modify, merge, publish, distribute, sublicense, 13 | and/or sell copies of the Software, and to permit persons to whom the 14 | Software is furnished to do so, subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in 17 | all copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 24 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 25 | DEALINGS IN THE SOFTWARE. 26 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-errno/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-errno') do |spec| 2 | spec.license = 'MIT' 3 | spec.authors = 'Internet Initiative Japan Inc.' 4 | spec.summary = 'Errno module and SystemCallError class' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-errno/mrblib/errno.rb: -------------------------------------------------------------------------------- 1 | module Errno 2 | def Errno.const_defined?(name) 3 | __errno_defined?(name) or super 4 | end 5 | 6 | def Errno.const_missing(name) 7 | __errno_define(name) or super 8 | end 9 | 10 | # Module#constants is defined in mruby-metaprog 11 | # So, it may be raised NoMethodError 12 | def Errno.constants 13 | __errno_list(super) 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-errno/src/gen.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | Dir.chdir(File.dirname($0)) 4 | 5 | d = File.open("known_errors_def.cstub", "w") 6 | 7 | IO.readlines("known_errors.def").each { |name| 8 | next if name =~ /^#/ 9 | name.strip! 10 | 11 | d.write < 'mruby-compiler' 7 | add_dependency 'mruby-binding', :core => 'mruby-binding' 8 | spec.add_test_dependency('mruby-metaprog', :core => 'mruby-metaprog') 9 | spec.add_test_dependency('mruby-method', :core => 'mruby-method') 10 | end 11 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-exit/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-exit') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Kernel#exit method' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-fiber/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-fiber') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Fiber class' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-hash-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-hash-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Hash class extension' 5 | spec.add_dependency 'mruby-array-ext', core: 'mruby-array-ext' 6 | end 7 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-io/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-io') do |spec| 2 | spec.license = 'MIT' 3 | spec.authors = ['Internet Initiative Japan Inc.', 'mruby developers'] 4 | spec.summary = 'IO and File class' 5 | 6 | if spec.for_windows? 7 | spec.linker.libraries << "ws2_32" 8 | end 9 | spec.add_test_dependency 'mruby-time', core: 'mruby-time' 10 | end 11 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-io/mrblib/file_constants.rb: -------------------------------------------------------------------------------- 1 | class File 2 | module Constants 3 | FNM_SYSCASE = 0 4 | FNM_NOESCAPE = 1 5 | FNM_PATHNAME = 2 6 | FNM_DOTMATCH = 4 7 | FNM_CASEFOLD = 8 8 | end 9 | end 10 | 11 | class File 12 | include File::Constants 13 | end 14 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-io/mrblib/kernel.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | def `(cmd) 3 | IO.popen(cmd) { |io| io.read } 4 | end 5 | 6 | def open(file, *rest, &block) 7 | raise ArgumentError unless file.is_a?(String) 8 | 9 | if file[0] == "|" 10 | IO.popen(file[1..-1], *rest, &block) 11 | else 12 | File.open(file, *rest, &block) 13 | end 14 | end 15 | 16 | def print(*args) 17 | $stdout.print(*args) 18 | end 19 | 20 | def puts(*args) 21 | $stdout.puts(*args) 22 | end 23 | 24 | def printf(*args) 25 | $stdout.printf(*args) 26 | end 27 | 28 | def gets(*args) 29 | $stdin.gets(*args) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-io/src/mruby_io_gem.c: -------------------------------------------------------------------------------- 1 | #include "mruby.h" 2 | 3 | void mrb_init_io(mrb_state *mrb); 4 | void mrb_init_file(mrb_state *mrb); 5 | void mrb_init_file_test(mrb_state *mrb); 6 | 7 | #define DONE mrb_gc_arena_restore(mrb, 0) 8 | 9 | void 10 | mrb_mruby_io_gem_init(mrb_state* mrb) 11 | { 12 | mrb_init_io(mrb); DONE; 13 | mrb_init_file(mrb); DONE; 14 | mrb_init_file_test(mrb); DONE; 15 | } 16 | 17 | void 18 | mrb_mruby_io_gem_final(mrb_state* mrb) 19 | { 20 | } 21 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-kernel-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-kernel-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'extensional function-like methods' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-math/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-math') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'standard Math module' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-metaprog/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-metaprog') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Meta-programming features for mruby' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-method/README.md: -------------------------------------------------------------------------------- 1 | # mruby-method 2 | 3 | An implementation of class **Method** and **UnboundMethod** for mruby 4 | 5 | ```ruby 6 | p Enumerable.instance_method(:find_all).source_location 7 | #=> ["mruby/mruby/mrblib/enum.rb", 148] 8 | ``` 9 | 10 | # Note 11 | 12 | You need to enable debug option in your build configuration to use 13 | `source_location` method in this gem, for example: 14 | 15 | ```ruby 16 | MRuby::Build.new do |conf| 17 | conf.enable_debug 18 | end 19 | ``` 20 | 21 | # Supported Methods 22 | 23 | ## Kernel 24 | 25 | - `Kernel#method` 26 | - `Kernel#singleton_method` 27 | 28 | ## Module 29 | 30 | - `Module#instance_method` 31 | 32 | ## Method class 33 | 34 | - `Method#name` 35 | - `Method#call` 36 | - `Method#super_method` 37 | - `Method#arity` 38 | - `Method#unbind` 39 | - `Method#[]` 40 | - `Method#owner` 41 | - `Method#receiver` 42 | - `Method#parameters` 43 | - `Method#source_location` 44 | - `Method#to_proc` 45 | 46 | ## UnboundMethod class 47 | 48 | - `UnboundMethod#name` 49 | - `UnboundMethod#bind` 50 | - `UnboundMethod#super_method` 51 | - `UnboundMethod#arity` 52 | - `UnboundMethod#owner` 53 | - `UnboundMethod#parameters` 54 | - `UnboundMethod#source_location` 55 | 56 | # See also 57 | 58 | - 59 | - 60 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-method/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-method') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Method and UnboundMethod class' 5 | 6 | spec.add_dependency('mruby-proc-ext', :core => 'mruby-proc-ext') 7 | end 8 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-method/mrblib/method.rb: -------------------------------------------------------------------------------- 1 | class Method 2 | def to_proc 3 | m = self 4 | lambda { |*args, **opts, &b| 5 | m.call(*args, **opts, &b) 6 | } 7 | end 8 | 9 | def <<(other) 10 | ->(*args, **opts, &block) { call(other.call(*args, **opts, &block)) } 11 | end 12 | 13 | def >>(other) 14 | ->(*args, **opts, &block) { other.call(call(*args, **opts, &block)) } 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-numeric-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-numeric-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Numeric class extension' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-numeric-ext/test/numeric.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # Numeric(Ext) Test 3 | 4 | assert('Integer#div') do 5 | assert_equal 52, 365.div(7) 6 | end 7 | 8 | assert('Float#div') do 9 | skip unless Object.const_defined?(:Float) 10 | assert_float 52, 365.2425.div(7) 11 | end 12 | 13 | assert('Integer#zero?') do 14 | assert_equal true, 0.zero? 15 | assert_equal false, 1.zero? 16 | end 17 | 18 | assert('Integer#nonzero?') do 19 | assert_equal nil, 0.nonzero? 20 | assert_equal 1000, 1000.nonzero? 21 | end 22 | 23 | assert('Integer#pow') do 24 | assert_equal(8, 2.pow(3)) 25 | assert_equal(-8, (-2).pow(3)) 26 | assert_equal(361, 9.pow(1024,1000)) 27 | end 28 | 29 | assert('Integer#ceildiv') do 30 | assert_equal(0, 0.ceildiv(3)) 31 | assert_equal(1, 1.ceildiv(3)) 32 | assert_equal(1, 3.ceildiv(3)) 33 | assert_equal(2, 4.ceildiv(3)) 34 | 35 | assert_equal(-1, 4.ceildiv(-3)) 36 | assert_equal(-1, -4.ceildiv(3)) 37 | assert_equal(2, -4.ceildiv(-3)) 38 | 39 | if Object.const_defined?(:Float) 40 | assert_equal(3, 3.ceildiv(1.2)) 41 | end 42 | if Object.const_defined?(:Rational) 43 | assert_equal(3, 3.ceildiv(6/5r)) 44 | end 45 | 46 | # assert_equal(10, (10**100-11).ceildiv(10**99-1)) 47 | # assert_equal(11, (10**100-9).ceildiv(10**99-1)) 48 | assert_equal(8, 2.pow(3)) 49 | assert_equal(-8, (-2).pow(3)) 50 | # assert_equal(361, 9.pow(1024,1000)) 51 | end 52 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-object-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-object-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'extensional methods shared by all objects' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-object-ext/mrblib/object.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | # call-seq: 3 | # obj.yield_self {|_obj|...} -> an_object 4 | # obj.then {|_obj|...} -> an_object 5 | # 6 | # Yields obj and returns the result. 7 | # 8 | # 'my string'.yield_self {|s|s.upcase} #=> "MY STRING" 9 | # 10 | def yield_self(&block) 11 | return to_enum :yield_self unless block 12 | block.call(self) 13 | end 14 | alias then yield_self 15 | 16 | ## 17 | # call-seq: 18 | # obj.tap{|x|...} -> obj 19 | # 20 | # Yields x to the block, and then returns x. 21 | # The primary purpose of this method is to "tap into" a method chain, 22 | # in order to perform operations on intermediate results within the chain. 23 | # 24 | # (1..10) .tap {|x| puts "original: #{x.inspect}"} 25 | # .to_a .tap {|x| puts "array: #{x.inspect}"} 26 | # .select {|x| x%2==0} .tap {|x| puts "evens: #{x.inspect}"} 27 | # .map { |x| x*x } .tap {|x| puts "squares: #{x.inspect}"} 28 | # 29 | def tap 30 | yield self 31 | self 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-object-ext/test/nil.rb: -------------------------------------------------------------------------------- 1 | assert('NilClass#to_a') do 2 | assert_equal [], nil.to_a 3 | end 4 | 5 | assert('NilClass#to_f') do 6 | skip unless Object.const_defined?(:Float) 7 | assert_equal 0.0, nil.to_f 8 | end 9 | 10 | assert('NilClass#to_h') do 11 | assert_equal Hash.new, nil.to_h 12 | end 13 | 14 | assert('NilClass#to_i') do 15 | assert_equal 0, nil.to_i 16 | end 17 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-object-ext/test/object.rb: -------------------------------------------------------------------------------- 1 | assert('Object#instance_exec') do 2 | class KlassWithSecret 3 | def initialize 4 | @secret = 99 5 | end 6 | end 7 | k = KlassWithSecret.new 8 | assert_equal 104, k.instance_exec(5) {|x| @secret+x } 9 | end 10 | 11 | assert('Object#tap') do 12 | ret = [] 13 | (1..10) .tap {|x| ret << "original: #{x.inspect}"} 14 | .to_a .tap {|x| ret << "array: #{x.inspect}"} 15 | .select {|x| x%2==0} .tap {|x| ret << "evens: #{x.inspect}"} 16 | .map { |x| x*x } .tap {|x| ret << "squares: #{x.inspect}"} 17 | 18 | assert_equal [ 19 | "original: 1..10", 20 | "array: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]", 21 | "evens: [2, 4, 6, 8, 10]", 22 | "squares: [4, 16, 36, 64, 100]" 23 | ], ret 24 | assert_equal(:tap_ok, Class.new {def m; tap{return :tap_ok}; end}.new.m) 25 | end 26 | 27 | assert('instance_exec on primitives with class and module definition') do 28 | begin 29 | class A 30 | 1.instance_exec do 31 | class B 32 | end 33 | end 34 | end 35 | 36 | assert_kind_of Class, A::B 37 | ensure 38 | Object.remove_const :A 39 | end 40 | 41 | begin 42 | class A 43 | 1.instance_exec do 44 | module B 45 | end 46 | end 47 | end 48 | 49 | assert_kind_of Module, A::B 50 | ensure 51 | Object.remove_const :A 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-objectspace/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-objectspace') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'ObjectSpace class' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-os-memsize/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-os-memsize') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'ObjectSpace memsize_of method' 5 | 6 | spec.add_dependency('mruby-objectspace', :core => 'mruby-objectspace') 7 | spec.add_test_dependency('mruby-metaprog', :core => 'mruby-metaprog') 8 | spec.add_test_dependency('mruby-method', :core => 'mruby-method') 9 | spec.add_test_dependency('mruby-fiber', :core => 'mruby-fiber') 10 | end 11 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-pack/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-pack') do |spec| 2 | spec.license = 'MIT' 3 | spec.authors = ['Internet Initiative Japan Inc.', 'mruby developers'] 4 | spec.summary = 'Array#pack and String#unpack method' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-print/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-print') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'standard print/puts/p' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-print/mrblib/print.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # Kernel 3 | # 4 | # ISO 15.3.1 5 | module Kernel 6 | ## 7 | # Print human readable object description 8 | # 9 | # ISO 15.3.1.2.9 Kernel.p 10 | # ISO 15.3.1.3.34 Kernel#p 11 | def p(*args) 12 | i = 0 13 | len = args.size 14 | while i < len 15 | print args[i].inspect, "\n" 16 | i += 1 17 | end 18 | args.__svalue 19 | end 20 | 21 | # ISO 15.3.1.2.11 Kernel.puts 22 | # ISO 15.3.1.3.39 Kernel#puts 23 | def puts(*args) 24 | i = 0 25 | len = args.size 26 | while i < len 27 | s = args[i] 28 | if s.kind_of?(Array) 29 | puts(*s) 30 | else 31 | s = s.to_s 32 | print s 33 | print "\n" if (s[-1] != "\n") 34 | end 35 | i += 1 36 | end 37 | print "\n" if len == 0 38 | end 39 | 40 | def printf(*args) 41 | print(sprintf(*args)) 42 | end 43 | end 44 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-proc-binding/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-proc-binding') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Proc#binding method' 5 | 6 | spec.add_dependency('mruby-binding', :core => 'mruby-binding') 7 | spec.add_dependency('mruby-proc-ext', :core => 'mruby-proc-ext') 8 | spec.add_test_dependency('mruby-eval', :core => 'mruby-eval') 9 | spec.add_test_dependency('mruby-compiler', :core => 'mruby-compiler') 10 | end 11 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-proc-binding/src/proc-binding.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | /* provided by mruby-proc-ext */ 7 | mrb_value mrb_proc_source_location(mrb_state *mrb, const struct RProc *p); 8 | 9 | /* provided by mruby-binding */ 10 | mrb_value mrb_binding_new(mrb_state *mrb, const struct RProc *proc, mrb_value recv, struct REnv *env); 11 | 12 | static mrb_value 13 | mrb_proc_binding(mrb_state *mrb, mrb_value procval) 14 | { 15 | const struct RProc *proc = mrb_proc_ptr(procval); 16 | struct REnv *env; 17 | 18 | mrb_value receiver; 19 | if (!proc || MRB_PROC_CFUNC_P(proc) || !proc->upper || MRB_PROC_CFUNC_P(proc->upper)) { 20 | env = NULL; 21 | proc = NULL; 22 | receiver = mrb_nil_value(); 23 | } 24 | else { 25 | env = MRB_PROC_ENV(proc); 26 | mrb_assert(env); 27 | proc = proc->upper; 28 | receiver = MRB_ENV_LEN(env) > 0 ? env->stack[0] : mrb_nil_value(); 29 | } 30 | 31 | mrb_value binding = mrb_binding_new(mrb, proc, receiver, env); 32 | mrb_iv_set(mrb, binding, MRB_SYM(source_location), mrb_proc_source_location(mrb, mrb_proc_ptr(procval))); 33 | return binding; 34 | } 35 | 36 | void 37 | mrb_mruby_proc_binding_gem_init(mrb_state *mrb) 38 | { 39 | mrb_define_method(mrb, mrb->proc_class, "binding", mrb_proc_binding, MRB_ARGS_NONE()); 40 | } 41 | 42 | void 43 | mrb_mruby_proc_binding_gem_final(mrb_state *mrb) 44 | { 45 | } 46 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-proc-binding/test/proc-binding.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static mrb_value 5 | proc_in_c(mrb_state *mrb, mrb_value self) 6 | { 7 | return mrb_load_string(mrb, "proc { |a, b| a + b }"); 8 | } 9 | 10 | void 11 | mrb_mruby_proc_binding_gem_test(mrb_state *mrb) 12 | { 13 | mrb_define_method(mrb, mrb->object_class, "proc_in_c", proc_in_c, MRB_ARGS_NONE()); 14 | } 15 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-proc-binding/test/proc-binding.rb: -------------------------------------------------------------------------------- 1 | assert "Proc#binding" do 2 | block = ->(i) {} 3 | a, b, c = 1, 2, 3 4 | bind = block.binding 5 | assert_equal([:a, :b, :bind, :block, :c], bind.local_variables.sort) 6 | assert_equal(1, bind.local_variable_get(:a)) 7 | assert_equal(5, bind.eval("b + c")) 8 | bind.local_variable_set(:x, 9) 9 | assert_equal(9, bind.local_variable_get(:x)) 10 | end 11 | 12 | assert("Binding#source_location after Proc#binding") do 13 | skip unless -> {}.source_location 14 | 15 | block, source_location = -> {}, [__FILE__, __LINE__] 16 | assert_equal source_location, block.binding.source_location 17 | end 18 | 19 | assert "Proc#binding and .eval from C" do 20 | bind = proc_in_c.binding 21 | assert_nothing_raised { bind.eval("self") } 22 | end 23 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-proc-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-proc-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Proc class extension' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-proc-ext/mrblib/proc.rb: -------------------------------------------------------------------------------- 1 | class Proc 2 | 3 | def ===(*args) 4 | call(*args) 5 | end 6 | 7 | def yield(*args) 8 | call(*args) 9 | end 10 | 11 | def to_proc 12 | self 13 | end 14 | 15 | def curry(arity=self.arity) 16 | type = :proc 17 | abs = lambda {|a| a < 0 ? -a - 1 : a} 18 | arity = abs[arity] 19 | if lambda? 20 | type = :lambda 21 | self_arity = self.arity 22 | if (self_arity >= 0 && arity != self_arity) || 23 | (self_arity < 0 && abs[self_arity] > arity) 24 | raise ArgumentError, "wrong number of arguments (given #{arity}, expected #{abs[self_arity]})" 25 | end 26 | end 27 | 28 | pproc = self 29 | make_curry = proc do |given_args=[]| 30 | __send__(type) do |*args| 31 | new_args = given_args + args 32 | if new_args.size >= arity 33 | pproc[*new_args] 34 | else 35 | make_curry[new_args] 36 | end 37 | end 38 | end 39 | make_curry.call 40 | end 41 | 42 | def <<(other) 43 | ->(*args, **opts, &block) { call(other.call(*args, **opts, &block)) } 44 | end 45 | 46 | def >>(other) 47 | ->(*args, **opts, &block) { other.call(call(*args, **opts, &block)) } 48 | end 49 | 50 | end 51 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-random/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-random') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Random class' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-range-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-range-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Range class extension' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-rational/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-rational') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Rational class' 5 | spec.build.defines << "MRB_USE_RATIONAL" 6 | spec.add_test_dependency('mruby-complex', :core => 'mruby-complex') 7 | end 8 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-rational/mrblib/rational.rb: -------------------------------------------------------------------------------- 1 | class Rational < Numeric 2 | def inspect 3 | "(#{to_s})" 4 | end 5 | 6 | def to_s 7 | "#{numerator}/#{denominator}" 8 | end 9 | end 10 | 11 | class Numeric 12 | def to_r 13 | Rational(self, 1) 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-set/LICENSE: -------------------------------------------------------------------------------- 1 | mruby-set 2 | 3 | Copyright (c) yui-knk 2016 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining 6 | a copy of this software and associated documentation files (the 7 | "Software"), to deal in the Software without restriction, including 8 | without limitation the rights to use, copy, modify, merge, publish, 9 | distribute, sublicense, and/or sell copies of the Software, and to 10 | permit persons to whom the Software is furnished to do so, subject to 11 | the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be 14 | included in all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | [ MIT license: http://www.opensource.org/licenses/mit-license.php ] 25 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-set/README.md: -------------------------------------------------------------------------------- 1 | # mruby-set 2 | 3 | Set class 4 | 5 | ## Example 6 | 7 | ```ruby 8 | set1 = Set.new([1,2]) 9 | set2 = Set[1,2,3] 10 | set3 = Set[4] 11 | 12 | set1 + set3 13 | #=> # 14 | set2 - set1 15 | #=> # 16 | set2 & set1 17 | #=> # 18 | set1 ^ set2 19 | #=> # 20 | ``` 21 | 22 | ## Limitations 23 | 24 | These methods are not implemented yet: 25 | 26 | - freeze 27 | - to_set 28 | - divide(Set#divide with 2 arity block is not implemented.) 29 | 30 | ## License 31 | 32 | Under the MIT License: 33 | 34 | - see [LICENSE](LICENSE) file 35 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-set/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-set') do |spec| 2 | spec.license = 'MIT' 3 | spec.authors = 'yui-knk' 4 | 5 | spec.add_dependency "mruby-hash-ext", :core => "mruby-hash-ext" 6 | spec.add_dependency "mruby-enumerator", :core => "mruby-enumerator" 7 | end 8 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-set/mruby-set.gem: -------------------------------------------------------------------------------- 1 | name: mruby-set 2 | description: Set class 3 | author: yui-knk 4 | website: https://github.com/yui-knk/mruby-set 5 | protocol: git 6 | repository: https://github.com/yui-knk/mruby-set.git 7 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-sleep/README.md: -------------------------------------------------------------------------------- 1 | # Sleep Module for mruby 2 | 3 | mruby sleep module 4 | 5 | ## Install by mrbgems 6 | 7 | - add `conf.gem` line to your build configuration. 8 | 9 | ```ruby 10 | MRuby::Build.new do |conf| 11 | 12 | # ... (snip) ... 13 | 14 | conf.gem :core => 'mruby-sleep' 15 | end 16 | ``` 17 | 18 | ## Example 19 | 20 | ```ruby 21 | sleep(10) 22 | usleep(10000) 23 | ``` 24 | 25 | # License 26 | 27 | under the MIT License: 28 | 29 | - 30 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-sleep/example/sleep.rb: -------------------------------------------------------------------------------- 1 | sleep(10) 2 | usleep(10000) 3 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-sleep/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-sleep') do |spec| 2 | spec.license = 'MIT' 3 | spec.authors = ['MATSUMOTO Ryosuke', 'mruby developers'] 4 | spec.summary = 'Kernel#sleep and Kernel#usleep' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-sleep/test/sleep_test.rb: -------------------------------------------------------------------------------- 1 | assert("sleep works") do 2 | assert_nothing_raised { sleep(1) } 3 | assert_nothing_raised { sleep(0) } 4 | end 5 | 6 | assert("sleep would accept non-negative float value") do 7 | skip unless Object.const_defined?(:Float) 8 | assert_nothing_raised { sleep(0.01) } 9 | assert_nothing_raised { sleep(0.0) } 10 | assert_nothing_raised { sleep(-0.0) } 11 | end 12 | 13 | assert("sleep would not accept negative integer value") do 14 | assert_raise(ArgumentError) { sleep(-1) } 15 | end 16 | 17 | assert("sleep would not accept negative float value") do 18 | skip unless Object.const_defined?(:Float) 19 | assert_raise(ArgumentError) { sleep(-0.1) } 20 | end 21 | 22 | assert("usleep works") do 23 | assert_nothing_raised { usleep(100) } 24 | assert_nothing_raised { usleep(0) } 25 | end 26 | 27 | assert("usleep would not accept negative value") do 28 | assert_raise(ArgumentError) { usleep(-100) } 29 | end 30 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-socket/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-socket') do |spec| 2 | spec.license = 'MIT' 3 | spec.authors = ['Internet Initiative Japan Inc.', 'mruby developers'] 4 | spec.summary = 'standard socket class' 5 | 6 | #spec.cc.defines << "HAVE_SA_LEN=0" 7 | 8 | # If Windows, use winsock 9 | if spec.for_windows? 10 | spec.linker.libraries << "wsock32" 11 | spec.linker.libraries << "ws2_32" 12 | end 13 | 14 | spec.add_dependency('mruby-io', :core => 'mruby-io') 15 | spec.add_dependency('mruby-error', :core => 'mruby-error') 16 | # spec.add_dependency('mruby-mtest') 17 | end 18 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-socket/src/gen.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | Dir.chdir(File.dirname($0)) 4 | 5 | f = File.open("const.cstub", "w") 6 | 7 | IO.readlines("const.def").each { |name| 8 | name.sub(/^#.*/, "") 9 | name.strip! 10 | next if name.empty? 11 | 12 | f.write <= 1 10 | a = ret[0] 11 | assert_equal "AF_INET", a[0] 12 | assert_equal 53, a[1] 13 | # documents says it's a hostname but CRuby returns an address 14 | #assert_equal "127.0.0.1", a[2] 15 | assert_equal "127.0.0.1", a[3] 16 | assert_equal Socket::AF_INET, a[4] 17 | assert_equal Socket::SOCK_DGRAM, a[5] 18 | assert_equal Socket::IPPROTO_UDP, a[6] unless SocketTest.cygwin? 19 | end 20 | 21 | assert('Socket#recvfrom') do 22 | begin 23 | sstr = "abcdefg" 24 | s = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0) 25 | c = Socket.new(Socket::AF_INET, Socket::SOCK_DGRAM, 0) 26 | s.bind(Socket.sockaddr_in(0, "127.0.0.1")) 27 | c.send sstr, 0, s.getsockname 28 | rstr, ai = s.recvfrom sstr.size 29 | 30 | assert_equal sstr, rstr 31 | assert_equal "127.0.0.1", ai.ip_address 32 | ensure 33 | s.close rescue nil 34 | c.close rescue nil 35 | end 36 | end 37 | 38 | end # win? 39 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-socket/test/tcpsocket.rb: -------------------------------------------------------------------------------- 1 | #assert('TCPSocket.gethostbyname') do 2 | #assert('TCPSocket.new') do 3 | #assert('TCPSocket#close') do 4 | #assert('TCPSocket#write') do 5 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-socket/test/udpsocket.rb: -------------------------------------------------------------------------------- 1 | assert('UDPSocket.new') do 2 | s = UDPSocket.new 3 | assert_true(s.is_a? UDPSocket) 4 | s.close 5 | s = UDPSocket.new(Socket::AF_INET6) 6 | assert_true(s.is_a? UDPSocket) 7 | s.close 8 | true 9 | end 10 | 11 | #assert('UDPSocket#connect') do 12 | #assert('UDPSocket#send') do 13 | #assert('UDPSocket#recv') do 14 | 15 | #assert('UDPSocket#bind') do 16 | #assert('UDPSocket#recvfrom_nonblock') do 17 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-sprintf/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-sprintf') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'standard Kernel#sprintf method' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-sprintf/mrblib/string.rb: -------------------------------------------------------------------------------- 1 | class String 2 | def %(args) 3 | if args.is_a? Array 4 | sprintf(self, *args) 5 | else 6 | sprintf(self, args) 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-string-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-string-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'String class extension' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-string-ext/test/numeric.rb: -------------------------------------------------------------------------------- 1 | assert('Integer#chr') do 2 | assert_equal("A", 65.chr) 3 | assert_equal("B", 0x42.chr) 4 | assert_equal("\xab", 171.chr) 5 | assert_raise(RangeError) { -1.chr } 6 | assert_raise(RangeError) { 256.chr } 7 | 8 | assert_equal("A", 65.chr("ASCII-8BIT")) 9 | assert_equal("B", 0x42.chr("BINARY")) 10 | assert_equal("\xab", 171.chr("ascii-8bit")) 11 | assert_raise(RangeError) { -1.chr("binary") } 12 | assert_raise(RangeError) { 256.chr("Ascii-8bit") } 13 | assert_raise(ArgumentError) { 65.chr("ASCII") } 14 | assert_raise(ArgumentError) { 65.chr("ASCII-8BIT", 2) } 15 | assert_raise(TypeError) { 65.chr(:BINARY) } 16 | 17 | if __ENCODING__ == "ASCII-8BIT" 18 | assert_raise(ArgumentError) { 65.chr("UTF-8") } 19 | else 20 | assert_equal("A", 65.chr("UTF-8")) 21 | assert_equal("B", 0x42.chr("UTF-8")) 22 | assert_equal("«", 171.chr("utf-8")) 23 | assert_equal("あ", 12354.chr("Utf-8")) 24 | assert_raise(RangeError) { -1.chr("utf-8") } 25 | assert_raise(RangeError) { 0x110000.chr.chr("UTF-8") } 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-string-ext/test/range.rb: -------------------------------------------------------------------------------- 1 | assert('Range#max') do 2 | # returns the maximum value in the range when called with no arguments 3 | assert_equal 'l', ('f'..'l').max 4 | assert_equal 'e', ('a'...'f').max 5 | 6 | # returns nil when the endpoint is less than the start point 7 | assert_equal nil, ('z'..'l').max 8 | end 9 | 10 | assert('Range#max given a block') do 11 | # returns nil when the endpoint is less than the start point 12 | assert_equal nil, (('z'..'l').max { |x, y| x <=> y }) 13 | end 14 | 15 | assert('Range#min') do 16 | # returns the minimum value in the range when called with no arguments 17 | assert_equal 'f', ('f'..'l').min 18 | 19 | # returns nil when the start point is greater than the endpoint 20 | assert_equal nil, ('z'..'l').min 21 | end 22 | 23 | assert('Range#min given a block') do 24 | # returns nil when the start point is greater than the endpoint 25 | assert_equal nil, (('z'..'l').min { |x, y| x <=> y }) 26 | end 27 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-struct/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-struct') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'standard Struct class' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-symbol-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-symbol-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'Symbol class extension' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-test-inline-struct/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-test-inline-struct') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'inline structure' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-test/README.md: -------------------------------------------------------------------------------- 1 | # Running Tests 2 | 3 | To run the tests, execute the following from the project's root directory. 4 | 5 | ``` 6 | $ make test 7 | ``` 8 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-time/include/mruby/time.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** mruby/time.h - Time class 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #ifndef MRUBY_TIME_H 8 | #define MRUBY_TIME_H 9 | 10 | #include "mruby/common.h" 11 | #include 12 | 13 | MRB_BEGIN_DECL 14 | 15 | typedef enum mrb_timezone { 16 | MRB_TIMEZONE_NONE = 0, 17 | MRB_TIMEZONE_UTC = 1, 18 | MRB_TIMEZONE_LOCAL = 2, 19 | MRB_TIMEZONE_LAST = 3 20 | } mrb_timezone; 21 | 22 | MRB_API mrb_value mrb_time_at(mrb_state *mrb, time_t sec, time_t usec, mrb_timezone timezone); 23 | 24 | MRB_END_DECL 25 | 26 | #endif /* MRUBY_TIME_H */ 27 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-time/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-time') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'standard Time class' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-toplevel-ext/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-toplevel-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'toplevel object (main) methods extension' 5 | end 6 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb: -------------------------------------------------------------------------------- 1 | def self.include(*modules) 2 | self.class.include(*modules) 3 | end 4 | 5 | def self.private(*methods) 6 | end 7 | def self.protected(*methods) 8 | end 9 | def self.public(*methods) 10 | end 11 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-toplevel-ext/test/toplevel.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # Toplevel Self(Ext) Test 3 | 4 | assert('Toplevel#include') do 5 | module ToplevelTestModule1 6 | def method_foo 7 | :foo 8 | end 9 | 10 | CONST_BAR = :bar 11 | end 12 | 13 | module ToplevelTestModule2 14 | CONST_BAR = :bar2 15 | end 16 | 17 | self.include ToplevelTestModule2, ToplevelTestModule1 18 | 19 | assert_true self.class.ancestors.include?( ToplevelTestModule1 ) 20 | assert_true self.class.ancestors.include?( ToplevelTestModule2 ) 21 | assert_equal :foo, method_foo 22 | assert_equal :bar2, CONST_BAR 23 | end 24 | -------------------------------------------------------------------------------- /mruby/mrbgems/stdlib-ext.gembox: -------------------------------------------------------------------------------- 1 | # It also works with MRB_NO_STDIO and MRB_NO_FLOAT. 2 | 3 | MRuby::GemBox.new do |conf| 4 | # Use standard Array#pack, String#unpack methods 5 | conf.gem :core => "mruby-pack" 6 | 7 | # Use standard Kernel#sprintf method 8 | conf.gem :core => "mruby-sprintf" 9 | 10 | # Use standard Time class 11 | conf.gem :core => "mruby-time" 12 | 13 | # Use standard Struct class 14 | conf.gem :core => "mruby-struct" 15 | 16 | # Use standard Data class 17 | conf.gem :core => "mruby-data" 18 | 19 | # Use Random class 20 | conf.gem :core => "mruby-random" 21 | end 22 | -------------------------------------------------------------------------------- /mruby/mrbgems/stdlib-io.gembox: -------------------------------------------------------------------------------- 1 | # It also works with MRB_NO_FLOAT. 2 | 3 | MRuby::GemBox.new do |conf| 4 | # Use standard IO/File class 5 | conf.gem :core => "mruby-io" 6 | 7 | # Use standard IO/File class 8 | conf.gem :core => "mruby-socket" 9 | 10 | # Use standard print/puts/p 11 | conf.gem :core => "mruby-print" 12 | 13 | # Use errno extension for a good mruby-io/mruby-socket experience 14 | conf.gem :core => "mruby-errno" 15 | 16 | # Use Dir class 17 | conf.gem :core => "mruby-dir" 18 | end 19 | -------------------------------------------------------------------------------- /mruby/mrblib/00class.rb: -------------------------------------------------------------------------------- 1 | class BasicObject 2 | def !=(other) 3 | if self == other 4 | false 5 | else 6 | true 7 | end 8 | end 9 | end 10 | 11 | class Module 12 | # 15.2.2.4.12 13 | def attr_accessor(*names) 14 | attr_reader(*names) 15 | attr_writer(*names) 16 | end 17 | # 15.2.2.4.11 18 | alias attr attr_reader 19 | #def attr(name) 20 | # attr_reader(name) 21 | #end 22 | 23 | # 15.2.2.4.27 24 | def include(*args) 25 | args.reverse! 26 | args.each do |m| 27 | m.append_features(self) 28 | m.included(self) 29 | end 30 | self 31 | end 32 | 33 | def prepend(*args) 34 | args.reverse! 35 | args.each do |m| 36 | m.prepend_features(self) 37 | m.prepended(self) 38 | end 39 | self 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /mruby/mrblib/00kernel.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | ## 3 | # call-seq: 4 | # obj.extend(module, ...) -> obj 5 | # 6 | # Adds to _obj_ the instance methods from each module given as a 7 | # parameter. 8 | # 9 | # module Mod 10 | # def hello 11 | # "Hello from Mod.\n" 12 | # end 13 | # end 14 | # 15 | # class Klass 16 | # def hello 17 | # "Hello from Klass.\n" 18 | # end 19 | # end 20 | # 21 | # k = Klass.new 22 | # k.hello #=> "Hello from Klass.\n" 23 | # k.extend(Mod) #=> # 24 | # k.hello #=> "Hello from Mod.\n" 25 | # 26 | # ISO 15.3.1.3.13 27 | def extend(*args) 28 | args.reverse! 29 | args.each do |m| 30 | m.extend_object(self) 31 | m.extended(self) 32 | end 33 | self 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /mruby/mrblib/10error.rb: -------------------------------------------------------------------------------- 1 | class Exception 2 | ## 3 | # call-seq: 4 | # exception.message -> string 5 | # 6 | # Returns the result of invoking exception.to_s. 7 | # Normally this returns the exception's message or name. 8 | # 9 | def message 10 | to_s 11 | end 12 | end 13 | 14 | # ISO 15.2.24 15 | class ArgumentError < StandardError 16 | end 17 | 18 | # ISO 15.2.25 19 | class LocalJumpError < StandardError 20 | end 21 | 22 | # ISO 15.2.26 23 | class RangeError < StandardError 24 | end 25 | 26 | class FloatDomainError < RangeError 27 | end 28 | 29 | # ISO 15.2.26 30 | class RegexpError < StandardError 31 | end 32 | 33 | # ISO 15.2.29 34 | class TypeError < StandardError 35 | end 36 | 37 | # ISO 15.2.30 38 | class ZeroDivisionError < StandardError 39 | end 40 | 41 | # ISO 15.2.31 42 | class NameError < StandardError 43 | attr_accessor :name 44 | 45 | def initialize(message=nil, name=nil) 46 | @name = name 47 | super(message) 48 | end 49 | end 50 | 51 | # ISO 15.2.32 52 | class NoMethodError < NameError 53 | attr_reader :args 54 | 55 | def initialize(message=nil, name=nil, args=nil) 56 | @args = args 57 | super message, name 58 | end 59 | end 60 | 61 | # ISO 15.2.33 62 | class IndexError < StandardError 63 | end 64 | 65 | class KeyError < IndexError 66 | end 67 | 68 | class NotImplementedError < ScriptError 69 | end 70 | 71 | class FrozenError < RuntimeError 72 | end 73 | 74 | class StopIteration < IndexError 75 | attr_accessor :result 76 | end 77 | -------------------------------------------------------------------------------- /mruby/mrblib/kernel.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # Kernel 3 | # 4 | # ISO 15.3.1 5 | module Kernel 6 | 7 | # 15.3.1.2.1 Kernel.` 8 | # provided by Kernel#` 9 | # 15.3.1.3.3 10 | def `(s) 11 | raise NotImplementedError.new("backquotes not implemented") 12 | end 13 | 14 | ## 15 | # 15.3.1.2.3 Kernel.eval 16 | # 15.3.1.3.12 Kernel#eval 17 | # NotImplemented by mruby core; use mruby-eval gem 18 | 19 | ## 20 | # ISO 15.3.1.2.8 Kernel.loop 21 | # provided by Kernel#loop 22 | 23 | ## 24 | # Calls the given block repetitively. 25 | # 26 | # ISO 15.3.1.3.29 27 | def loop(&block) 28 | return to_enum :loop unless block 29 | 30 | while true 31 | yield 32 | end 33 | rescue StopIteration => e 34 | e.result 35 | end 36 | 37 | # 11.4.4 Step c) 38 | def !~(y) 39 | !(self =~ y) 40 | end 41 | 42 | def to_enum(*a) 43 | raise NotImplementedError.new("fiber required for enumerator") 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /mruby/mrblib/symbol.rb: -------------------------------------------------------------------------------- 1 | class Symbol 2 | def to_proc 3 | ->(obj,*args,**opts,&block) do 4 | obj.__send__(self, *args, **opts, &block) 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /mruby/mruby-source.gemspec: -------------------------------------------------------------------------------- 1 | lib = File.expand_path('../lib', __FILE__) 2 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 3 | require 'mruby/source' 4 | 5 | Gem::Specification.new do |spec| 6 | spec.name = "mruby-source" 7 | spec.version = MRuby::Source::MRUBY_VERSION 8 | spec.authors = [ MRuby::Source::MRUBY_AUTHOR ] 9 | 10 | spec.summary = %q{mruby source code wrapper.} 11 | spec.description = %q{mruby source code wrapper for use with Ruby libs.} 12 | spec.homepage = "https://mruby.org" 13 | spec.license = "MIT" 14 | 15 | spec.files = `git ls-files -z`.split("\x0") 16 | spec.require_paths = ["lib"] 17 | end 18 | -------------------------------------------------------------------------------- /mruby/oss-fuzz/config/mruby_fuzzer.options: -------------------------------------------------------------------------------- 1 | [libfuzzer] 2 | close_fd_mask = 3 3 | dict = mruby.dict 4 | fork = 1 5 | only_ascii = 1 6 | -------------------------------------------------------------------------------- /mruby/oss-fuzz/config/mruby_proto_fuzzer.options: -------------------------------------------------------------------------------- 1 | [libfuzzer] 2 | close_fd_mask = 3 3 | dict = mruby.dict 4 | fork = 1 5 | -------------------------------------------------------------------------------- /mruby/oss-fuzz/mruby_fuzzer.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int LLVMFuzzerTestOneInput(uint8_t *Data, size_t size) { 7 | if (size < 1) { 8 | return 0; 9 | } 10 | char *code = malloc(size+1); 11 | memcpy(code, Data, size); 12 | code[size] = '\0'; 13 | mrb_state *mrb = mrb_open(); 14 | mrb_load_string(mrb, code); 15 | mrb_close(mrb); 16 | free(code); 17 | return 0; 18 | } 19 | -------------------------------------------------------------------------------- /mruby/oss-fuzz/mruby_proto_fuzzer.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include 6 | #include 7 | 8 | #include 9 | #include 10 | #include "proto_to_ruby.h" 11 | 12 | using namespace ruby_fuzzer; 13 | using namespace std; 14 | 15 | int FuzzRB(const uint8_t *Data, size_t size) { 16 | mrb_value v; 17 | mrb_state *mrb = mrb_open(); 18 | if (!mrb) 19 | return 0; 20 | 21 | char *code = (char*)malloc(size+1); 22 | if (!code) 23 | return 0; 24 | memcpy(code, Data, size); 25 | code[size] = '\0'; 26 | 27 | if (const char *dump_path = getenv("PROTO_FUZZER_DUMP_PATH")) { 28 | // With libFuzzer binary run this to generate an RB file x.rb: 29 | // PROTO_FUZZER_DUMP_PATH=x.rb ./a.out proto-input 30 | std::ofstream of(dump_path); 31 | of.write(code, size); 32 | } 33 | std::cout << "\n\n############\n" << code << "\n############\n\n"; 34 | v = mrb_load_string(mrb, code); 35 | mrb_close(mrb); 36 | 37 | free(code); 38 | return 0; 39 | } 40 | 41 | DEFINE_PROTO_FUZZER(const Function &function) { 42 | protoConverter converter; 43 | auto s = converter.FunctionToString(function); 44 | (void)FuzzRB((const uint8_t*)s.data(), s.size()); 45 | } 46 | -------------------------------------------------------------------------------- /mruby/src/allocf.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** allocf.c - default memory allocation function 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #include 8 | #include "mruby.h" 9 | 10 | /* This function serves as the default memory allocation function and accepts four arguments: 11 | * 12 | * - `mrb`: An instance of `mrb_state`. It's important to note that for the initial allocation (used to allocate the `mrb_state` itself), `mrb` is set to NULL. 13 | * - `p`: The previous pointer to the memory region. For memory allocation, this parameter is NULL. 14 | * - `size`: The new size of the memory region to be returned. 15 | * - `ud`: User data, represented as a `void*`, which is passed to the `mrb_state`. 16 | */ 17 | 18 | void* 19 | mrb_default_allocf(mrb_state *mrb, void *p, size_t size, void *ud) 20 | { 21 | if (size == 0) { 22 | /* `free(NULL)` should be no-op */ 23 | free(p); 24 | return NULL; 25 | } 26 | else { 27 | /* `ralloc(NULL, size)` works as `malloc(size)` */ 28 | return realloc(p, size); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /mruby/src/enum.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** enum.c - Enumerable module 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | /* internal method `__update_hash(oldhash, index, itemhash)` */ 12 | static mrb_value 13 | enum_update_hash(mrb_state *mrb, mrb_value self) 14 | { 15 | mrb_int hash; 16 | mrb_int index; 17 | mrb_int hv; 18 | 19 | mrb_get_args(mrb, "iii", &hash, &index, &hv); 20 | hash ^= ((uint32_t)hv << (index % 16)); 21 | 22 | return mrb_int_value(mrb, hash); 23 | } 24 | 25 | void 26 | mrb_init_enumerable(mrb_state *mrb) 27 | { 28 | struct RClass *enumerable; 29 | enumerable = mrb_define_module_id(mrb, MRB_SYM(Enumerable)); /* 15.3.2 */ 30 | mrb_define_module_function_id(mrb, enumerable, MRB_SYM(__update_hash), enum_update_hash, MRB_ARGS_REQ(3)); 31 | } 32 | -------------------------------------------------------------------------------- /mruby/src/error.h: -------------------------------------------------------------------------------- 1 | /* this header file is to be removed soon. 2 | added for compatibility purpose (1.0.0) */ 3 | #include 4 | -------------------------------------------------------------------------------- /mruby/src/init.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** init.c - initialize mruby core 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #include 8 | 9 | void mrb_init_symtbl(mrb_state*); 10 | void mrb_init_class(mrb_state*); 11 | void mrb_init_object(mrb_state*); 12 | void mrb_init_kernel(mrb_state*); 13 | void mrb_init_enumerable(mrb_state*); 14 | void mrb_init_symbol(mrb_state*); 15 | void mrb_init_string(mrb_state*); 16 | void mrb_init_exception(mrb_state*); 17 | void mrb_init_proc(mrb_state*); 18 | void mrb_init_array(mrb_state*); 19 | void mrb_init_hash(mrb_state*); 20 | void mrb_init_numeric(mrb_state*); 21 | void mrb_init_range(mrb_state*); 22 | void mrb_init_gc(mrb_state*); 23 | void mrb_init_math(mrb_state*); 24 | void mrb_init_version(mrb_state*); 25 | void mrb_init_mrblib(mrb_state*); 26 | 27 | #define DONE mrb_gc_arena_restore(mrb, 0); 28 | void 29 | mrb_init_core(mrb_state *mrb) 30 | { 31 | mrb_init_symtbl(mrb); DONE; 32 | 33 | mrb_init_class(mrb); DONE; 34 | mrb_init_object(mrb); DONE; 35 | mrb_init_kernel(mrb); DONE; 36 | mrb_init_enumerable(mrb); DONE; 37 | 38 | mrb_init_symbol(mrb); DONE; 39 | mrb_init_string(mrb); DONE; 40 | mrb_init_exception(mrb); DONE; 41 | mrb_init_proc(mrb); DONE; 42 | mrb_init_array(mrb); DONE; 43 | mrb_init_hash(mrb); DONE; 44 | mrb_init_numeric(mrb); DONE; 45 | mrb_init_range(mrb); DONE; 46 | mrb_init_gc(mrb); DONE; 47 | mrb_init_version(mrb); DONE; 48 | mrb_init_mrblib(mrb); DONE; 49 | } 50 | -------------------------------------------------------------------------------- /mruby/src/opcode.h: -------------------------------------------------------------------------------- 1 | /* this header file is to be removed soon. */ 2 | #include 3 | -------------------------------------------------------------------------------- /mruby/src/readint.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | /* mrb_read_int(): read mrb_int from a string (base 10 only) */ 5 | /* const char *p - string to read */ 6 | /* const char *e - end of string */ 7 | /* char **endp - end of parsed integer */ 8 | /* mrb_int *np - variable to save the result */ 9 | /* returns TRUE if read succeeded */ 10 | /* if integer overflows, returns FALSE */ 11 | MRB_API mrb_bool 12 | mrb_read_int(const char *p, const char *e, char **endp, mrb_int *np) 13 | { 14 | mrb_int n = 0; 15 | int ch; 16 | 17 | while ((e == NULL || p < e) && ISDIGIT(*p)) { 18 | ch = *p - '0'; 19 | if (mrb_int_mul_overflow(n, 10, &n) || 20 | mrb_int_add_overflow(n, ch, &n)) { 21 | return FALSE; 22 | } 23 | p++; 24 | } 25 | if (endp) *endp = (char*)p; 26 | *np = n; 27 | return TRUE; 28 | } 29 | -------------------------------------------------------------------------------- /mruby/src/readnum.c: -------------------------------------------------------------------------------- 1 | /* this file defines obsolete functions: mrb_int_read() and mrb_float_read() */ 2 | /* use mrb_read_int() and mrb_read_float() instead */ 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | /* mrb_int_read(): read mrb_int from a string (base 10 only) */ 9 | /* const char *p - string to read */ 10 | /* const char *e - end of string */ 11 | /* char **endp - end of parsed integer */ 12 | 13 | /* if integer overflows, errno will be set to ERANGE */ 14 | /* also endp will be set to NULL on overflow */ 15 | MRB_API mrb_int 16 | mrb_int_read(const char *p, const char *e, char **endp) 17 | { 18 | mrb_int n; 19 | 20 | if (!mrb_read_int(p, e, endp, &n)) { 21 | if (endp) *endp = NULL; 22 | errno = ERANGE; 23 | return MRB_INT_MAX; 24 | } 25 | if (endp) *endp = (char*)p; 26 | return n; 27 | } 28 | 29 | #ifndef MRB_NO_FLOAT 30 | //#include 31 | //#include 32 | 33 | MRB_API double 34 | mrb_float_read(const char *str, char **endp) 35 | { 36 | double d; 37 | 38 | if (!mrb_read_float(str, endp, &d)) { 39 | errno = ERANGE; 40 | } 41 | return d; 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /mruby/src/value_array.h: -------------------------------------------------------------------------------- 1 | #ifndef MRB_VALUE_ARRAY_H__ 2 | #define MRB_VALUE_ARRAY_H__ 3 | 4 | #include 5 | 6 | static inline void 7 | value_move(mrb_value *s1, const mrb_value *s2, size_t n) 8 | { 9 | if (n == 0) return; 10 | if (s1 > s2 && s1 < s2 + n) 11 | { 12 | s1 += n; 13 | s2 += n; 14 | while (n-- > 0) { 15 | *--s1 = *--s2; 16 | } 17 | } 18 | else if (s1 != s2) { 19 | while (n-- > 0) { 20 | *s1++ = *s2++; 21 | } 22 | } 23 | else { 24 | /* nothing to do. */ 25 | } 26 | } 27 | 28 | #endif /* MRB_VALUE_ARRAY_H__ */ 29 | -------------------------------------------------------------------------------- /mruby/src/version.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void 5 | mrb_init_version(mrb_state* mrb) 6 | { 7 | mrb_value mruby_version = mrb_str_new_lit(mrb, MRUBY_VERSION); 8 | 9 | mrb_define_global_const(mrb, "RUBY_VERSION", mrb_str_new_lit(mrb, MRUBY_RUBY_VERSION)); 10 | mrb_define_global_const(mrb, "RUBY_ENGINE", mrb_str_new_lit(mrb, MRUBY_RUBY_ENGINE)); 11 | mrb_define_global_const(mrb, "RUBY_ENGINE_VERSION", mruby_version); 12 | mrb_define_global_const(mrb, "MRUBY_VERSION", mruby_version); 13 | mrb_define_global_const(mrb, "MRUBY_RELEASE_NO", mrb_fixnum_value(MRUBY_RELEASE_NO)); 14 | mrb_define_global_const(mrb, "MRUBY_RELEASE_DATE", mrb_str_new_lit(mrb, MRUBY_RELEASE_DATE)); 15 | mrb_define_global_const(mrb, "MRUBY_DESCRIPTION", mrb_str_new_lit(mrb, MRUBY_DESCRIPTION)); 16 | mrb_define_global_const(mrb, "MRUBY_COPYRIGHT", mrb_str_new_lit(mrb, MRUBY_COPYRIGHT)); 17 | } 18 | -------------------------------------------------------------------------------- /mruby/tasks/bin.rake: -------------------------------------------------------------------------------- 1 | MRuby.each_target do |build| 2 | if build.host? && build.mrbc_build && !build.gems["mruby-bin-mrbc"] 3 | exe = build.exefile("#{build.mrbc_build.build_dir}/bin/mrbc") 4 | build.products << build.define_installer(exe) 5 | end 6 | 7 | build.bins.each{|bin| build.products << define_installer_if_needed(bin)} 8 | 9 | build.gems.each do |gem| 10 | linker_attrs = build.gems.linker_attrs(gem) 11 | gem.bins.each do |bin| 12 | exe = build.exefile("#{build.build_dir}/bin/#{bin}") 13 | objs = Dir["#{gem.dir}/tools/#{bin}/*.{c,cpp,cxx,cc}"].map do |f| 14 | build.objfile(f.pathmap("#{gem.build_dir}/tools/#{bin}/%n")) 15 | end 16 | file exe => objs.concat(build.libraries) do |t| 17 | build.linker.run t.name, t.prerequisites, *linker_attrs 18 | end 19 | 20 | build.products << define_installer_if_needed(bin) 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /mruby/tasks/core.rake: -------------------------------------------------------------------------------- 1 | as_cxx_srcs = %w[vm error gc].map{|name| "#{MRUBY_ROOT}/src/#{name}.c"} 2 | 3 | MRuby.each_target do 4 | objs = Dir.glob("#{MRUBY_ROOT}/src/*.c").map do |src| 5 | if cxx_exception_enabled? && as_cxx_srcs.include?(src) 6 | compile_as_cxx(src) 7 | else 8 | objfile(src.pathmap("#{build_dir}/src/%n")) 9 | end 10 | end 11 | self.libmruby_core_objs << objs 12 | end 13 | -------------------------------------------------------------------------------- /mruby/tasks/install.rake: -------------------------------------------------------------------------------- 1 | desc "install compiled products (on host)" 2 | task :install => "install:full:host" 3 | 4 | desc "install compiled executable (on host)" 5 | task :install_bin => "install:bin:host" 6 | 7 | desc "install compiled products (all build targets)" 8 | task "install:full" 9 | 10 | desc "install compiled executable (all build targets)" 11 | task "install:bin" 12 | 13 | MRuby.each_target do |build| 14 | next if build.internal? 15 | 16 | prefix = File.join(MRuby::INSTALL_DESTDIR, build.install_prefix) 17 | 18 | task "install:full" => "install:full:#{build.name}" 19 | 20 | task "install:full:#{build.name}" => "install:bin:#{build.name}" do 21 | Dir.glob(File.join(build.build_dir.gsub(/[\[\{\*\?]/, "\\\0"), "{include,lib}/**/*")) do |path| 22 | install_D path, File.join(prefix, path.relative_path_from(build.build_dir)) if File.file? path 23 | end 24 | end 25 | 26 | task "install:bin" => "install:bin:#{build.name}" 27 | 28 | task "install:bin:#{build.name}" => "all" do 29 | Dir.glob(File.join(build.build_dir.gsub(/[\[\{\*\?]/, "\\\0"), "{bin,host-bin}/**/*")) do |path| 30 | install_D path, File.join(prefix, path.relative_path_from(build.build_dir)) if File.file? path 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /mruby/tasks/mrblib.rake: -------------------------------------------------------------------------------- 1 | MRuby.each_target do 2 | next unless libmruby_enabled? 3 | 4 | src = "#{build_dir}/mrblib/mrblib.c" 5 | rbfiles = Dir["#{MRUBY_ROOT}/mrblib/*.rb"].sort! 6 | 7 | self.libmruby_objs << objfile(src.ext) 8 | 9 | file src => [mrbcfile, __FILE__, *rbfiles] do |t| 10 | if presym_enabled? 11 | cdump = true 12 | suffix = "proc" 13 | else 14 | cdump = false 15 | suffix = "irep" 16 | end 17 | mkdir_p File.dirname(t.name) 18 | File.open(t.name, 'w') do |f| 19 | _pp "GEN", "mrblib/*.rb", "#{t.name.relative_path}" 20 | f.puts %Q[/*] 21 | f.puts %Q[ * This file is loading the mrblib] 22 | f.puts %Q[ *] 23 | f.puts %Q[ * IMPORTANT:] 24 | f.puts %Q[ * This file was generated!] 25 | f.puts %Q[ * All manual changes will get lost.] 26 | f.puts %Q[ */] 27 | unless presym_enabled? 28 | f.puts %Q[#include ] 29 | f.puts %Q[#include ] 30 | end 31 | mrbc.run f, rbfiles, "mrblib_#{suffix}", cdump: cdump, static: true 32 | f.puts %Q[void] 33 | f.puts %Q[mrb_init_mrblib(mrb_state *mrb)] 34 | f.puts %Q[{] 35 | f.puts %Q[ mrblib_#{suffix}_init_syms(mrb);] if cdump 36 | f.puts %Q[ mrb_load_#{suffix}(mrb, mrblib_#{suffix});] 37 | f.puts %Q[}] 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /mruby/tasks/toolchains/clang.rake: -------------------------------------------------------------------------------- 1 | MRuby::Toolchain.new(:clang) do |conf, _params| 2 | toolchain :gcc, default_command: 'clang' 3 | 4 | [conf.cc, conf.objc, conf.asm].each do |cc| 5 | cc.flags << '-Wzero-length-array' unless ENV['CFLAGS'] 6 | end 7 | conf.cxx.flags << '-Wzero-length-array' unless ENV['CXXFLAGS'] || ENV['CFLAGS'] 8 | end 9 | -------------------------------------------------------------------------------- /mruby/tasks/toolchains/openwrt.rake: -------------------------------------------------------------------------------- 1 | # usage of environmental variables to set the 2 | # cross compiling toolchain proper 3 | MRuby::Toolchain.new(:openwrt) do |conf| 4 | [conf.cc, conf.cxx, conf.objc, conf.asm].each do |cc| 5 | if cc == conf.cxx 6 | cc.command = ENV['TARGET_CXX'] 7 | cc.flags = ENV['TARGET_CXXFLAGS'] 8 | else 9 | cc.command = ENV['TARGET_CC'] 10 | cc.flags = ENV['TARGET_CFLAGS'] 11 | end 12 | cc.option_include_path = %q[-I"%s"] 13 | cc.option_define = '-D%s' 14 | cc.compile_options = '%{flags} -MMD -o "%{outfile}" -c "%{infile}"' 15 | cc.preprocess_options = '%{flags} -o "%{outfile}" -E -P "%{infile}"' 16 | end 17 | 18 | conf.linker do |linker| 19 | linker.command = ENV['TARGET_CC'] 20 | linker.flags = ENV['TARGET_LDFLAGS'] 21 | linker.libraries = %w(m) 22 | linker.library_paths = [] 23 | linker.option_library = '-l%s' 24 | linker.option_library_path = '-L%s' 25 | linker.link_options = '%{flags} -o "%{outfile}" %{objs} %{flags_before_libraries} %{libs} %{flags_after_libraries}' 26 | end 27 | 28 | conf.archiver do |archiver| 29 | archiver.command = ENV['TARGET_AR'] 30 | archiver.archive_options = 'rs "%{outfile}" %{objs}' 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /mruby/test/bintest.rb: -------------------------------------------------------------------------------- 1 | $:.unshift File.dirname(File.dirname(File.expand_path(__FILE__))) 2 | require 'test/assert.rb' 3 | 4 | GEMNAME = "" 5 | 6 | def cmd_list(s) 7 | path = s == "mrbc" ? ENV['MRBCFILE'] : "#{ENV['BUILD_DIR']}/bin/#{s}" 8 | path = path.sub(/\.exe\z/, "") 9 | if /mswin(?!ce)|mingw|bccwin/ =~ RbConfig::CONFIG['host_os'] 10 | path = "#{path}.exe".tr("/", "\\") 11 | end 12 | 13 | path_list = [path] 14 | 15 | emu = ENV['EMULATOR'] 16 | path_list.unshift emu if emu && !emu.empty? 17 | 18 | path_list 19 | end 20 | 21 | def cmd(s) 22 | cmd_list(s).join(' ') 23 | end 24 | 25 | def cmd_bin(s) 26 | cmd_list(s).pop 27 | end 28 | 29 | def shellquote(s) 30 | case RbConfig::CONFIG['host_os'] 31 | when /mswin(?!ce)|mingw|bccwin/ 32 | "\"#{s}\"" 33 | else 34 | "'#{s}'" 35 | end 36 | end 37 | 38 | print "bintest - Command Binary Test\n\n" 39 | 40 | ARGV.each do |gem| 41 | case gem 42 | when '-v'; $mrbtest_verbose = true 43 | end 44 | 45 | case RbConfig::CONFIG['host_os'] 46 | when /mswin(?!ce)|mingw|bccwin/ 47 | gem = gem.tr('\\', '/') 48 | end 49 | 50 | Dir["#{gem}/bintest/**/*.rb"].each do |file| 51 | GEMNAME.replace(File.basename(gem)) 52 | load file 53 | end 54 | end 55 | 56 | exit report 57 | -------------------------------------------------------------------------------- /mruby/test/t/argumenterror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # ArgumentError ISO Test 3 | 4 | def assert_argnum_error(given, expected, &block) 5 | assert("wrong number of arguments") do 6 | message = "wrong number of arguments (given #{given}, expected #{expected})" 7 | assert_raise_with_message(ArgumentError, message, &block) 8 | end 9 | end 10 | 11 | assert('ArgumentError', '15.2.24') do 12 | e2 = nil 13 | a = [] 14 | begin 15 | # this will cause an exception due to the wrong arguments 16 | a[] 17 | rescue => e1 18 | e2 = e1 19 | end 20 | 21 | assert_equal(Class, ArgumentError.class) 22 | assert_equal(ArgumentError, e2.class) 23 | end 24 | 25 | assert("'wrong number of arguments' from mrb_get_args") do 26 | assert_argnum_error(0, "1+"){__send__} 27 | assert_argnum_error(0, 1..2){Object.const_defined?} 28 | assert_argnum_error(3, 1..2){Object.const_defined?(:A, true, 2)} 29 | assert_argnum_error(2, 0..1){{}.default(1, 2)} 30 | assert_argnum_error(1, 2){Object.const_set(:B)} 31 | assert_argnum_error(3, 2){Object.const_set(:C, 1, 2)} 32 | end 33 | 34 | assert('Call to MRB_ARGS_NONE method') do 35 | assert_raise(ArgumentError) { nil.__id__ 1 } 36 | assert_raise(ArgumentError) { nil.__id__ opts: 1 } 37 | end 38 | -------------------------------------------------------------------------------- /mruby/test/t/basicobject.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # BasicObject 3 | 4 | assert('BasicObject') do 5 | assert_equal(Class, BasicObject.class) 6 | end 7 | 8 | assert('BasicObject superclass') do 9 | assert_nil(BasicObject.superclass) 10 | end 11 | -------------------------------------------------------------------------------- /mruby/test/t/bs_literal.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # Bootstrap test for literals 3 | 4 | assert('BS Literal 1') do 5 | assert_true true 6 | end 7 | 8 | assert('BS Literal 2') do 9 | assert_equal TrueClass, true.class 10 | end 11 | 12 | assert('BS Literal 3') do 13 | assert_false false 14 | end 15 | 16 | assert('BS Literal 4') do 17 | assert_equal FalseClass, false.class 18 | end 19 | 20 | assert('BS Literal 5') do 21 | assert_equal 'nil', nil.inspect 22 | end 23 | 24 | assert('BS Literal 6') do 25 | assert_equal NilClass, nil.class 26 | end 27 | 28 | assert('BS Literal 7') do 29 | assert_equal Symbol, :sym.class 30 | end 31 | 32 | assert('BS Literal 8') do 33 | assert_equal 1234, 1234 34 | end 35 | 36 | assert('BS Literal 9') do 37 | assert_equal Integer, 1234.class 38 | end 39 | -------------------------------------------------------------------------------- /mruby/test/t/ensure.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # ensure Test 3 | 4 | class EnsureYieldBreak 5 | attr_reader :ensure_context 6 | def try 7 | yield 8 | ensure 9 | @ensure_context = self 10 | end 11 | end 12 | 13 | assert('ensure - context - yield') do 14 | yielder = EnsureYieldBreak.new 15 | yielder.try do 16 | end 17 | assert_equal yielder, yielder.ensure_context 18 | end 19 | 20 | assert('ensure - context - yield and break') do 21 | yielder = EnsureYieldBreak.new 22 | yielder.try do 23 | break 24 | end 25 | assert_equal yielder, yielder.ensure_context 26 | end 27 | 28 | assert('ensure - context - yield and return') do 29 | yielder = EnsureYieldBreak.new 30 | lambda do 31 | yielder.try do 32 | return 33 | end 34 | end.call 35 | assert_equal yielder, yielder.ensure_context 36 | end 37 | -------------------------------------------------------------------------------- /mruby/test/t/false.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # FalseClass ISO Test 3 | 4 | assert('FalseClass', '15.2.6') do 5 | assert_equal Class, FalseClass.class 6 | end 7 | 8 | assert('FalseClass false', '15.2.6.1') do 9 | assert_false false 10 | assert_equal FalseClass, false.class 11 | assert_false FalseClass.method_defined? :new 12 | end 13 | 14 | assert('FalseClass#&', '15.2.6.3.1') do 15 | assert_false false.&(true) 16 | assert_false false.&(false) 17 | end 18 | 19 | assert('FalseClass#^', '15.2.6.3.2') do 20 | assert_true false.^(true) 21 | assert_false false.^(false) 22 | end 23 | 24 | assert('FalseClass#to_s', '15.2.6.3.3') do 25 | assert_equal 'false', false.to_s 26 | end 27 | 28 | assert('FalseClass#|', '15.2.6.3.4') do 29 | assert_true false.|(true) 30 | assert_false false.|(false) 31 | end 32 | -------------------------------------------------------------------------------- /mruby/test/t/gc.rb: -------------------------------------------------------------------------------- 1 | # Not ISO specified 2 | 3 | assert('GC.enable') do 4 | assert_false GC.disable 5 | assert_true GC.enable 6 | assert_false GC.enable 7 | end 8 | 9 | assert('GC.disable') do 10 | begin 11 | assert_false GC.disable 12 | assert_true GC.disable 13 | ensure 14 | GC.enable 15 | end 16 | end 17 | 18 | assert('GC.interval_ratio=') do 19 | origin = GC.interval_ratio 20 | begin 21 | assert_equal 150, (GC.interval_ratio = 150) 22 | ensure 23 | GC.interval_ratio = origin 24 | end 25 | end 26 | 27 | assert('GC.step_ratio=') do 28 | origin = GC.step_ratio 29 | begin 30 | assert_equal 150, (GC.step_ratio = 150) 31 | ensure 32 | GC.step_ratio = origin 33 | end 34 | end 35 | 36 | assert('GC.generational_mode=') do 37 | origin = GC.generational_mode 38 | begin 39 | assert_false (GC.generational_mode = false) 40 | assert_true (GC.generational_mode = true) 41 | assert_true (GC.generational_mode = true) 42 | ensure 43 | GC.generational_mode = origin 44 | end 45 | end 46 | -------------------------------------------------------------------------------- /mruby/test/t/indexerror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # IndexError ISO Test 3 | 4 | assert('IndexError', '15.2.33') do 5 | assert_equal Class, IndexError.class 6 | end 7 | -------------------------------------------------------------------------------- /mruby/test/t/iterations.rb: -------------------------------------------------------------------------------- 1 | assert('while expression', '11.5.2.3.2') do 2 | idx = 10 3 | all = [] 4 | res = while idx > 0 5 | all << idx 6 | idx -= 1 7 | end 8 | 9 | assert_equal nil, res 10 | assert_equal [10,9,8,7,6,5,4,3,2,1], all 11 | end 12 | 13 | assert('until expression', '11.5.2.3.3') do 14 | idx = 10 15 | all = [] 16 | res = until idx == 0 17 | all << idx 18 | idx -= 1 19 | end 20 | 21 | assert_equal nil, res 22 | assert_equal [10,9,8,7,6,5,4,3,2,1], all 23 | end 24 | 25 | assert('break expression', '11.5.2.4.3') do 26 | assert_equal :result do 27 | while true 28 | break :result 29 | end 30 | end 31 | 32 | assert_equal :result do 33 | until false 34 | break :result 35 | end 36 | end 37 | end 38 | 39 | assert('next expression', '11.5.2.4.4') do 40 | assert_equal [8,6,4,2,0] do 41 | all = [] 42 | idx = 10 43 | while idx > 0 44 | idx -= 1 45 | next if (idx % 2) == 1 46 | all << idx 47 | end 48 | all 49 | end 50 | 51 | assert_equal [8,6,4,2,0] do 52 | all = [] 53 | idx = 10 54 | until idx == 0 55 | idx -= 1 56 | next if (idx % 2) == 1 57 | all << idx 58 | end 59 | all 60 | end 61 | end 62 | -------------------------------------------------------------------------------- /mruby/test/t/localjumperror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # LocalJumpError ISO Test 3 | 4 | assert('LocalJumpError', '15.2.25') do 5 | assert_equal Class, LocalJumpError.class 6 | # assert_raise LocalJumpError do 7 | # # this will cause an exception due to the wrong location 8 | # retry 9 | # end 10 | end 11 | 12 | # TODO 15.2.25.2.1 LocalJumpError#exit_value 13 | # TODO 15.2.25.2.2 LocalJumpError#reason 14 | -------------------------------------------------------------------------------- /mruby/test/t/nameerror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # NameError ISO Test 3 | 4 | assert('NameError', '15.2.31') do 5 | assert_equal Class, NameError.class 6 | end 7 | 8 | assert('NameError#name', '15.2.31.2.1') do 9 | 10 | # This check is not duplicate with 15.2.31.2.2 check. 11 | # Because the NameError in this test is generated in 12 | # C API. 13 | class TestDummy 14 | alias foo bar 15 | rescue NameError => e 16 | $test_dummy_result = e.name 17 | end 18 | 19 | assert_equal :bar, $test_dummy_result 20 | end 21 | 22 | assert('NameError#initialize', '15.2.31.2.2') do 23 | e = NameError.new('a', :foo) 24 | 25 | assert_equal NameError, e.class 26 | assert_equal 'a', e.message 27 | assert_equal :foo, e.name 28 | end 29 | -------------------------------------------------------------------------------- /mruby/test/t/nil.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # NilClass ISO Test 3 | 4 | assert('NilClass', '15.2.4') do 5 | assert_equal Class, NilClass.class 6 | end 7 | 8 | assert('NilClass', '15.2.4.1') do 9 | assert_equal NilClass, nil.class 10 | assert_false NilClass.method_defined? :new 11 | end 12 | 13 | assert('NilClass#&', '15.2.4.3.1') do 14 | assert_false nil.&(true) 15 | assert_false nil.&(nil) 16 | end 17 | 18 | assert('NilClass#^', '15.2.4.3.2') do 19 | assert_true nil.^(true) 20 | assert_false nil.^(false) 21 | end 22 | 23 | assert('NilClass#|', '15.2.4.3.3') do 24 | assert_true nil.|(true) 25 | assert_false nil.|(false) 26 | end 27 | 28 | assert('NilClass#nil?', '15.2.4.3.4') do 29 | assert_true nil.nil? 30 | end 31 | 32 | assert('NilClass#to_s', '15.2.4.3.5') do 33 | assert_equal '', nil.to_s 34 | end 35 | 36 | assert('safe navigation') do 37 | assert_nil nil&.size 38 | assert_equal 0, []&.size 39 | end 40 | -------------------------------------------------------------------------------- /mruby/test/t/nomethoderror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # NoMethodError ISO Test 3 | 4 | assert('NoMethodError', '15.2.32') do 5 | NoMethodError.class == Class 6 | assert_raise NoMethodError do 7 | doesNotExistAsAMethodNameForVerySure("") 8 | end 9 | end 10 | 11 | assert('NoMethodError#args', '15.2.32.2.1') do 12 | a = NoMethodError.new 'test', :test, [1, 2] 13 | assert_equal [1, 2], a.args 14 | 15 | assert_nothing_raised do 16 | begin 17 | doesNotExistAsAMethodNameForVerySure 3, 1, 4 18 | rescue NoMethodError => e 19 | assert_equal [3, 1, 4], e.args 20 | end 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /mruby/test/t/object.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # Object ISO Test 3 | 4 | assert('Object', '15.2.1') do 5 | assert_equal Class, Object.class 6 | end 7 | 8 | assert('Object superclass', '15.2.1.2') do 9 | assert_equal BasicObject, Object.superclass 10 | end 11 | -------------------------------------------------------------------------------- /mruby/test/t/rangeerror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # RangeError ISO Test 3 | 4 | assert('RangeError', '15.2.26') do 5 | assert_equal Class, RangeError.class 6 | end 7 | -------------------------------------------------------------------------------- /mruby/test/t/regexperror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # RegexpError ISO Test 3 | 4 | # TODO broken ATM assert('RegexpError', '15.2.27') do 5 | -------------------------------------------------------------------------------- /mruby/test/t/runtimeerror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # RuntimeError ISO Test 3 | 4 | assert('RuntimeError', '15.2.28') do 5 | assert_equal Class, RuntimeError.class 6 | end 7 | -------------------------------------------------------------------------------- /mruby/test/t/standarderror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # StandardError ISO Test 3 | 4 | assert('StandardError', '15.2.23') do 5 | assert_equal Class, StandardError.class 6 | end 7 | -------------------------------------------------------------------------------- /mruby/test/t/symbol.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # Symbol ISO Test 3 | 4 | assert('Symbol') do 5 | assert_equal :"a", :a 6 | assert_equal :"a#{1}", :a1 7 | assert_equal :'a', :a 8 | assert_equal :'a#{1}', :"a\#{1}" 9 | end 10 | 11 | assert('Symbol', '15.2.11') do 12 | assert_equal Class, Symbol.class 13 | end 14 | 15 | assert('Symbol#===', '15.2.11.3.1') do 16 | assert_true :abc === :abc 17 | assert_false :abc === :cba 18 | end 19 | 20 | assert('Symbol#to_s', '15.2.11.3.3') do 21 | assert_equal 'abc', :abc.to_s 22 | end 23 | 24 | assert('Symbol#to_sym', '15.2.11.3.4') do 25 | assert_equal :abc, :abc.to_sym 26 | end 27 | 28 | assert('Symbol#to_proc') do 29 | assert_equal 5, :abs.to_proc[-5] 30 | end 31 | -------------------------------------------------------------------------------- /mruby/test/t/true.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # TrueClass ISO Test 3 | 4 | assert('TrueClass', '15.2.5') do 5 | assert_equal Class, TrueClass.class 6 | end 7 | 8 | assert('TrueClass true', '15.2.5.1') do 9 | assert_true true 10 | assert_equal TrueClass, true.class 11 | assert_false TrueClass.method_defined? :new 12 | end 13 | 14 | assert('TrueClass#&', '15.2.5.3.1') do 15 | assert_true true.&(true) 16 | assert_false true.&(false) 17 | end 18 | 19 | assert('TrueClass#^', '15.2.5.3.2') do 20 | assert_false true.^(true) 21 | assert_true true.^(false) 22 | end 23 | 24 | assert('TrueClass#to_s', '15.2.5.3.3') do 25 | assert_equal 'true', true.to_s 26 | end 27 | 28 | assert('TrueClass#|', '15.2.5.3.4') do 29 | assert_true true.|(true) 30 | assert_true true.|(false) 31 | end 32 | -------------------------------------------------------------------------------- /mruby/test/t/typeerror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # TypeError ISO Test 3 | 4 | assert('TypeError', '15.2.29') do 5 | assert_equal Class, TypeError.class 6 | end 7 | -------------------------------------------------------------------------------- /mruby/test/t/unicode.rb: -------------------------------------------------------------------------------- 1 | # Test of the \u notation 2 | 3 | assert('bare \u notation test') do 4 | # Minimum and maximum one byte characters 5 | assert_equal("\x00", "\u0000") 6 | assert_equal("\x7F", "\u007F") 7 | 8 | # Minimum and maximum two byte characters 9 | assert_equal("\xC2\x80", "\u0080") 10 | assert_equal("\xDF\xBF", "\u07FF") 11 | 12 | # Minimum and maximum three byte characters 13 | assert_equal("\xE0\xA0\x80", "\u0800") 14 | assert_equal("\xEF\xBF\xBF", "\uFFFF") 15 | 16 | # Four byte characters require the \U notation 17 | end 18 | 19 | assert('braced \u notation test') do 20 | # Minimum and maximum one byte characters 21 | assert_equal("\x00", "\u{0000}") 22 | assert_equal("\x7F", "\u{007F}") 23 | 24 | # Minimum and maximum two byte characters 25 | assert_equal("\xC2\x80", "\u{0080}") 26 | assert_equal("\xDF\xBF", "\u{07FF}") 27 | 28 | # Minimum and maximum three byte characters 29 | assert_equal("\xE0\xA0\x80", "\u{0800}") 30 | assert_equal("\xEF\xBF\xBF", "\u{FFFF}") 31 | 32 | # Minimum and maximum four byte characters 33 | assert_equal("\xF0\x90\x80\x80", "\u{10000}") 34 | assert_equal("\xF4\x8F\xBF\xBF", "\u{10FFFF}") 35 | end 36 | 37 | assert('braced multiple \u notation test') do 38 | assert_equal("ABC", "\u{41 42 43}") 39 | end 40 | -------------------------------------------------------------------------------- /mruby/test/t/vformat.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/ngx_mruby/bed251036c0f273fb42fa9e84c00767b15983956/mruby/test/t/vformat.rb -------------------------------------------------------------------------------- /nginx_version: -------------------------------------------------------------------------------- 1 | NGINX_SRC_MAJOR=1 2 | NGINX_SRC_MINOR=27 3 | NGINX_SRC_PATCH=2 4 | NGINX_SRC_VER=nginx-${NGINX_SRC_MAJOR}.${NGINX_SRC_MINOR}.${NGINX_SRC_PATCH} 5 | -------------------------------------------------------------------------------- /src/http/ngx_http_mruby_async.h: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_http_mruby_async.h - ngx_mruby mruby module header 3 | // 4 | // See Copyright Notice in ngx_http_mruby_module.c 5 | */ 6 | 7 | #ifndef NGX_HTTP_MRUBY_ASYNC_H 8 | #define NGX_HTTP_MRUBY_ASYNC_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | mrb_value ngx_mrb_start_fiber(ngx_http_request_t *r, mrb_state *mrb, struct RProc *proc, mrb_value *result); 17 | mrb_value ngx_mrb_run_fiber(mrb_state *mrb, mrb_value *fiber, mrb_value *result); 18 | 19 | void ngx_mrb_async_class_init(mrb_state *mrb, struct RClass *class); 20 | 21 | #endif // NGX_HTTP_MRUBY_ASYNC_H 22 | -------------------------------------------------------------------------------- /src/http/ngx_http_mruby_connection.h: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_http_mruby_connection.h - ngx_mruby mruby module header 3 | // 4 | // See Copyright Notice in ngx_http_mruby_module.c 5 | */ 6 | 7 | #ifndef NGX_HTTP_MRUBY_CONNECTION_H 8 | #define NGX_HTTP_MRUBY_CONNECTION_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | void ngx_mrb_conn_class_init(mrb_state *mrb, struct RClass *class); 17 | 18 | #endif // NGX_HTTP_MRUBY_CONNECTION_H 19 | -------------------------------------------------------------------------------- /src/http/ngx_http_mruby_filter.h: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_http_mruby_filter.h - ngx_mruby mruby module header 3 | // 4 | // See Copyright Notice in ngx_http_mruby_module.c 5 | */ 6 | 7 | #ifndef NGX_HTTP_MRUBY_FILTER_H 8 | #define NGX_HTTP_MRUBY_FILTER_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | void ngx_mrb_filter_class_init(mrb_state *mrb, struct RClass *class); 17 | 18 | #endif // NGX_HTTP_MRUBY_FILTER_H 19 | -------------------------------------------------------------------------------- /src/http/ngx_http_mruby_init.h: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_http_mruby_init.h - ngx_mruby mruby init header 3 | // 4 | // See Copyright Notice in ngx_http_mruby_module.c 5 | */ 6 | 7 | #ifndef NGX_HTTP_MRUBY_INIT_H 8 | #define NGX_HTTP_MRUBY_INIT_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | ngx_int_t ngx_mrb_class_init(mrb_state *mrb); 17 | 18 | #endif // NGX_HTTP_MRUBY_INIT_H 19 | -------------------------------------------------------------------------------- /src/http/ngx_http_mruby_request.h: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_http_mruby_request.h - ngx_mruby mruby module header 3 | // 4 | // See Copyright Notice in ngx_http_mruby_module.c 5 | */ 6 | 7 | #ifndef NGX_HTTP_MRUBY_REQUEST_H 8 | #define NGX_HTTP_MRUBY_REQUEST_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | ngx_int_t ngx_mrb_push_request(ngx_http_request_t *r); 17 | ngx_http_request_t *ngx_mrb_get_request(void); 18 | mrb_value ngx_mrb_get_request_var(mrb_state *mrb, mrb_value self); 19 | 20 | void ngx_mrb_request_class_init(mrb_state *mrb, struct RClass *class); 21 | 22 | #endif // NGX_HTTP_MRUBY_REQUEST_H 23 | -------------------------------------------------------------------------------- /src/http/ngx_http_mruby_server.h: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_http_mruby_server.h - ngx_mruby mruby module header 3 | // 4 | // See Copyright Notice in ngx_http_mruby_module.c 5 | */ 6 | 7 | #ifndef NGX_HTTP_MRUBY_SERVER_H 8 | #define NGX_HTTP_MRUBY_SERVER_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | void ngx_mrb_server_class_init(mrb_state *mrb, struct RClass *class); 17 | 18 | #endif // NGX_HTTP_MRUBY_SERVER_H 19 | -------------------------------------------------------------------------------- /src/http/ngx_http_mruby_ssl.h: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_http_mruby_ssl.h - ngx_mruby mruby module header 3 | // 4 | // See Copyright Notice in ngx_http_mruby_module.c 5 | */ 6 | 7 | #ifndef NGX_HTTP_MRUBY_SSL_H 8 | #define NGX_HTTP_MRUBY_SSL_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #if (NGX_HTTP_SSL) 15 | 16 | #include 17 | 18 | void ngx_mrb_ssl_class_init(mrb_state *mrb, struct RClass *class); 19 | 20 | #endif // NGX_HTTP_SSL 21 | 22 | #endif // NGX_HTTP_MRUBY_SSL_H 23 | -------------------------------------------------------------------------------- /src/http/ngx_http_mruby_var.h: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_http_mruby_var.h - ngx_mruby mruby module header 3 | // 4 | // See Copyright Notice in ngx_http_mruby_var.c 5 | */ 6 | 7 | #ifndef NGX_HTTP_MRUBY_VAR_H 8 | #define NGX_HTTP_MRUBY_VAR_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | mrb_value ngx_mrb_var_set_vector(mrb_state *mrb, mrb_value self, char *k, int len, mrb_value o, ngx_http_request_t *r); 17 | 18 | void ngx_mrb_var_class_init(mrb_state *mrb, struct RClass *class); 19 | 20 | #endif // NGX_HTTP_MRUBY_VAR_H 21 | -------------------------------------------------------------------------------- /src/stream/ngx_stream_mruby_async.h: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_stream_mruby_async.h - ngx_mruby mruby module header 3 | // 4 | // See Copyright Notice in ngx_stream_mruby_module.c 5 | */ 6 | 7 | #ifndef NGX_STREAM_MRUBY_ASYNC_H 8 | #define NGX_STREAM_MRUBY_ASYNC_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | mrb_value ngx_stream_mrb_start_fiber(ngx_stream_session_t *s, mrb_state *mrb, struct RProc *proc, mrb_value *result); 17 | void ngx_stream_mrb_async_class_init(mrb_state *mrb, struct RClass *class); 18 | 19 | #endif // NGX_STREAM_MRUBY_ASYNC_H 20 | -------------------------------------------------------------------------------- /src/stream/ngx_stream_mruby_connection.h: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_stream_mruby_connection.h - ngx_mruby mruby module header 3 | // 4 | // See Copyright Notice in ngx_http_mruby_module.c 5 | */ 6 | 7 | #ifndef NGX_STREAM_MRUBY_CONNECTION_H 8 | #define NGX_STREAM_MRUBY_CONNECTION_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | void ngx_stream_mrb_conn_class_init(mrb_state *mrb, struct RClass *class); 17 | 18 | #endif // NGX_STREAM_MRUBY_CONNECTION_H 19 | -------------------------------------------------------------------------------- /src/stream/ngx_stream_mruby_core.h: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_stream_mruby_core.h - ngx_mruby mruby module header 3 | // 4 | // See Copyright Notice in ngx_http_mruby_module.c 5 | */ 6 | 7 | #ifndef NGX_STREAM_MRUBY_CORE_H 8 | #define NGX_STREAM_MRUBY_CORE_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | void ngx_stream_mrb_core_class_init(mrb_state *mrb, struct RClass *class); 17 | typedef void (*ngx_stream_mrb_cleanup_pt)(void *data); 18 | typedef struct ngx_stream_mruby_ctx_t { 19 | mrb_value *fiber_proc; 20 | mrb_value *async_handler_result; 21 | ngx_stream_mrb_cleanup_pt cleanup; 22 | ngx_event_t sleep; 23 | } ngx_stream_mruby_ctx_t; 24 | 25 | ngx_stream_mruby_ctx_t *ngx_stream_mrb_get_module_ctx(mrb_state *mrb, ngx_stream_session_t *s); 26 | 27 | extern ngx_module_t ngx_stream_mruby_module; 28 | 29 | #endif // NGX_STREAM_MRUBY_CORE_H 30 | -------------------------------------------------------------------------------- /src/stream/ngx_stream_mruby_init.c: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_stream_mruby_init.c - ngx_mruby mruby init functions 3 | // 4 | // See Copyright Notice in ngx_http_mruby_module.c 5 | */ 6 | 7 | #include "ngx_stream_mruby_init.h" 8 | 9 | #include "ngx_stream_mruby_core.h" 10 | #include "ngx_stream_mruby_connection.h" 11 | #include "ngx_stream_mruby_async.h" 12 | 13 | #include 14 | 15 | #define GC_ARENA_RESTORE mrb_gc_arena_restore(mrb, 0); 16 | 17 | ngx_int_t ngx_stream_mrb_class_init(mrb_state *mrb) 18 | { 19 | struct RClass *top; 20 | struct RClass *class; 21 | 22 | /* define Nginx::Stream class */ 23 | top = mrb_define_class(mrb, "Nginx", mrb->object_class); 24 | class = mrb_define_class_under(mrb, top, "Stream", mrb->object_class); 25 | 26 | ngx_stream_mrb_core_class_init(mrb, class); 27 | GC_ARENA_RESTORE; 28 | ngx_stream_mrb_conn_class_init(mrb, class); 29 | GC_ARENA_RESTORE; 30 | ngx_stream_mrb_async_class_init(mrb, class); 31 | GC_ARENA_RESTORE; 32 | 33 | return NGX_OK; 34 | } 35 | -------------------------------------------------------------------------------- /src/stream/ngx_stream_mruby_init.h: -------------------------------------------------------------------------------- 1 | /* 2 | // ngx_stream_mruby_init.h - ngx_mruby mruby init header 3 | // 4 | // See Copyright Notice in ngx_http_mruby_module.c 5 | */ 6 | 7 | #ifndef NGX_STREAM_MRUBY_INIT_H 8 | #define NGX_STREAM_MRUBY_INIT_H 9 | 10 | #include 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | ngx_int_t ngx_stream_mrb_class_init(mrb_state *mrb); 17 | 18 | #endif // NGX_STREAM_MRUBY_INIT_H 19 | -------------------------------------------------------------------------------- /test/conf/auto-ssl/dehydrated_out/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/ngx_mruby/bed251036c0f273fb42fa9e84c00767b15983956/test/conf/auto-ssl/dehydrated_out/.gitkeep -------------------------------------------------------------------------------- /test/html/add_handler.rb: -------------------------------------------------------------------------------- 1 | Nginx.rputs "add_handler" 2 | -------------------------------------------------------------------------------- /test/html/backtrace.rb: -------------------------------------------------------------------------------- 1 | class Foo 2 | def foo 3 | b = Bar.new 4 | b.bar 5 | end 6 | end 7 | 8 | class Bar 9 | def bar 10 | raise "Intentional Error for testing ngx_mrb_log_backtrace" 11 | end 12 | end 13 | 14 | Foo.new.foo 15 | -------------------------------------------------------------------------------- /test/html/exit_worker.rb: -------------------------------------------------------------------------------- 1 | p "[#{Process.pid}] exit worker!" 2 | -------------------------------------------------------------------------------- /test/html/filter_dynamic_arg.rb: -------------------------------------------------------------------------------- 1 | r = Nginx::Request.new 2 | f = Nginx::Filter.new 3 | args = r.var.args 4 | if args.nil? 5 | f.body = "output filter: static" 6 | else 7 | r.headers_out["X-New-Header"] = args.to_s 8 | f.body = "output filter: #{args}" 9 | end 10 | -------------------------------------------------------------------------------- /test/html/header_filter.rb: -------------------------------------------------------------------------------- 1 | Nginx::Request.new.headers_out["x-add-new-header"] = "new_header" 2 | -------------------------------------------------------------------------------- /test/html/hoge.rb: -------------------------------------------------------------------------------- 1 | "aaa" 2 | -------------------------------------------------------------------------------- /test/html/image/matsumotory.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/ngx_mruby/bed251036c0f273fb42fa9e84c00767b15983956/test/html/image/matsumotory.png -------------------------------------------------------------------------------- /test/html/init_worker.rb: -------------------------------------------------------------------------------- 1 | p "[#{Process.pid}] init worker!" 2 | -------------------------------------------------------------------------------- /test/html/issue-210.rb: -------------------------------------------------------------------------------- 1 | Nginx::Request.new.headers_out["fuga"] = "hoge" 2 | -------------------------------------------------------------------------------- /test/html/issue_172/index.html: -------------------------------------------------------------------------------- 1 | hello -------------------------------------------------------------------------------- /test/html/issue_172_2/index.html: -------------------------------------------------------------------------------- 1 | hello -------------------------------------------------------------------------------- /test/html/output_filter_builtin_header/index.html: -------------------------------------------------------------------------------- 1 | output_filter_builtin_header 2 | -------------------------------------------------------------------------------- /test/html/output_filter_header/index.html: -------------------------------------------------------------------------------- 1 | output_filter_header 2 | -------------------------------------------------------------------------------- /test/html/proxy.rb: -------------------------------------------------------------------------------- 1 | # location /proxy { 2 | # mruby_set $backend "/path/to/proxy.rb"; 3 | # proxy_pass http://$backend; 4 | # } 5 | 6 | backends = [ 7 | "test1", 8 | "test2", 9 | "test3", 10 | ] 11 | 12 | r = Redis.new "192.168.12.251", 6379 13 | r.get backends[rand(backends.length)] 14 | -------------------------------------------------------------------------------- /test/html/set.rb: -------------------------------------------------------------------------------- 1 | r = Nginx::Request.new 2 | 3 | r.var.fuga.to_i * 2 4 | -------------------------------------------------------------------------------- /test/html/set2.rb: -------------------------------------------------------------------------------- 1 | r = Nginx::Request.new 2 | 3 | Nginx.rputs "fuga => #{r.var.fuga} " 4 | Nginx.rputs "hoge => #{r.var.hoge} " 5 | 6 | r.var.set "hoge", r.var.hoge.to_i * 2 7 | Nginx.rputs "hoge => #{r.var.hoge}" 8 | -------------------------------------------------------------------------------- /test/html/set_ssl_cert_and_key.rb: -------------------------------------------------------------------------------- 1 | ssl = Nginx::SSL.new 2 | ssl.certificate = "__NGXDOCROOT__/#{ssl.servername}.crt" 3 | ssl.certificate_key = "__NGXDOCROOT__/#{ssl.servername}.key" 4 | -------------------------------------------------------------------------------- /test/html/stream_lb.rb: -------------------------------------------------------------------------------- 1 | c = Nginx::Stream::Connection.new "dynamic_server1" 2 | c.upstream_server = "127.0.0.1:58080" 3 | -------------------------------------------------------------------------------- /test/html/unified_hello.rb: -------------------------------------------------------------------------------- 1 | # Unified Ruby Code between Apache(mod_mruby) and nginx(ngx_mruby) 2 | # for Web server extensions. 3 | # 4 | # Apache httpd.conf by mod_mruby 5 | # 6 | # 7 | # mrubyHandlerMiddle "/path/to/unified_hello.rb" 8 | # 9 | # 10 | # nginx nginx.conf by ngx_mruby 11 | # 12 | # location /mruby { 13 | # mruby_content_handler "/path/to/unified_hello.rb"; 14 | # } 15 | # 16 | 17 | if server_name == "NGINX" 18 | Server = Nginx 19 | elsif server_name == "Apache" 20 | Server = Apache 21 | end 22 | 23 | Server::rputs "Hello #{Server::module_name} world!" 24 | #Server::rputs "Hello #{Server::module_name}/#{Server::module_version} world!" 25 | # mod_mruby => "Hello mod_mruby/0.9.3 world!" 26 | # ngx_mruby => "Hello ngx_mruby/0.0.1 world!" 27 | -------------------------------------------------------------------------------- /test/t/issue-268-test.rb: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | 3 | require 'socket' 4 | 5 | request_body = %({"hello": "ngx_mruby"}) 6 | headers = < /dev/null 9 | if [ $? -ne 0 ]; then 10 | echo "Missing remote repository ${REMOTE_REPO_NAME}" 11 | echo -n "Do you want to add (y/n)? " 12 | read answer 13 | if [ X$answer = "Xy" -o X$answer = "XY" ]; then 14 | git remote add ${REMOTE_REPO_NAME} ${REMOTE_REPO_URL} 15 | echo "Added ${REMOTE_REPO_URL} as ${REMOTE_REPO_NAME}." 16 | else 17 | echo "Aborted." 18 | exit 1 19 | fi 20 | fi 21 | if [ $# -eq 1 ]; then 22 | if [ $1 = "-h" -o $1 = "--help" ]; then 23 | echo "Usage: `basename $0` [ref]" 24 | echo " 'ref' can be a SHA-1 hash, tag or branch. The default ref is 'master'." 25 | exit 0 26 | else 27 | REF=$1 28 | fi 29 | fi 30 | 31 | git subtree pull --prefix=${SUBTREE_DIR} --squash ${REMOTE_REPO_NAME} ${REF} 32 | 33 | exit 0 34 | -------------------------------------------------------------------------------- /update-mruby-subtree: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | REMOTE_REPO_NAME=dep-mruby 4 | REMOTE_REPO_URL=https://github.com/mruby/mruby.git 5 | SUBTREE_DIR=mruby 6 | REF=master 7 | 8 | git remote | grep ${REMOTE_REPO_NAME} > /dev/null 9 | if [ $? -ne 0 ]; then 10 | echo "Missing remote repository ${REMOTE_REPO_NAME}" 11 | echo -n "Do you want to add (y/n)? " 12 | read answer 13 | if [ X$answer = "Xy" -o X$answer = "XY" ]; then 14 | git remote add ${REMOTE_REPO_NAME} ${REMOTE_REPO_URL} 15 | echo "Added ${REMOTE_REPO_URL} as ${REMOTE_REPO_NAME}." 16 | else 17 | echo "Aborted." 18 | exit 1 19 | fi 20 | fi 21 | if [ $# -eq 1 ]; then 22 | if [ $1 = "-h" -o $1 = "--help" ]; then 23 | echo "Usage: `basename $0` [ref]" 24 | echo " 'ref' can be a SHA-1 hash, tag or branch. The default ref is 'master'." 25 | exit 0 26 | else 27 | REF=$1 28 | fi 29 | fi 30 | 31 | git subtree pull --prefix=${SUBTREE_DIR} --squash ${REMOTE_REPO_NAME} ${REF} 32 | 33 | exit 0 34 | --------------------------------------------------------------------------------