├── .gitmodules ├── webif ├── .gitkeep ├── api │ └── .gitkeep ├── interface │ ├── .gitkeep │ ├── .gitignore │ ├── views │ │ └── sample_image.jpeg │ └── README.md └── README.md ├── mrbgems ├── mod_mruby_mrblib │ ├── test │ │ └── .gitkeep │ ├── mrbgem.rake │ └── mrblib │ │ └── mrb_apache.rb └── rack-based-api │ ├── test │ └── .gitkeep │ └── mrbgem.rake ├── test ├── htdocs │ ├── echo.rb │ ├── proxy_reply.rb │ ├── output_body_filter.rb │ ├── output_error_filter.rb │ ├── read_note.rb │ ├── write_note.rb │ ├── sleep.cgi │ ├── request_body.rb │ ├── proxy_request.rb │ ├── document_root.rb │ ├── authn_basic.rb │ ├── output_filter.rb │ └── header.rb └── docker │ └── Dockerfile ├── mruby ├── minirake ├── mrbgems │ ├── mruby-sleep │ │ ├── example │ │ │ └── sleep.rb │ │ ├── mrbgem.rake │ │ ├── README.md │ │ └── test │ │ │ └── sleep_test.rb │ ├── mruby-socket │ │ ├── test │ │ │ ├── tcpsocket.rb │ │ │ ├── udpsocket.rb │ │ │ ├── basicsocket.rb │ │ │ └── ipsocket.rb │ │ ├── src │ │ │ └── gen.rb │ │ └── mrbgem.rake │ ├── mruby-test │ │ └── README.md │ ├── mruby-fiber │ │ └── mrbgem.rake │ ├── mruby-exit │ │ ├── mrbgem.rake │ │ └── src │ │ │ └── mruby-exit.c │ ├── mruby-math │ │ └── mrbgem.rake │ ├── mruby-random │ │ └── mrbgem.rake │ ├── mruby-time │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── time.rb │ │ └── include │ │ │ └── mruby │ │ │ └── time.h │ ├── mruby-print │ │ ├── mrbgem.rake │ │ └── mrblib │ │ │ └── print.rb │ ├── mruby-rational │ │ └── mrbgem.rake │ ├── mruby-struct │ │ └── mrbgem.rake │ ├── mruby-proc-ext │ │ └── mrbgem.rake │ ├── mruby-sprintf │ │ ├── mrblib │ │ │ └── string.rb │ │ ├── mrbgem.rake │ │ └── src │ │ │ └── kernel.c │ ├── mruby-array-ext │ │ └── mrbgem.rake │ ├── mruby-class-ext │ │ └── mrbgem.rake │ ├── mruby-enum-ext │ │ └── mrbgem.rake │ ├── mruby-inline-struct │ │ └── mrbgem.rake │ ├── mruby-objectspace │ │ └── mrbgem.rake │ ├── mruby-range-ext │ │ └── mrbgem.rake │ ├── mruby-string-ext │ │ ├── mrbgem.rake │ │ └── test │ │ │ ├── range.rb │ │ │ └── numeric.rb │ ├── mruby-symbol-ext │ │ └── mrbgem.rake │ ├── mruby-compar-ext │ │ ├── mrbgem.rake │ │ └── mrblib │ │ │ └── compar.rb │ ├── mruby-numeric-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── numeric_ext.rb │ │ └── test │ │ │ └── numeric.rb │ ├── mruby-kernel-ext │ │ └── mrbgem.rake │ ├── mruby-metaprog │ │ └── mrbgem.rake │ ├── mruby-object-ext │ │ ├── mrbgem.rake │ │ ├── test │ │ │ └── nil.rb │ │ └── mrblib │ │ │ └── object.rb │ ├── mruby-toplevel-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── toplevel.rb │ │ └── test │ │ │ └── toplevel.rb │ ├── mruby-bin-strip │ │ └── mrbgem.rake │ ├── mruby-complex │ │ └── mrbgem.rake │ ├── mruby-enumerator │ │ └── mrbgem.rake │ ├── mruby-eval │ │ └── mrbgem.rake │ ├── mruby-hash-ext │ │ └── mrbgem.rake │ ├── mruby-enum-chain │ │ └── mrbgem.rake │ ├── mruby-io │ │ ├── mrblib │ │ │ ├── file_constants.rb │ │ │ └── kernel.rb │ │ ├── mrbgem.rake │ │ └── src │ │ │ └── mruby_io_gem.c │ ├── mruby-method │ │ ├── mrbgem.rake │ │ └── mrblib │ │ │ ├── kernel.rb │ │ │ └── method.rb │ ├── mruby-pack │ │ └── mrbgem.rake │ ├── mruby-bin-debugger │ │ ├── mrbgem.rake │ │ └── tools │ │ │ └── mrdb │ │ │ ├── apiprint.h │ │ │ ├── apilist.h │ │ │ ├── mrdberror.h │ │ │ └── mrdbconf.h │ ├── full-core.gembox │ ├── mruby-enum-lazy │ │ └── mrbgem.rake │ ├── mruby-error │ │ └── mrbgem.rake │ ├── mruby-bin-mruby │ │ └── mrbgem.rake │ ├── mruby-bin-mrbc │ │ └── mrbgem.rake │ ├── mruby-bin-config │ │ ├── mruby-config │ │ ├── mrbgem.rake │ │ └── mruby-config.bat │ └── mruby-bin-mirb │ │ └── bintest │ │ └── mirb.rb ├── src │ ├── opcode.h │ ├── error.h │ ├── compar.c │ ├── value_array.h │ ├── mruby_core.rake │ ├── enum.c │ ├── version.c │ └── crc.c ├── test │ ├── t │ │ ├── vformat.rb │ │ ├── regexperror.rb │ │ ├── typeerror.rb │ │ ├── indexerror.rb │ │ ├── rangeerror.rb │ │ ├── runtimeerror.rb │ │ ├── standarderror.rb │ │ ├── basicobject.rb │ │ ├── object.rb │ │ ├── argumenterror.rb │ │ ├── localjumperror.rb │ │ ├── nomethoderror.rb │ │ ├── nameerror.rb │ │ ├── true.rb │ │ ├── bs_literal.rb │ │ ├── false.rb │ │ ├── symbol.rb │ │ ├── ensure.rb │ │ ├── nil.rb │ │ └── gc.rb │ └── bintest.rb ├── doc │ └── mruby_logo_red_icon.png ├── oss-fuzz │ ├── config │ │ ├── mruby_proto_fuzzer.options │ │ └── mruby_fuzzer.options │ └── mruby_fuzzer.c ├── benchmark │ ├── bm_fib.rb │ ├── plot.gpl │ ├── build_config_cc.rb │ └── build_config_boxing.rb ├── examples │ ├── mrbgems │ │ ├── c_extension_example │ │ │ ├── test │ │ │ │ ├── example.rb │ │ │ │ └── example.c │ │ │ ├── README.md │ │ │ ├── src │ │ │ │ └── example.c │ │ │ └── mrbgem.rake │ │ ├── ruby_extension_example │ │ │ ├── test │ │ │ │ └── example.rb │ │ │ ├── README.md │ │ │ ├── mrblib │ │ │ │ └── example.rb │ │ │ └── mrbgem.rake │ │ └── c_and_ruby_extension_example │ │ │ ├── README.md │ │ │ ├── mrblib │ │ │ └── example.rb │ │ │ ├── test │ │ │ └── example.rb │ │ │ ├── src │ │ │ └── example.c │ │ │ └── mrbgem.rake │ └── targets │ │ ├── build_config_android_armeabi.rb │ │ ├── build_config_android_arm64-v8a.rb │ │ └── build_config_android_armeabi_v7a_neon_hard.rb ├── mrblib │ ├── symbol.rb │ ├── init_mrblib.c │ ├── 00class.rb │ ├── mrblib.rake │ └── kernel.rb ├── .travis.yml ├── LEGAL ├── TODO ├── Makefile ├── include │ └── mruby │ │ └── re.h ├── .yardopts ├── tasks │ ├── toolchains │ │ └── clang.rake │ └── doc.rake ├── NEWS ├── .gitignore ├── mruby-source.gemspec ├── .github │ └── workflows │ │ └── main.yml ├── lib │ └── mruby-core-ext.rb ├── travis_config.rb └── LICENSE ├── mruby_test ├── minirake ├── mrbgems │ ├── mruby-sleep │ │ ├── example │ │ │ └── sleep.rb │ │ ├── mrbgem.rake │ │ ├── README.md │ │ └── test │ │ │ └── sleep_test.rb │ ├── mruby-socket │ │ ├── test │ │ │ ├── tcpsocket.rb │ │ │ ├── udpsocket.rb │ │ │ ├── basicsocket.rb │ │ │ └── ipsocket.rb │ │ ├── src │ │ │ └── gen.rb │ │ └── mrbgem.rake │ ├── mruby-test │ │ └── README.md │ ├── mruby-fiber │ │ └── mrbgem.rake │ ├── mruby-exit │ │ ├── mrbgem.rake │ │ └── src │ │ │ └── mruby-exit.c │ ├── mruby-math │ │ └── mrbgem.rake │ ├── mruby-random │ │ └── mrbgem.rake │ ├── mruby-time │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── time.rb │ │ └── include │ │ │ └── mruby │ │ │ └── time.h │ ├── mruby-print │ │ ├── mrbgem.rake │ │ └── mrblib │ │ │ └── print.rb │ ├── mruby-rational │ │ └── mrbgem.rake │ ├── mruby-struct │ │ └── mrbgem.rake │ ├── mruby-proc-ext │ │ └── mrbgem.rake │ ├── mruby-sprintf │ │ ├── mrblib │ │ │ └── string.rb │ │ ├── mrbgem.rake │ │ └── src │ │ │ └── kernel.c │ ├── mruby-array-ext │ │ └── mrbgem.rake │ ├── mruby-class-ext │ │ └── mrbgem.rake │ ├── mruby-enum-ext │ │ └── mrbgem.rake │ ├── mruby-inline-struct │ │ └── mrbgem.rake │ ├── mruby-objectspace │ │ └── mrbgem.rake │ ├── mruby-range-ext │ │ └── mrbgem.rake │ ├── mruby-string-ext │ │ ├── mrbgem.rake │ │ └── test │ │ │ ├── range.rb │ │ │ └── numeric.rb │ ├── mruby-symbol-ext │ │ └── mrbgem.rake │ ├── mruby-compar-ext │ │ ├── mrbgem.rake │ │ └── mrblib │ │ │ └── compar.rb │ ├── mruby-numeric-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── numeric_ext.rb │ │ └── test │ │ │ └── numeric.rb │ ├── mruby-kernel-ext │ │ └── mrbgem.rake │ ├── mruby-metaprog │ │ └── mrbgem.rake │ ├── mruby-object-ext │ │ ├── mrbgem.rake │ │ ├── test │ │ │ └── nil.rb │ │ └── mrblib │ │ │ └── object.rb │ ├── mruby-toplevel-ext │ │ ├── mrbgem.rake │ │ ├── mrblib │ │ │ └── toplevel.rb │ │ └── test │ │ │ └── toplevel.rb │ ├── mruby-bin-strip │ │ └── mrbgem.rake │ ├── mruby-complex │ │ └── mrbgem.rake │ ├── mruby-enumerator │ │ └── mrbgem.rake │ ├── mruby-eval │ │ └── mrbgem.rake │ ├── mruby-hash-ext │ │ └── mrbgem.rake │ ├── mruby-enum-chain │ │ └── mrbgem.rake │ ├── mruby-io │ │ ├── mrblib │ │ │ ├── file_constants.rb │ │ │ └── kernel.rb │ │ ├── mrbgem.rake │ │ └── src │ │ │ └── mruby_io_gem.c │ ├── mruby-method │ │ ├── mrbgem.rake │ │ └── mrblib │ │ │ ├── kernel.rb │ │ │ └── method.rb │ ├── mruby-pack │ │ └── mrbgem.rake │ ├── mruby-bin-debugger │ │ ├── mrbgem.rake │ │ └── tools │ │ │ └── mrdb │ │ │ ├── apiprint.h │ │ │ ├── apilist.h │ │ │ ├── mrdberror.h │ │ │ └── mrdbconf.h │ ├── full-core.gembox │ ├── mruby-enum-lazy │ │ └── mrbgem.rake │ ├── mruby-error │ │ └── mrbgem.rake │ ├── mruby-bin-mruby │ │ └── mrbgem.rake │ ├── mruby-bin-mrbc │ │ └── mrbgem.rake │ ├── mruby-bin-config │ │ ├── mruby-config │ │ ├── mrbgem.rake │ │ └── mruby-config.bat │ └── mruby-bin-mirb │ │ └── bintest │ │ └── mirb.rb ├── src │ ├── opcode.h │ ├── error.h │ ├── compar.c │ ├── value_array.h │ ├── mruby_core.rake │ ├── enum.c │ ├── version.c │ └── crc.c ├── test │ ├── t │ │ ├── vformat.rb │ │ ├── regexperror.rb │ │ ├── typeerror.rb │ │ ├── indexerror.rb │ │ ├── rangeerror.rb │ │ ├── runtimeerror.rb │ │ ├── standarderror.rb │ │ ├── basicobject.rb │ │ ├── object.rb │ │ ├── argumenterror.rb │ │ ├── localjumperror.rb │ │ ├── nomethoderror.rb │ │ ├── nameerror.rb │ │ ├── true.rb │ │ ├── bs_literal.rb │ │ ├── false.rb │ │ ├── symbol.rb │ │ ├── ensure.rb │ │ ├── nil.rb │ │ └── gc.rb │ └── bintest.rb ├── oss-fuzz │ ├── config │ │ ├── mruby_proto_fuzzer.options │ │ └── mruby_fuzzer.options │ └── mruby_fuzzer.c ├── benchmark │ ├── bm_fib.rb │ ├── plot.gpl │ ├── build_config_cc.rb │ └── build_config_boxing.rb ├── doc │ └── mruby_logo_red_icon.png ├── examples │ ├── mrbgems │ │ ├── c_extension_example │ │ │ ├── test │ │ │ │ ├── example.rb │ │ │ │ └── example.c │ │ │ ├── README.md │ │ │ ├── src │ │ │ │ └── example.c │ │ │ └── mrbgem.rake │ │ ├── ruby_extension_example │ │ │ ├── test │ │ │ │ └── example.rb │ │ │ ├── README.md │ │ │ ├── mrblib │ │ │ │ └── example.rb │ │ │ └── mrbgem.rake │ │ └── c_and_ruby_extension_example │ │ │ ├── README.md │ │ │ ├── mrblib │ │ │ └── example.rb │ │ │ ├── test │ │ │ └── example.rb │ │ │ ├── src │ │ │ └── example.c │ │ │ └── mrbgem.rake │ └── targets │ │ ├── build_config_android_armeabi.rb │ │ ├── build_config_android_arm64-v8a.rb │ │ └── build_config_android_armeabi_v7a_neon_hard.rb ├── mrblib │ ├── symbol.rb │ ├── init_mrblib.c │ ├── 00class.rb │ ├── mrblib.rake │ └── kernel.rb ├── .travis.yml ├── LEGAL ├── TODO ├── Makefile ├── include │ └── mruby │ │ └── re.h ├── .yardopts ├── tasks │ └── toolchains │ │ └── clang.rake ├── NEWS ├── .gitignore ├── mruby-source.gemspec ├── .github │ └── workflows │ │ └── main.yml ├── lib │ └── mruby-core-ext.rb ├── travis_config.rb └── LICENSE ├── misc ├── logo │ ├── logo.png │ ├── favicon.png │ ├── logo_transparent.png │ ├── pinterest_board_photo.png │ ├── twitter_profile_image.png │ ├── youtube_profile_image.png │ ├── facebook_cover_photo_1.png │ ├── facebook_cover_photo_2.png │ ├── facebook_profile_image.png │ ├── instagram_profile_image.png │ ├── linkedin_banner_image_1.png │ ├── linkedin_banner_image_2.png │ ├── linkedin_profile_image.png │ ├── pinterest_profile_image.png │ ├── twitter_header_photo_1.png │ └── twitter_header_photo_2.png └── provision.sh ├── AUTHORS ├── TODO ├── httpd_version ├── example ├── notes.rb ├── rewrite │ ├── sample.conf │ ├── sample.rb │ ├── rewrite2.rb │ └── rewrite.rb ├── hello │ └── hello.rb ├── suexec │ ├── capset.rb │ └── suexec.rb ├── security │ ├── remove_global_variable.rb │ └── remove_class_from_topself_obj.rb ├── vhost │ └── vhost.rb ├── cgroup │ ├── cgroup_detach.rb │ └── cgroup_attach.rb ├── gv_remove │ └── remove.rb ├── filter │ └── ouput_filter │ │ ├── filter.rb │ │ └── filter2.rb ├── proxy │ ├── proxy.rb │ └── proxy_by_scboard.rb ├── RaspberryPi │ └── led.rb ├── auth │ ├── authn_basic_by_redis.rb │ └── authn_basic.rb ├── redis │ └── authn_basic_by_redis.rb ├── limit_control │ ├── file_limit_dec_by_redis.rb │ ├── file_limit_inc_by_redis.rb │ ├── traffic_rate_limit.rb │ └── worker_rate_limit.rb └── unified_with_ngx_mruby │ └── unified_hello.rb ├── images └── performance_20140301.png ├── apply-clang-format ├── src ├── ap_mrb_env.h ├── ap_mrb_server.h ├── ap_mrb_connection.h ├── ap_mrb_scoreboard.h ├── ap_mrb_authnprovider.h ├── ap_mrb_request.h ├── ap_mrb_filter.h ├── ap_mrb_init.h └── ap_mrb_core.h ├── .clang-format ├── Vagrantfile ├── LEGAL ├── wercker.yml ├── docker └── conf │ └── mruby.conf ├── .gitignore ├── lib ├── old │ └── redis │ │ └── redis.h └── hello │ └── hello.c ├── .travis.yml ├── Makefile.w32 ├── update-mruby-subtree └── MITL /.gitmodules: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /webif/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /webif/api/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /webif/interface/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mrbgems/mod_mruby_mrblib/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /mrbgems/rack-based-api/test/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /test/htdocs/echo.rb: -------------------------------------------------------------------------------- 1 | Apache.echo "echo" 2 | -------------------------------------------------------------------------------- /webif/interface/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | -------------------------------------------------------------------------------- /mruby/minirake: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby 2 | exec "rake", *ARGV 3 | -------------------------------------------------------------------------------- /mruby_test/minirake: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby 2 | exec "rake", *ARGV 3 | -------------------------------------------------------------------------------- /test/htdocs/proxy_reply.rb: -------------------------------------------------------------------------------- 1 | Apache.rputs "proxy reply success" 2 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-sleep/example/sleep.rb: -------------------------------------------------------------------------------- 1 | sleep(10) 2 | usleep(10000) 3 | 4 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-sleep/example/sleep.rb: -------------------------------------------------------------------------------- 1 | sleep(10) 2 | usleep(10000) 3 | 4 | -------------------------------------------------------------------------------- /misc/logo/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/logo.png -------------------------------------------------------------------------------- /mruby/src/opcode.h: -------------------------------------------------------------------------------- 1 | /* this header file is to be removed soon. */ 2 | #include 3 | -------------------------------------------------------------------------------- /misc/logo/favicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/favicon.png -------------------------------------------------------------------------------- /mruby/test/t/vformat.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/mruby/test/t/vformat.rb -------------------------------------------------------------------------------- /mruby_test/src/opcode.h: -------------------------------------------------------------------------------- 1 | /* this header file is to be removed soon. */ 2 | #include 3 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | Original Authors "mod_mruby developers" are: 2 | MATSUMOTO Ryosuke 3 | TSUZAKI Yoshiharu 4 | -------------------------------------------------------------------------------- /test/htdocs/output_body_filter.rb: -------------------------------------------------------------------------------- 1 | f = Apache::Filter.new 2 | data = f.body 3 | f.body = "body-filter" 4 | -------------------------------------------------------------------------------- /TODO: -------------------------------------------------------------------------------- 1 | Add input filter 2 | Add some test 3 | Windows support again 4 | Support getting thread id for mac 5 | 6 | -------------------------------------------------------------------------------- /httpd_version: -------------------------------------------------------------------------------- 1 | HTTPD_VERSION=httpd-2.4.43 2 | APR=apr-1.7.0 3 | APR_UTIL=apr-util-1.6.1 4 | HTTPD_CONFIG_OPT= 5 | -------------------------------------------------------------------------------- /mruby_test/test/t/vformat.rb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/mruby_test/test/t/vformat.rb -------------------------------------------------------------------------------- /example/notes.rb: -------------------------------------------------------------------------------- 1 | n = Apache::Notes.new() 2 | n["memo"] = "hello" 3 | Apache.rputs("memo = " + n["memo"] + "
") 4 | -------------------------------------------------------------------------------- /misc/logo/logo_transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/logo_transparent.png -------------------------------------------------------------------------------- /test/htdocs/output_error_filter.rb: -------------------------------------------------------------------------------- 1 | f = Apache::Filter.new 2 | 3 | f.error_create Apache::HTTP_SERVICE_UNAVAILABLE 4 | -------------------------------------------------------------------------------- /test/htdocs/read_note.rb: -------------------------------------------------------------------------------- 1 | note = Apache::Notes.new 2 | 3 | Apache.rputs note[Apache::Connection.new.remote_ip] 4 | -------------------------------------------------------------------------------- /images/performance_20140301.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/images/performance_20140301.png -------------------------------------------------------------------------------- /mruby/doc/mruby_logo_red_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/mruby/doc/mruby_logo_red_icon.png -------------------------------------------------------------------------------- /mruby/oss-fuzz/config/mruby_proto_fuzzer.options: -------------------------------------------------------------------------------- 1 | [libfuzzer] 2 | close_fd_mask = 3 3 | dict = mruby.dict 4 | fork = 1 5 | -------------------------------------------------------------------------------- /apply-clang-format: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | for f in `ls src/*.{c,h}` 6 | do 7 | clang-format -i $f 8 | done 9 | -------------------------------------------------------------------------------- /example/rewrite/sample.conf: -------------------------------------------------------------------------------- 1 | LoadModule mruby_module modules/mod_mruby.so 2 | mrubyTranslateNameMiddle /path/to/sample.rb 3 | -------------------------------------------------------------------------------- /misc/logo/pinterest_board_photo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/pinterest_board_photo.png -------------------------------------------------------------------------------- /misc/logo/twitter_profile_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/twitter_profile_image.png -------------------------------------------------------------------------------- /misc/logo/youtube_profile_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/youtube_profile_image.png -------------------------------------------------------------------------------- /mruby/benchmark/bm_fib.rb: -------------------------------------------------------------------------------- 1 | 2 | def fib n 3 | return n if n < 2 4 | fib(n-2) + fib(n-1) 5 | end 6 | 7 | puts fib(37) 8 | -------------------------------------------------------------------------------- /mruby/test/t/regexperror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # RegexpError ISO Test 3 | 4 | # TODO broken ATM assert('RegexpError', '15.2.27') do 5 | -------------------------------------------------------------------------------- /mruby_test/oss-fuzz/config/mruby_proto_fuzzer.options: -------------------------------------------------------------------------------- 1 | [libfuzzer] 2 | close_fd_mask = 3 3 | dict = mruby.dict 4 | fork = 1 5 | -------------------------------------------------------------------------------- /misc/logo/facebook_cover_photo_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/facebook_cover_photo_1.png -------------------------------------------------------------------------------- /misc/logo/facebook_cover_photo_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/facebook_cover_photo_2.png -------------------------------------------------------------------------------- /misc/logo/facebook_profile_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/facebook_profile_image.png -------------------------------------------------------------------------------- /misc/logo/instagram_profile_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/instagram_profile_image.png -------------------------------------------------------------------------------- /misc/logo/linkedin_banner_image_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/linkedin_banner_image_1.png -------------------------------------------------------------------------------- /misc/logo/linkedin_banner_image_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/linkedin_banner_image_2.png -------------------------------------------------------------------------------- /misc/logo/linkedin_profile_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/linkedin_profile_image.png -------------------------------------------------------------------------------- /misc/logo/pinterest_profile_image.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/pinterest_profile_image.png -------------------------------------------------------------------------------- /misc/logo/twitter_header_photo_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/twitter_header_photo_1.png -------------------------------------------------------------------------------- /misc/logo/twitter_header_photo_2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/misc/logo/twitter_header_photo_2.png -------------------------------------------------------------------------------- /mruby_test/benchmark/bm_fib.rb: -------------------------------------------------------------------------------- 1 | 2 | def fib n 3 | return n if n < 2 4 | fib(n-2) + fib(n-1) 5 | end 6 | 7 | puts fib(37) 8 | -------------------------------------------------------------------------------- /mruby_test/doc/mruby_logo_red_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/mruby_test/doc/mruby_logo_red_icon.png -------------------------------------------------------------------------------- /mruby_test/test/t/regexperror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # RegexpError ISO Test 3 | 4 | # TODO broken ATM assert('RegexpError', '15.2.27') do 5 | -------------------------------------------------------------------------------- /example/hello/hello.rb: -------------------------------------------------------------------------------- 1 | #Apache.rputs("hello mod_mruby world!") 2 | h = Apache::Hello.new 3 | 4 | Apache.rputs(h.hello("matsumoto")) 5 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /webif/interface/views/sample_image.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/matsumotory/mod_mruby/HEAD/webif/interface/views/sample_image.jpeg -------------------------------------------------------------------------------- /example/rewrite/sample.rb: -------------------------------------------------------------------------------- 1 | r = Apache::Request.new 2 | 3 | r.filename = "/var/www/html/redirect.html" 4 | 5 | Apache::return Apache::OK 6 | -------------------------------------------------------------------------------- /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/src/error.h: -------------------------------------------------------------------------------- 1 | /* this header file is to be removed soon. 2 | added for compatibility purpose (1.0.0) */ 3 | #include 4 | -------------------------------------------------------------------------------- /mruby_test/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 | -------------------------------------------------------------------------------- /test/htdocs/write_note.rb: -------------------------------------------------------------------------------- 1 | note = Apache::Notes.new 2 | 3 | target_ip = Apache::Connection.new.remote_ip 4 | 5 | note[target_ip] = "allow" 6 | -------------------------------------------------------------------------------- /mruby_test/examples/mrbgems/c_extension_example/test/example.rb: -------------------------------------------------------------------------------- 1 | assert('C Extension Example') do 2 | CExtension.respond_to? :c_method 3 | end 4 | -------------------------------------------------------------------------------- /mruby_test/src/error.h: -------------------------------------------------------------------------------- 1 | /* this header file is to be removed soon. 2 | added for compatibility purpose (1.0.0) */ 3 | #include 4 | -------------------------------------------------------------------------------- /test/htdocs/sleep.cgi: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | echo -ne "Content-Type: text/html; charset=UTF-8\r\n\r\n" 4 | 5 | sleep 5 6 | 7 | echo "sleep done" 8 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/ap_mrb_env.h: -------------------------------------------------------------------------------- 1 | #ifndef AP_MRB_ENV_H 2 | #define AP_MRB_ENV_H 3 | 4 | #include "ap_mrb_request.h" 5 | #include "mruby/string.h" 6 | 7 | #endif 8 | -------------------------------------------------------------------------------- /example/suexec/capset.rb: -------------------------------------------------------------------------------- 1 | # 2 | # use mruby-process, mruby-random, mruby-capability 3 | # 4 | 5 | c = Capability.new 6 | Apache.errlogger 4, "prepare cap" 7 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_extension_example/README.md: -------------------------------------------------------------------------------- 1 | C Extension Example 2 | ========= 3 | 4 | This is an example gem which implements a C extension. 5 | -------------------------------------------------------------------------------- /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/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/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/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 | -------------------------------------------------------------------------------- /example/security/remove_global_variable.rb: -------------------------------------------------------------------------------- 1 | $hoge = 1 2 | 3 | Apache::rputs global_variables.to_s 4 | Apache::rputs Apache::remove_global_variable(:$hoge).to_s 5 | -------------------------------------------------------------------------------- /mruby/mrblib/symbol.rb: -------------------------------------------------------------------------------- 1 | class Symbol 2 | def to_proc 3 | ->(obj,*args,&block) do 4 | obj.__send__(self, *args, &block) 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /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/examples/mrbgems/c_extension_example/README.md: -------------------------------------------------------------------------------- 1 | C Extension Example 2 | ========= 3 | 4 | This is an example gem which implements a C extension. 5 | -------------------------------------------------------------------------------- /mruby_test/examples/mrbgems/ruby_extension_example/test/example.rb: -------------------------------------------------------------------------------- 1 | assert('Ruby Extension Example') do 2 | RubyExtension.respond_to? :ruby_method 3 | end 4 | -------------------------------------------------------------------------------- /mruby_test/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/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/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/mrblib/symbol.rb: -------------------------------------------------------------------------------- 1 | class Symbol 2 | def to_proc 3 | ->(obj,*args,&block) do 4 | obj.__send__(self, *args, &block) 5 | end 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /mruby_test/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/examples/mrbgems/ruby_extension_example/README.md: -------------------------------------------------------------------------------- 1 | Pure Ruby Extension Example 2 | ========= 3 | 4 | This is an example gem which implements a pure Ruby extension. 5 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/ruby_extension_example/mrblib/example.rb: -------------------------------------------------------------------------------- 1 | class RubyExtension 2 | def RubyExtension.ruby_method 3 | puts "A Ruby Extension" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /mruby_test/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/examples/mrbgems/ruby_extension_example/README.md: -------------------------------------------------------------------------------- 1 | Pure Ruby Extension Example 2 | ========= 3 | 4 | This is an example gem which implements a pure Ruby extension. 5 | -------------------------------------------------------------------------------- /mruby_test/examples/mrbgems/ruby_extension_example/mrblib/example.rb: -------------------------------------------------------------------------------- 1 | class RubyExtension 2 | def RubyExtension.ruby_method 3 | puts "A Ruby Extension" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /example/vhost/vhost.rb: -------------------------------------------------------------------------------- 1 | r = Apache::Request.new() 2 | s = Apache::Server.new() 3 | 4 | r.filename = s.docroot + "/" + r.hostname + "/" + r.uri 5 | 6 | Apache::return(Apache::OK) 7 | -------------------------------------------------------------------------------- /mrbgems/mod_mruby_mrblib/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-mod-mruby-ext') do |spec| 2 | spec.license = 'MIT' 3 | spec.authors = 'MATSUMOTO Ryosuke' 4 | end 5 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_and_ruby_extension_example/README.md: -------------------------------------------------------------------------------- 1 | C and Ruby Extension Example 2 | ========= 3 | 4 | This is an example gem which implements a C and Ruby extension. 5 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb: -------------------------------------------------------------------------------- 1 | module CRubyExtension 2 | def CRubyExtension.ruby_method 3 | puts "A Ruby Extension" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /.clang-format: -------------------------------------------------------------------------------- 1 | # requires clang-format >= 3.6 2 | BasedOnStyle: "LLVM" 3 | IndentWidth: 2 4 | ColumnLimit: 120 5 | BreakBeforeBraces: Linux 6 | AllowShortFunctionsOnASingleLine: None 7 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | Vagrant.configure("2") do |config| 2 | config.vm.box = "bento/ubuntu-16.04" 3 | config.vm.provision "shell", :path => "misc/provision.sh", :privileged => false 4 | end 5 | -------------------------------------------------------------------------------- /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-test/README.md: -------------------------------------------------------------------------------- 1 | Running Tests 2 | ============= 3 | 4 | To run the tests, execute the following from the project's root directory. 5 | 6 | $ make test 7 | 8 | -------------------------------------------------------------------------------- /mruby_test/examples/mrbgems/c_and_ruby_extension_example/README.md: -------------------------------------------------------------------------------- 1 | C and Ruby Extension Example 2 | ========= 3 | 4 | This is an example gem which implements a C and Ruby extension. 5 | -------------------------------------------------------------------------------- /mruby_test/examples/mrbgems/c_and_ruby_extension_example/mrblib/example.rb: -------------------------------------------------------------------------------- 1 | module CRubyExtension 2 | def CRubyExtension.ruby_method 3 | puts "A Ruby Extension" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /test/htdocs/request_body.rb: -------------------------------------------------------------------------------- 1 | r = Apache::Request.new 2 | 3 | if r.method_number == Apache::M_POST 4 | Apache.rputs r.body 5 | else 6 | Apache.rputs "request body not found" 7 | end 8 | -------------------------------------------------------------------------------- /mruby/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | jobs: 4 | - os: linux 5 | - os: osx 6 | 7 | env: 8 | - MRUBY_CONFIG=travis_config.rb 9 | 10 | script: 11 | - rake -m && rake test 12 | -------------------------------------------------------------------------------- /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_test/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_test/mrbgems/mruby-test/README.md: -------------------------------------------------------------------------------- 1 | Running Tests 2 | ============= 3 | 4 | To run the tests, execute the following from the project's root directory. 5 | 6 | $ make test 7 | 8 | -------------------------------------------------------------------------------- /mruby_test/.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | 3 | jobs: 4 | - os: linux 5 | - os: osx 6 | 7 | env: 8 | - MRUBY_CONFIG=travis_config.rb 9 | 10 | script: 11 | - rake -m && rake test 12 | -------------------------------------------------------------------------------- /mruby_test/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 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /mrbgems/rack-based-api/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-rack-based-api') do |spec| 2 | spec.license = 'MIT' 3 | spec.authors = 'MATSUMOTO Ryosuke, Kentaro Kuribayashi' 4 | end 5 | -------------------------------------------------------------------------------- /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/benchmark/plot.gpl: -------------------------------------------------------------------------------- 1 | set yrange [0:] 2 | set terminal pngcairo font 'Sans, 8' lw 1 size 1400,1024 3 | set xtics rotate by -45 4 | set style histogram errorbars gap 2 lw 1 5 | set style fill solid border -1 6 | -------------------------------------------------------------------------------- /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-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-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-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_test/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 | -------------------------------------------------------------------------------- /example/cgroup/cgroup_detach.rb: -------------------------------------------------------------------------------- 1 | r = Apache::Request.new 2 | 3 | if r.filename == "/var/www/html/while.cgi" 4 | c = Cgroup::CPU.new("apache/mod_mruby_group") 5 | if c.exist? 6 | c.delete 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /example/gv_remove/remove.rb: -------------------------------------------------------------------------------- 1 | # mrubyFixupsMiddle "/usr/local/apache/hooks/test.rb" 2 | $hoge = 1 3 | Apache::rputs global_variables.to_s 4 | Apache::rputs "hoge" 5 | Apache::rputs Apache::global_remove(:$hoge).to_s 6 | -------------------------------------------------------------------------------- /mruby/LEGAL: -------------------------------------------------------------------------------- 1 | LEGAL NOTICE INFORMATION 2 | ------------------------ 3 | 4 | All the files in this distribution are covered under the MIT license 5 | (see the file LICENSE) except some files mentioned below: 6 | 7 | -------------------------------------------------------------------------------- /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-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 | end 6 | -------------------------------------------------------------------------------- /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_test/benchmark/plot.gpl: -------------------------------------------------------------------------------- 1 | set yrange [0:] 2 | set terminal pngcairo font 'Sans, 8' lw 1 size 1400,1024 3 | set xtics rotate by -45 4 | set style histogram errorbars gap 2 lw 1 5 | set style fill solid border -1 6 | -------------------------------------------------------------------------------- /mruby_test/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_test/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_test/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_test/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-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-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.version = '0.0.1' 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_test/LEGAL: -------------------------------------------------------------------------------- 1 | LEGAL NOTICE INFORMATION 2 | ------------------------ 3 | 4 | All the files in this distribution are covered under the MIT license 5 | (see the file LICENSE) except some files mentioned below: 6 | 7 | -------------------------------------------------------------------------------- /mruby_test/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_test/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 | end 6 | -------------------------------------------------------------------------------- /mruby_test/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/TODO: -------------------------------------------------------------------------------- 1 | Things to do (Things that are not done yet) 2 | 3 | * special variables ($1,$2..) 4 | * super in aliased methods 5 | 6 | Things to improve (Done but things to fix) 7 | 8 | * Make additions as they are noticed. 9 | -------------------------------------------------------------------------------- /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-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-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-inline-struct/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-inline-struct') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'inline structure' 5 | end 6 | -------------------------------------------------------------------------------- /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-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-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-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_test/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_test/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.version = '0.0.1' 5 | end 6 | -------------------------------------------------------------------------------- /mruby_test/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-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 = 'Enumerable module extension' 5 | end 6 | -------------------------------------------------------------------------------- /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-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_test/TODO: -------------------------------------------------------------------------------- 1 | Things to do (Things that are not done yet) 2 | 3 | * special variables ($1,$2..) 4 | * super in aliased methods 5 | 6 | Things to improve (Done but things to fix) 7 | 8 | * Make additions as they are noticed. 9 | -------------------------------------------------------------------------------- /mruby_test/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_test/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_test/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_test/mrbgems/mruby-inline-struct/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-inline-struct') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'inline structure' 5 | end 6 | -------------------------------------------------------------------------------- /mruby_test/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_test/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_test/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_test/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-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-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_test/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 = 'Enumerable module extension' 5 | end 6 | -------------------------------------------------------------------------------- /mruby_test/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_test/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/mrblib/init_mrblib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern const uint8_t mrblib_irep[]; 5 | 6 | void 7 | mrb_init_mrblib(mrb_state *mrb) 8 | { 9 | mrb_load_irep(mrb, mrblib_irep); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /mruby_test/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_test/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 | -------------------------------------------------------------------------------- /test/htdocs/proxy_request.rb: -------------------------------------------------------------------------------- 1 | backend = "http://127.0.0.1:8081" 2 | uri = "/proxy-reply" 3 | r = Apache::Request.new 4 | 5 | r.handler = "proxy-server" 6 | r.proxyreq = Apache::PROXYREQ_REVERSE 7 | r.filename = "proxy:" + backend + uri 8 | -------------------------------------------------------------------------------- /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_test/mrblib/init_mrblib.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | extern const uint8_t mrblib_irep[]; 5 | 6 | void 7 | mrb_init_mrblib(mrb_state *mrb) 8 | { 9 | mrb_load_irep(mrb, mrblib_irep); 10 | } 11 | 12 | -------------------------------------------------------------------------------- /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/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 | 12 | -------------------------------------------------------------------------------- /mruby_test/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_test/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_test/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 | 12 | -------------------------------------------------------------------------------- /webif/interface/README.md: -------------------------------------------------------------------------------- 1 | # Install 2 | ## install npm 3 | npm install express socket.io ejs routes http 4 | 5 | ## modify host setting 6 | vi app.js 7 | 8 | 9 | # Start 10 | node app.js 11 | 12 | - access http://127.0.0.1:3000/ 13 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb: -------------------------------------------------------------------------------- 1 | 2 | def self.include (*modules) 3 | self.class.include(*modules) 4 | end 5 | 6 | def self.private(*methods) 7 | end 8 | def self.protected(*methods) 9 | end 10 | def self.public(*methods) 11 | end 12 | -------------------------------------------------------------------------------- /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 | 12 | -------------------------------------------------------------------------------- /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_test/mrbgems/mruby-toplevel-ext/mrblib/toplevel.rb: -------------------------------------------------------------------------------- 1 | 2 | def self.include (*modules) 3 | self.class.include(*modules) 4 | end 5 | 6 | def self.private(*methods) 7 | end 8 | def self.protected(*methods) 9 | end 10 | def self.public(*methods) 11 | end 12 | -------------------------------------------------------------------------------- /mruby_test/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 | 12 | -------------------------------------------------------------------------------- /example/cgroup/cgroup_attach.rb: -------------------------------------------------------------------------------- 1 | r = Apache::Request.new 2 | 3 | if r.filename == "/var/www/html/while.cgi" 4 | c = Cgroup::CPU.new("apache/mod_mruby_group") 5 | unless c.exist? 6 | c.create 7 | end 8 | c.cfs_quota_us = 10000 9 | c.attach 10 | end 11 | -------------------------------------------------------------------------------- /mruby/Makefile: -------------------------------------------------------------------------------- 1 | # mruby is using Rake (http://rake.rubyforge.org) 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 | -------------------------------------------------------------------------------- /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.bins = %w(mruby-strip) 6 | end 7 | -------------------------------------------------------------------------------- /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 | 6 | spec.add_dependency 'mruby-math', core: 'mruby-math' 7 | end 8 | -------------------------------------------------------------------------------- /mruby_test/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/src/compar.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** compar.c - Comparable module 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #include 8 | 9 | void 10 | mrb_init_comparable(mrb_state *mrb) 11 | { 12 | mrb_define_module(mrb, "Comparable"); /* 15.3.3 */ 13 | } 14 | -------------------------------------------------------------------------------- /mruby_test/Makefile: -------------------------------------------------------------------------------- 1 | # mruby is using Rake (http://rake.rubyforge.org) 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 | -------------------------------------------------------------------------------- /mruby_test/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.bins = %w(mruby-strip) 6 | end 7 | -------------------------------------------------------------------------------- /mruby_test/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 | 6 | spec.add_dependency 'mruby-math', core: 'mruby-math' 7 | end 8 | -------------------------------------------------------------------------------- /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_test/src/compar.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** compar.c - Comparable module 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #include 8 | 9 | void 10 | mrb_init_comparable(mrb_state *mrb) 11 | { 12 | mrb_define_module(mrb, "Comparable"); /* 15.3.3 */ 13 | } 14 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-eval/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-eval') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'standard Kernel#eval method' 5 | 6 | add_dependency 'mruby-compiler', :core => 'mruby-compiler' 7 | end 8 | -------------------------------------------------------------------------------- /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_test/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 | -------------------------------------------------------------------------------- /test/htdocs/document_root.rb: -------------------------------------------------------------------------------- 1 | r = Apache::Request.new 2 | 3 | orig = r.document_root 4 | r.document_root = "/tmp" 5 | 6 | if r.document_root == "/tmp" 7 | r.document_root = orig 8 | Apache.rputs "OK" 9 | else 10 | r.document_root = orig 11 | Apache.rputs "NG" 12 | end 13 | -------------------------------------------------------------------------------- /example/security/remove_class_from_topself_obj.rb: -------------------------------------------------------------------------------- 1 | class Hoge 2 | def self.fuga 3 | Apache::rputs "hello" 4 | end 5 | end 6 | 7 | Hoge::fuga 8 | Apache::rputs self.class.constants.to_s 9 | 10 | self.class.remove_const :Hoge 11 | Apache::rputs self.class.constants.to_s 12 | 13 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-eval/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-eval') do |spec| 2 | spec.license = 'MIT' 3 | spec.author = 'mruby developers' 4 | spec.summary = 'standard Kernel#eval method' 5 | 6 | add_dependency 'mruby-compiler', :core => 'mruby-compiler' 7 | end 8 | -------------------------------------------------------------------------------- /mruby_test/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-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-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-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/kernel.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | def singleton_method(name) 3 | m = method(name) 4 | sc = (class < 'mruby-enumerator') 6 | end 7 | -------------------------------------------------------------------------------- /mruby_test/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_test/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 | -------------------------------------------------------------------------------- /test/htdocs/authn_basic.rb: -------------------------------------------------------------------------------- 1 | user_list = { 2 | "user1" => "passwd", 3 | } 4 | 5 | anp = Apache::AuthnProvider.new 6 | 7 | if user_list[anp.user] == anp.password 8 | Apache.return Apache::AuthnProvider::AUTH_GRANTED 9 | else 10 | Apache.return Apache::AuthnProvider::AUTH_DENIED 11 | end 12 | -------------------------------------------------------------------------------- /mruby/benchmark/build_config_cc.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | toolchain :gcc 3 | end 4 | 5 | MRuby::Build.new('gcc') do |conf| 6 | toolchain :gcc 7 | conf.gembox 'default' 8 | end 9 | 10 | MRuby::Build.new('clang') do |conf| 11 | toolchain :clang 12 | conf.gembox 'default' 13 | end 14 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-method/mrblib/kernel.rb: -------------------------------------------------------------------------------- 1 | module Kernel 2 | def singleton_method(name) 3 | m = method(name) 4 | sc = (class < 5 | #include "apr_strings.h" 6 | #include "http_request.h" 7 | #include "http_core.h" 8 | #include "mruby.h" 9 | #include "mruby/data.h" 10 | #include "mruby/variable.h" 11 | #include "ap_mrb_request.h" 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /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 | 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/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_test/.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 | AUTHORS 15 | LICENSE 16 | CONTRIBUTING.md 17 | doc/guides/*.md 18 | -------------------------------------------------------------------------------- /mruby_test/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 | 6 | spec.add_dependency('mruby-eval', :core => 'mruby-eval') 7 | 8 | spec.bins = %w(mrdb) 9 | end 10 | -------------------------------------------------------------------------------- /mruby_test/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 | -------------------------------------------------------------------------------- /src/ap_mrb_connection.h: -------------------------------------------------------------------------------- 1 | #ifndef AP_MRB_CONNECTION_H 2 | #define AP_MRB_CONNECTION_H 3 | 4 | #include 5 | #include "apr_strings.h" 6 | #include "http_request.h" 7 | #include "http_core.h" 8 | #include "mruby.h" 9 | #include "mruby/data.h" 10 | #include "mruby/variable.h" 11 | #include "ap_mrb_request.h" 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /src/ap_mrb_scoreboard.h: -------------------------------------------------------------------------------- 1 | #ifndef AP_MRB_SCOREBOARD_H 2 | #define AP_MRB_SCOREBOARD_H 3 | 4 | #include 5 | #include "apr_strings.h" 6 | #include "http_request.h" 7 | #include "http_core.h" 8 | #include "mruby.h" 9 | #include "mruby/data.h" 10 | #include "mruby/variable.h" 11 | #include "ap_mrb_request.h" 12 | 13 | #endif 14 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb: -------------------------------------------------------------------------------- 1 | class Numeric 2 | def zero? 3 | self == 0 4 | end 5 | 6 | def nonzero? 7 | if self == 0 8 | nil 9 | else 10 | self 11 | end 12 | end 13 | 14 | def positive? 15 | self > 0 16 | end 17 | 18 | def negative? 19 | self < 0 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /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/mrbgems/full-core.gembox: -------------------------------------------------------------------------------- 1 | MRuby::GemBox.new do |conf| 2 | conf.gem :core => "mruby-sprintf" 3 | conf.gem :core => "mruby-print" 4 | 5 | Dir.glob("#{root}/mrbgems/mruby-*/mrbgem.rake") do |x| 6 | g = File.basename File.dirname x 7 | conf.gem :core => g unless g =~ /^mruby-(print|sprintf|bin-debugger|test)$/ 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-numeric-ext/mrblib/numeric_ext.rb: -------------------------------------------------------------------------------- 1 | class Numeric 2 | def zero? 3 | self == 0 4 | end 5 | 6 | def nonzero? 7 | if self == 0 8 | nil 9 | else 10 | self 11 | end 12 | end 13 | 14 | def positive? 15 | self > 0 16 | end 17 | 18 | def negative? 19 | self < 0 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /mruby_test/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_test/mrbgems/full-core.gembox: -------------------------------------------------------------------------------- 1 | MRuby::GemBox.new do |conf| 2 | conf.gem :core => "mruby-sprintf" 3 | conf.gem :core => "mruby-print" 4 | 5 | Dir.glob("#{root}/mrbgems/mruby-*/mrbgem.rake") do |x| 6 | g = File.basename File.dirname x 7 | conf.gem :core => g unless g =~ /^mruby-(print|sprintf|bin-debugger|test)$/ 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /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_test/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-method/mrblib/method.rb: -------------------------------------------------------------------------------- 1 | class Method 2 | def to_proc 3 | m = self 4 | lambda { |*args, &b| 5 | m.call(*args, &b) 6 | } 7 | end 8 | 9 | def <<(other) 10 | ->(*args, &block) { call(other.call(*args, &block)) } 11 | end 12 | 13 | def >>(other) 14 | ->(*args, &block) { other.call(call(*args, &block)) } 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /mruby/test/t/argumenterror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # ArgumentError ISO Test 3 | 4 | assert('ArgumentError', '15.2.24') do 5 | e2 = nil 6 | a = [] 7 | begin 8 | # this will cause an exception due to the wrong arguments 9 | a[] 10 | rescue => e1 11 | e2 = e1 12 | end 13 | 14 | assert_equal(Class, ArgumentError.class) 15 | assert_equal(ArgumentError, e2.class) 16 | end 17 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-method/mrblib/method.rb: -------------------------------------------------------------------------------- 1 | class Method 2 | def to_proc 3 | m = self 4 | lambda { |*args, &b| 5 | m.call(*args, &b) 6 | } 7 | end 8 | 9 | def <<(other) 10 | ->(*args, &block) { call(other.call(*args, &block)) } 11 | end 12 | 13 | def >>(other) 14 | ->(*args, &block) { other.call(call(*args, &block)) } 15 | end 16 | end 17 | -------------------------------------------------------------------------------- /mruby_test/test/t/argumenterror.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # ArgumentError ISO Test 3 | 4 | assert('ArgumentError', '15.2.24') do 5 | e2 = nil 6 | a = [] 7 | begin 8 | # this will cause an exception due to the wrong arguments 9 | a[] 10 | rescue => e1 11 | e2 = e1 12 | end 13 | 14 | assert_equal(Class, ArgumentError.class) 15 | assert_equal(ArgumentError, e2.class) 16 | end 17 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /example/filter/ouput_filter/filter.rb: -------------------------------------------------------------------------------- 1 | # httpd.conf 設定 2 | # 3 | # SetOutputFilter mruby 4 | # mrubyOutputFilter /tmp/filter.rb 5 | # 6 | 7 | f = Apache::Filter.new 8 | 9 | # brigade のデータ取得 10 | data = f.flatten 11 | 12 | # データ取得したので元のbrigadeは綺麗に 13 | f.cleanup 14 | 15 | # 綺麗にしたbigaedeに弄ったbrigadeデータを書き込み 16 | f.insert_tail "inset_tail したよ #{data * 3}" 17 | 18 | # streamの終了を明示 19 | f.insert_eos 20 | -------------------------------------------------------------------------------- /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_test/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_test/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 | -------------------------------------------------------------------------------- /docker/conf/mruby.conf: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | mrubyHandlerMiddle /etc/apache2/hook/test.rb cache 5 | 6 | 7 | 8 | mrubyHandlerMiddleCode 'Apache.echo "server ip: #{Apache::Connection.new.local_ip}: hello mod_mruby world."' 9 | 10 | 11 | # and write something config for mod_mruby. 12 | 13 | 14 | -------------------------------------------------------------------------------- /mruby/NEWS: -------------------------------------------------------------------------------- 1 | * NEWS 2 | 3 | This document is a list of user visible feature changes made between 4 | releases except for bug fixes. 5 | 6 | Note that each entry is kept so brief that no reason behind or 7 | reference information is supplied with. For a full list of changes 8 | with all sufficient information, see the ChangeLog file. 9 | 10 | 11 | ** Information about first release v1.0.0 12 | 13 | 14 | -------------------------------------------------------------------------------- /mruby_test/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_test/NEWS: -------------------------------------------------------------------------------- 1 | * NEWS 2 | 3 | This document is a list of user visible feature changes made between 4 | releases except for bug fixes. 5 | 6 | Note that each entry is kept so brief that no reason behind or 7 | reference information is supplied with. For a full list of changes 8 | with all sufficient information, see the ChangeLog file. 9 | 10 | 11 | ** Information about first release v1.0.0 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/proxy/proxy.rb: -------------------------------------------------------------------------------- 1 | backends = [ 2 | "http://192.168.0.101:8888/", 3 | "http://192.168.0.102:8888/", 4 | "http://192.168.0.103:8888/", 5 | "http://192.168.0.104:8888/", 6 | ] 7 | 8 | r = Apache::Request.new() 9 | 10 | r.handler = "proxy-server" 11 | r.proxyreq = Apache::PROXYREQ_REVERSE 12 | r.filename = "proxy:" + backends[rand(backends.length)] + r.uri 13 | 14 | Apache::return(Apache::OK) 15 | -------------------------------------------------------------------------------- /example/rewrite/rewrite2.rb: -------------------------------------------------------------------------------- 1 | # RewriteEngine on 2 | # RewriteRule ^/hoge/$ /fuga/ 3 | 4 | r = Apache::Request.new() 5 | s = Apache::Server.new() 6 | 7 | match_hoge = Regexp.new("^/hoge/(.*)").match(r.uri) 8 | 9 | if match_hoge 10 | redirect = "/fuga/" + match_hoge[1] 11 | r.filename = s.document_root + redirect 12 | 13 | Apache.return(Apache::OK) 14 | else 15 | Apache.return(Apache::DECLINED) 16 | end 17 | -------------------------------------------------------------------------------- /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 < 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_test/.gitignore: -------------------------------------------------------------------------------- 1 | *.lock 2 | *.bak 3 | *.bc 4 | *.d 5 | *.i 6 | *.o 7 | *.orig 8 | *.pdb 9 | *.rej 10 | *.s 11 | *.sav 12 | *.swp 13 | *.tmp 14 | *~ 15 | .DS_Store 16 | .ccmalloc 17 | .svn 18 | .vscode 19 | .yardoc 20 | .ccls* 21 | compile_flags.txt 22 | compile_commands.json 23 | cscope.files 24 | cscope.out 25 | tags 26 | 27 | /.git 28 | /bin 29 | /build 30 | /mruby-source-*.gem 31 | 32 | /benchmark/**/*.dat 33 | /benchmark/*.pdf 34 | /benchmark/*.png 35 | 36 | /doc/api 37 | /doc/capi 38 | -------------------------------------------------------------------------------- /mruby_test/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 | -------------------------------------------------------------------------------- /src/ap_mrb_request.h: -------------------------------------------------------------------------------- 1 | #ifndef AP_MRB_REQUEST_H 2 | #define AP_MRB_REQUEST_H 3 | 4 | #include 5 | #include "apr_strings.h" 6 | #include "http_request.h" 7 | #include "apr_file_info.h" 8 | #include "mruby.h" 9 | #include "mruby/data.h" 10 | #include "mruby/variable.h" 11 | #include "mruby/class.h" 12 | 13 | mrb_value ap_mrb_str_to_value(mrb_state *mrb, apr_pool_t *p, const char *str); 14 | int ap_mrb_push_request(request_rec *r); 15 | request_rec *ap_mrb_get_request(); 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-sleep/README.md: -------------------------------------------------------------------------------- 1 | # Sleep Module for mruby 2 | mruby sleep module 3 | 4 | ## install by mrbgems 5 | - add conf.gem line to `build_config.rb` 6 | ```ruby 7 | MRuby::Build.new do |conf| 8 | 9 | # ... (snip) ... 10 | 11 | conf.gem :core => 'mruby-sleep' 12 | end 13 | ``` 14 | 15 | ## example 16 | 17 | ```ruby 18 | sleep(10) 19 | usleep(10000) 20 | ``` 21 | 22 | # License 23 | under the MIT License: 24 | 25 | * http://www.opensource.org/licenses/mit-license.php 26 | 27 | 28 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-sleep/README.md: -------------------------------------------------------------------------------- 1 | # Sleep Module for mruby 2 | mruby sleep module 3 | 4 | ## install by mrbgems 5 | - add conf.gem line to `build_config.rb` 6 | ```ruby 7 | MRuby::Build.new do |conf| 8 | 9 | # ... (snip) ... 10 | 11 | conf.gem :core => 'mruby-sleep' 12 | end 13 | ``` 14 | 15 | ## example 16 | 17 | ```ruby 18 | sleep(10) 19 | usleep(10000) 20 | ``` 21 | 22 | # License 23 | under the MIT License: 24 | 25 | * http://www.opensource.org/licenses/mit-license.php 26 | 27 | 28 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /mruby_test/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 | -------------------------------------------------------------------------------- /src/ap_mrb_filter.h: -------------------------------------------------------------------------------- 1 | #ifndef AP_MRB_FILTER_H 2 | #define AP_MRB_FILTER_H 3 | 4 | #include "ap_mrb_request.h" 5 | 6 | typedef struct { 7 | ap_filter_t *f; 8 | apr_bucket_brigade *bb; 9 | apr_finfo_t *finfo; 10 | apr_bucket_file *file_bucket; 11 | } ap_mrb_filter_rec; 12 | 13 | void ap_mrb_set_filter_rec(ap_filter_t *f, apr_bucket_brigade *bb, apr_pool_t *pool); 14 | ap_mrb_filter_rec *ap_mrb_get_filter_rec(apr_pool_t *pool); 15 | 16 | // void ap_mruby_filter_init(mrb_state *mrb, struct RClass *class_core); 17 | 18 | #endif 19 | -------------------------------------------------------------------------------- /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", "#{spec.build_dir}/tools/mruby/mruby.cxx") 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /mruby_test/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", "#{spec.build_dir}/tools/mruby/mruby.cxx") 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /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 (s1 > s2 && s1 < s2 + n) 10 | { 11 | s1 += n; 12 | s2 += n; 13 | while (n-- > 0) { 14 | *--s1 = *--s2; 15 | } 16 | } 17 | else if (s1 != s2) { 18 | while (n-- > 0) { 19 | *s1++ = *s2++; 20 | } 21 | } 22 | else { 23 | /* nothing to do. */ 24 | } 25 | } 26 | 27 | #endif /* MRB_VALUE_ARRAY_H__ */ 28 | -------------------------------------------------------------------------------- /mruby_test/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 (s1 > s2 && s1 < s2 + n) 10 | { 11 | s1 += n; 12 | s2 += n; 13 | while (n-- > 0) { 14 | *--s1 = *--s2; 15 | } 16 | } 17 | else if (s1 != s2) { 18 | while (n-- > 0) { 19 | *s1++ = *s2++; 20 | } 21 | } 22 | else { 23 | /* nothing to do. */ 24 | } 25 | } 26 | 27 | #endif /* MRB_VALUE_ARRAY_H__ */ 28 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-socket/test/basicsocket.rb: -------------------------------------------------------------------------------- 1 | assert('BasicSocket') do 2 | assert_equal(Class, BasicSocket.class) 3 | end 4 | 5 | assert('super class of BasicSocket') do 6 | assert_equal(IO, BasicSocket.superclass) 7 | end 8 | 9 | assert('BasicSocket.do_not_reverse_lookup') do 10 | assert_equal(BasicSocket.do_not_reverse_lookup, true) 11 | end 12 | 13 | assert('BasicSocket.do_not_reverse_lookup=') do 14 | BasicSocket.do_not_reverse_lookup = false 15 | assert_equal(BasicSocket.do_not_reverse_lookup, false) 16 | BasicSocket.do_not_reverse_lookup = true 17 | end 18 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-socket/test/basicsocket.rb: -------------------------------------------------------------------------------- 1 | assert('BasicSocket') do 2 | assert_equal(Class, BasicSocket.class) 3 | end 4 | 5 | assert('super class of BasicSocket') do 6 | assert_equal(IO, BasicSocket.superclass) 7 | end 8 | 9 | assert('BasicSocket.do_not_reverse_lookup') do 10 | assert_equal(BasicSocket.do_not_reverse_lookup, true) 11 | end 12 | 13 | assert('BasicSocket.do_not_reverse_lookup=') do 14 | BasicSocket.do_not_reverse_lookup = false 15 | assert_equal(BasicSocket.do_not_reverse_lookup, false) 16 | BasicSocket.do_not_reverse_lookup = true 17 | end 18 | -------------------------------------------------------------------------------- /src/ap_mrb_init.h: -------------------------------------------------------------------------------- 1 | #ifndef AP_MRB_INIT_H 2 | #define AP_MRB_INIT_H 3 | 4 | #include "mruby.h" 5 | #include "mruby/data.h" 6 | #include "mruby/variable.h" 7 | #include "mruby/class.h" 8 | /* 9 | #include "ap_mrb_request.h" 10 | #include "ap_mrb_server.h" 11 | #include "ap_mrb_connection.h" 12 | #include "ap_mrb_core.h" 13 | #include "ap_mrb_string.h" 14 | 15 | struct RClass *class; 16 | struct RClass *class_request; 17 | struct RClass *class_server; 18 | struct RClass *class_conn; 19 | struct RClass *class_headers_in; 20 | struct RClass *class_headers_out; 21 | */ 22 | 23 | #endif 24 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_extension_example/src/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static mrb_value 5 | mrb_c_method(mrb_state *mrb, mrb_value self) 6 | { 7 | puts("A C Extension"); 8 | return self; 9 | } 10 | 11 | void 12 | mrb_c_extension_example_gem_init(mrb_state* mrb) { 13 | struct RClass *class_cextension = mrb_define_module(mrb, "CExtension"); 14 | mrb_define_class_method(mrb, class_cextension, "c_method", mrb_c_method, MRB_ARGS_NONE()); 15 | } 16 | 17 | void 18 | mrb_c_extension_example_gem_final(mrb_state* mrb) { 19 | /* finalizer */ 20 | } 21 | -------------------------------------------------------------------------------- /mruby_test/examples/mrbgems/c_extension_example/src/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static mrb_value 5 | mrb_c_method(mrb_state *mrb, mrb_value self) 6 | { 7 | puts("A C Extension"); 8 | return self; 9 | } 10 | 11 | void 12 | mrb_c_extension_example_gem_init(mrb_state* mrb) { 13 | struct RClass *class_cextension = mrb_define_module(mrb, "CExtension"); 14 | mrb_define_class_method(mrb, class_cextension, "c_method", mrb_c_method, MRB_ARGS_NONE()); 15 | } 16 | 17 | void 18 | mrb_c_extension_example_gem_final(mrb_state* mrb) { 19 | /* finalizer */ 20 | } 21 | -------------------------------------------------------------------------------- /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 | 21 | -------------------------------------------------------------------------------- /example/suexec/suexec.rb: -------------------------------------------------------------------------------- 1 | # 2 | # use mruby-process, mruby-random, mruby-capability 3 | # 4 | 5 | uid = 501 6 | 7 | pid = Process.fork { 8 | c = Capability.new 9 | r = Apache::Request.new 10 | c.get_proc 11 | cap = [Capability::CAP_SETUID, Capability::CAP_SETGID] 12 | c.set Capability::CAP_PERMITTED, cap 13 | c.set Capability::CAP_EFFECTIVE, cap 14 | c.setuid(uid) 15 | c.clear Capability::CAP_EFFECTIVE, cap 16 | c.clear Capability::CAP_PERMITTED, cap 17 | r.run_handler 18 | Apache.errlogger 4, "suexec for #{r.filename}. set to uid #{uid}." 19 | } 20 | 21 | Process.waitpid pid 22 | -------------------------------------------------------------------------------- /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/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 | 21 | -------------------------------------------------------------------------------- /mruby_test/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 | -------------------------------------------------------------------------------- /example/rewrite/rewrite.rb: -------------------------------------------------------------------------------- 1 | # RewriteEngine On 2 | # RewriteRule ^/hoge/(.*) /fuga/$1 3 | # RewriteRule ^/fuga/hage/(.*) /foo/$1 4 | 5 | r = Apache::Request.new() 6 | s = Apache::Server.new() 7 | 8 | match_hoge = Regexp.new("^/hoge/(.*)").match(r.uri) 9 | 10 | if match_hoge 11 | redirect = "/fuga/" + match_hoge[1] 12 | match_hage = Regexp.new("^/fuga/hage/(.*)").match(redirect) 13 | 14 | if match_hage 15 | redirect = "/foo/" + match_hage[1] 16 | end 17 | 18 | r.filename = s.document_root + redirect 19 | 20 | Apache.return(Apache::OK) 21 | else 22 | Apache.return(Apache::DECLINED) 23 | end 24 | -------------------------------------------------------------------------------- /mruby/benchmark/build_config_boxing.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | toolchain :gcc 3 | end 4 | 5 | MRuby::Build.new('no_boxing') do |conf| 6 | toolchain :gcc 7 | 8 | conf.gembox 'default' 9 | end 10 | 11 | MRuby::Build.new('word_boxing') do |conf| 12 | toolchain :gcc 13 | 14 | conf.gembox 'default' 15 | conf.compilers.each do |c| 16 | c.defines += %w(MRB_WORD_BOXING) 17 | end 18 | end 19 | 20 | MRuby::Build.new('nan_boxing') do |conf| 21 | toolchain :gcc 22 | 23 | conf.gembox 'default' 24 | conf.compilers.each do |c| 25 | c.defines += %w(MRB_NAN_BOXING) 26 | end 27 | end 28 | 29 | -------------------------------------------------------------------------------- /mruby/examples/mrbgems/c_and_ruby_extension_example/src/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static mrb_value 5 | mrb_c_method(mrb_state *mrb, mrb_value self) 6 | { 7 | puts("A C Extension"); 8 | return self; 9 | } 10 | 11 | void 12 | mrb_c_and_ruby_extension_example_gem_init(mrb_state* mrb) { 13 | struct RClass *class_cextension = mrb_define_module(mrb, "CRubyExtension"); 14 | mrb_define_class_method(mrb, class_cextension, "c_method", mrb_c_method, MRB_ARGS_NONE()); 15 | } 16 | 17 | void 18 | mrb_c_and_ruby_extension_example_gem_final(mrb_state* mrb) { 19 | /* finalizer */ 20 | } 21 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: 3 | - gcc 4 | - clang 5 | before_install: 6 | - sudo apt-get -qq update 7 | install: 8 | - sudo apt-get -qq install rake bison libcurl4-openssl-dev libmarkdown2-dev 9 | env: 10 | - HTTPD_VERSION=httpd-2.4.43 11 | APR=apr-1.7.0 12 | APR_UTIL=apr-util-1.6.1 13 | HTTPD_CONFIG_OPT= 14 | before_script: 15 | - echo "HTTPD_VERSION=${HTTPD_VERSION}" > httpd_version 16 | - echo "APR=${APR}" >> httpd_version 17 | - echo "APR_UTIL=${APR_UTIL}" >> httpd_version 18 | - echo "HTTPD_CONFIG_OPT='${HTTPD_CONFIG_OPT}'" >> httpd_version 19 | script: 20 | - sh test.sh 21 | -------------------------------------------------------------------------------- /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_test/benchmark/build_config_boxing.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | toolchain :gcc 3 | end 4 | 5 | MRuby::Build.new('no_boxing') do |conf| 6 | toolchain :gcc 7 | 8 | conf.gembox 'default' 9 | end 10 | 11 | MRuby::Build.new('word_boxing') do |conf| 12 | toolchain :gcc 13 | 14 | conf.gembox 'default' 15 | conf.compilers.each do |c| 16 | c.defines += %w(MRB_WORD_BOXING) 17 | end 18 | end 19 | 20 | MRuby::Build.new('nan_boxing') do |conf| 21 | toolchain :gcc 22 | 23 | conf.gembox 'default' 24 | conf.compilers.each do |c| 25 | c.defines += %w(MRB_NAN_BOXING) 26 | end 27 | end 28 | 29 | -------------------------------------------------------------------------------- /mruby_test/examples/mrbgems/c_and_ruby_extension_example/src/example.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static mrb_value 5 | mrb_c_method(mrb_state *mrb, mrb_value self) 6 | { 7 | puts("A C Extension"); 8 | return self; 9 | } 10 | 11 | void 12 | mrb_c_and_ruby_extension_example_gem_init(mrb_state* mrb) { 13 | struct RClass *class_cextension = mrb_define_module(mrb, "CRubyExtension"); 14 | mrb_define_class_method(mrb, class_cextension, "c_method", mrb_c_method, MRB_ARGS_NONE()); 15 | } 16 | 17 | void 18 | mrb_c_and_ruby_extension_example_gem_final(mrb_state* mrb) { 19 | /* finalizer */ 20 | } 21 | -------------------------------------------------------------------------------- /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 | 25 | -------------------------------------------------------------------------------- /mruby_test/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 | -------------------------------------------------------------------------------- /example/RaspberryPi/led.rb: -------------------------------------------------------------------------------- 1 | r = Apache::Request.new 2 | io = WiringPi::GPIO.new 3 | pin = 7 4 | 5 | #Apache.rputs "filename = #{r.filename}" 6 | #Apache.rputs "uri = #{r.uri}" 7 | 8 | if r.uri == "/led/on" 9 | io.write(pin, WiringPi::HIGH) 10 | Apache.return 200 11 | elsif r.uri == "/led/off" 12 | io.write(pin, WiringPi::LOW) 13 | Apache.return 200 14 | elsif r.uri == "/led/flash" 15 | 5.times do |v| 16 | io.write(pin, WiringPi::HIGH) 17 | Sleep::sleep 1 18 | io.write(pin, WiringPi::LOW) 19 | Sleep::sleep 1 20 | end 21 | Apache.return 200 22 | else 23 | Apache.return Apache::DECLINED 24 | end 25 | 26 | -------------------------------------------------------------------------------- /mruby_test/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 | 25 | -------------------------------------------------------------------------------- /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_test/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/examples/targets/build_config_android_armeabi.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | 3 | # Gets set by the VS command prompts. 4 | if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] 5 | toolchain :visualcpp 6 | else 7 | toolchain :gcc 8 | end 9 | 10 | enable_debug 11 | 12 | # include the default GEMs 13 | conf.gembox 'default' 14 | end 15 | 16 | # Requires Android NDK r13 or later. 17 | MRuby::CrossBuild.new('android-armeabi') do |conf| 18 | params = { 19 | :arch => 'armeabi', 20 | :platform => 'android-24', 21 | :toolchain => :clang, 22 | } 23 | toolchain :android, params 24 | 25 | conf.gembox 'default' 26 | end 27 | -------------------------------------------------------------------------------- /mruby/examples/targets/build_config_android_arm64-v8a.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | 3 | # Gets set by the VS command prompts. 4 | if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] 5 | toolchain :visualcpp 6 | else 7 | toolchain :gcc 8 | end 9 | 10 | enable_debug 11 | 12 | # include the default GEMs 13 | conf.gembox 'default' 14 | end 15 | 16 | # Requires Android NDK r13 or later. 17 | MRuby::CrossBuild.new('android-arm64-v8a') do |conf| 18 | params = { 19 | :arch => 'arm64-v8a', 20 | :platform => 'android-24', 21 | :toolchain => :clang, 22 | } 23 | toolchain :android, params 24 | 25 | conf.gembox 'default' 26 | end 27 | -------------------------------------------------------------------------------- /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', 'mruby developers'] 4 | spec.summary = 'standard socket class' 5 | 6 | spec.cc.include_paths << "#{build.root}/src" 7 | #spec.cc.defines << "HAVE_SA_LEN=0" 8 | 9 | # If Windows, use winsock 10 | if for_windows? 11 | spec.linker.libraries << "wsock32" 12 | spec.linker.libraries << "ws2_32" 13 | end 14 | 15 | spec.add_dependency('mruby-io', :core => 'mruby-io') 16 | spec.add_dependency('mruby-pack', :core => 'mruby-pack') 17 | # spec.add_dependency('mruby-mtest') 18 | end 19 | -------------------------------------------------------------------------------- /mruby_test/examples/targets/build_config_android_armeabi.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | 3 | # Gets set by the VS command prompts. 4 | if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] 5 | toolchain :visualcpp 6 | else 7 | toolchain :gcc 8 | end 9 | 10 | enable_debug 11 | 12 | # include the default GEMs 13 | conf.gembox 'default' 14 | end 15 | 16 | # Requires Android NDK r13 or later. 17 | MRuby::CrossBuild.new('android-armeabi') do |conf| 18 | params = { 19 | :arch => 'armeabi', 20 | :platform => 'android-24', 21 | :toolchain => :clang, 22 | } 23 | toolchain :android, params 24 | 25 | conf.gembox 'default' 26 | end 27 | -------------------------------------------------------------------------------- /example/auth/authn_basic_by_redis.rb: -------------------------------------------------------------------------------- 1 | # Basic Authentication Sample 2 | # 3 | # Apache configuration 4 | # 5 | # 6 | # AuthType basic 7 | # AuthName "Message for clients" 8 | # AuthBasicProvider mruby 9 | # mrubyAuthnCheckPassword /path/to/authn_basic.rb 10 | # require valid-user 11 | # 12 | # 13 | 14 | a = Apache 15 | 16 | host = "127.0.0.1" 17 | port = 6379 18 | 19 | anp = Apache::AuthnProvider.new 20 | redis = Redis.new(host, port) 21 | 22 | if redis.get(anp.user) == anp.password 23 | Apache.return(Apache::AuthnProvider::AUTH_GRANTED) 24 | else 25 | Apache.return(Apache::AuthnProvider::AUTH_DENIED) 26 | end 27 | -------------------------------------------------------------------------------- /mruby_test/examples/targets/build_config_android_arm64-v8a.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | 3 | # Gets set by the VS command prompts. 4 | if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] 5 | toolchain :visualcpp 6 | else 7 | toolchain :gcc 8 | end 9 | 10 | enable_debug 11 | 12 | # include the default GEMs 13 | conf.gembox 'default' 14 | end 15 | 16 | # Requires Android NDK r13 or later. 17 | MRuby::CrossBuild.new('android-arm64-v8a') do |conf| 18 | params = { 19 | :arch => 'arm64-v8a', 20 | :platform => 'android-24', 21 | :toolchain => :clang, 22 | } 23 | toolchain :android, params 24 | 25 | conf.gembox 'default' 26 | end 27 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-socket/mrbgem.rake: -------------------------------------------------------------------------------- 1 | MRuby::Gem::Specification.new('mruby-socket') do |spec| 2 | spec.license = 'MIT' 3 | spec.authors = ['Internet Initiative Japan', 'mruby developers'] 4 | spec.summary = 'standard socket class' 5 | 6 | spec.cc.include_paths << "#{build.root}/src" 7 | #spec.cc.defines << "HAVE_SA_LEN=0" 8 | 9 | # If Windows, use winsock 10 | if for_windows? 11 | spec.linker.libraries << "wsock32" 12 | spec.linker.libraries << "ws2_32" 13 | end 14 | 15 | spec.add_dependency('mruby-io', :core => 'mruby-io') 16 | spec.add_dependency('mruby-pack', :core => 'mruby-pack') 17 | # spec.add_dependency('mruby-mtest') 18 | end 19 | -------------------------------------------------------------------------------- /example/redis/authn_basic_by_redis.rb: -------------------------------------------------------------------------------- 1 | # Basic Authentication Sample 2 | # 3 | # Apache configuration 4 | # 5 | # 6 | # AuthType basic 7 | # AuthName "Message for clients" 8 | # AuthBasicProvider mruby 9 | # mrubyAuthnCheckPassword /path/to/authn_basic.rb 10 | # require valid-user 11 | # 12 | # 13 | 14 | a = Apache 15 | 16 | host = "127.0.0.1" 17 | port = 6379 18 | 19 | anp = Apache::AuthnProvider.new 20 | redis = Apache::Redis.new(host, port) 21 | 22 | if redis.get(anp.user) == anp.password 23 | Apache.return(Apache::AuthnProvider::AUTH_GRANTED) 24 | else 25 | Apache.return(Apache::AuthnProvider::AUTH_DENIED) 26 | end 27 | -------------------------------------------------------------------------------- /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_ENABLE_DEBUG_HOOK 10 | # error mruby-bin-debugger need 'MRB_ENABLE_DEBUG_HOOK' configuration in your 'build_config.rb' 11 | #endif 12 | 13 | #ifdef MRB_DISABLE_STDIO 14 | # error mruby-bin-debugger conflicts 'MRB_DISABLE_STDIO' configuration in your 'build_config.rb' 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 | -------------------------------------------------------------------------------- /src/ap_mrb_core.h: -------------------------------------------------------------------------------- 1 | #ifndef AP_MRB_UTILS_H 2 | #define AP_MRB_UTILS_H 3 | 4 | #ifndef _WIN32 5 | #include 6 | #include 7 | #include 8 | #else 9 | #include 10 | #endif 11 | #include "mruby.h" 12 | 13 | #include "http_protocol.h" 14 | #include "mruby/string.h" 15 | #include "mruby/variable.h" 16 | 17 | #define INVALID_PRIORITY -1 18 | 19 | // int mod_mruby_return_code; 20 | 21 | typedef struct _code { 22 | char *c_name; 23 | int c_val; 24 | } CODE; 25 | 26 | int ap_mrb_get_status_code(); 27 | int ap_mrb_set_status_code(int val); 28 | void ap_mrb_raise_error(mrb_state *mrb, mrb_value obj, mod_mruby_code_t *code); 29 | 30 | #endif 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 | 6 | spec.add_dependency 'mruby-compiler', :core => 'mruby-compiler' 7 | 8 | exec = exefile("#{build.build_dir}/bin/mrbc") 9 | mrbc_objs = Dir.glob("#{spec.dir}/tools/mrbc/*.c").map { |f| objfile(f.pathmap("#{spec.build_dir}/tools/mrbc/%n")) }.flatten 10 | 11 | file exec => mrbc_objs + [build.libmruby_core_static] do |t| 12 | build.linker.run t.name, t.prerequisites 13 | end 14 | 15 | build.bins << 'mrbc' unless build.bins.find { |v| v == 'mrbc' } 16 | end 17 | -------------------------------------------------------------------------------- /mruby_test/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_ENABLE_DEBUG_HOOK 10 | # error mruby-bin-debugger need 'MRB_ENABLE_DEBUG_HOOK' configuration in your 'build_config.rb' 11 | #endif 12 | 13 | #ifdef MRB_DISABLE_STDIO 14 | # error mruby-bin-debugger conflicts 'MRB_DISABLE_STDIO' configuration in your 'build_config.rb' 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_test/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 | 6 | spec.add_dependency 'mruby-compiler', :core => 'mruby-compiler' 7 | 8 | exec = exefile("#{build.build_dir}/bin/mrbc") 9 | mrbc_objs = Dir.glob("#{spec.dir}/tools/mrbc/*.c").map { |f| objfile(f.pathmap("#{spec.build_dir}/tools/mrbc/%n")) }.flatten 10 | 11 | file exec => mrbc_objs + [build.libmruby_core_static] do |t| 12 | build.linker.run t.name, t.prerequisites 13 | end 14 | 15 | build.bins << 'mrbc' unless build.bins.find { |v| v == 'mrbc' } 16 | end 17 | -------------------------------------------------------------------------------- /example/limit_control/file_limit_dec_by_redis.rb: -------------------------------------------------------------------------------- 1 | # file limit control 2 | # 3 | # mrubyAccessCheckerMiddle /var/www/html/file_limit_inc_by_redis.rb 4 | # mrubyLogTransactionMiddle /var/www/html/file_limit_dec_by_redis.rb 5 | 6 | redis = Apache::Redis.new("127.0.0.1", 6379) 7 | req = Apache::Request.new 8 | 9 | fcounter = redis.get req.filename 10 | 11 | if fcounter.nil? or fcounter.to_i <= 0 12 | Apache.errlogger(4, "unexpect error: fcounter is nil or <= 0 at dec phase") 13 | redis.set req.filename, fcounter 14 | else 15 | fcounter = (fcounter.to_i - 1).to_s 16 | Apache.errlogger(4, "fcounter dec: #{req.filename}: #{fcounter.to_s}") 17 | redis.set req.filename, fcounter 18 | end 19 | -------------------------------------------------------------------------------- /mruby/mruby-source.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'mruby/source' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "mruby-source" 8 | spec.version = MRuby::Source::MRUBY_VERSION 9 | spec.authors = [ MRuby::Source::MRUBY_AUTHOR ] 10 | 11 | spec.summary = %q{MRuby source code wrapper.} 12 | spec.description = %q{MRuby source code wrapper for use with Ruby libs.} 13 | spec.homepage = "https://mruby.org" 14 | spec.license = "MIT" 15 | 16 | spec.files = `git ls-files -z`.split("\x0") 17 | spec.require_paths = ["lib"] 18 | end 19 | -------------------------------------------------------------------------------- /mrbgems/mod_mruby_mrblib/mrblib/mrb_apache.rb: -------------------------------------------------------------------------------- 1 | class Apache 2 | class Request 3 | def reverse_proxy path 4 | self.handler = "proxy-server" 5 | self.proxyreq = Apache::PROXYREQ_REVERSE 6 | self.filename = "proxy:" + path 7 | end 8 | end 9 | class Headers_in 10 | def user_agent; self["User-Agent"]; end 11 | def referer; self["Referer"]; end 12 | end 13 | class Filter 14 | def body 15 | data = self.flatten 16 | self.cleanup 17 | data 18 | end 19 | def body= output 20 | self.insert_tail output 21 | self.insert_eos 22 | end 23 | end 24 | end 25 | module Kernel 26 | def get_server_class 27 | Apache 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /mruby_test/mruby-source.gemspec: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | lib = File.expand_path('../lib', __FILE__) 3 | $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) 4 | require 'mruby/source' 5 | 6 | Gem::Specification.new do |spec| 7 | spec.name = "mruby-source" 8 | spec.version = MRuby::Source::MRUBY_VERSION 9 | spec.authors = [ MRuby::Source::MRUBY_AUTHOR ] 10 | 11 | spec.summary = %q{MRuby source code wrapper.} 12 | spec.description = %q{MRuby source code wrapper for use with Ruby libs.} 13 | spec.homepage = "https://mruby.org" 14 | spec.license = "MIT" 15 | 16 | spec.files = `git ls-files -z`.split("\x0") 17 | spec.require_paths = ["lib"] 18 | end 19 | -------------------------------------------------------------------------------- /test/docker/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM stackbrew/ubuntu:14.04 2 | # 3 | MAINTAINER matsumotory 4 | # 5 | RUN apt-get -y update 6 | RUN apt-get -y install sudo openssh-server 7 | RUN apt-get -y install git 8 | RUN apt-get -y install apache2 apache2-dev apache2-utils 9 | RUN apt-get -y install rake 10 | RUN apt-get -y install ruby2.0 ruby2.0-dev 11 | RUN apt-get -y install bison 12 | RUN apt-get -y install libcurl4-openssl-dev 13 | RUN apt-get -y install libhiredis-dev 14 | RUN apt-get -y install libmarkdown2-dev 15 | RUN apt-get -y install libcap-dev 16 | RUN apt-get -y install libcgroup-dev 17 | # 18 | RUN cd /usr/local/src/ && git clone https://github.com/matsumoto-r/mod_mruby.git 19 | RUN cd /usr/local/src/mod_mruby && sh test.sh 20 | -------------------------------------------------------------------------------- /mruby/.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CIFuzz 2 | on: [pull_request] 3 | jobs: 4 | Fuzzing: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Build Fuzzers 8 | uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master 9 | with: 10 | oss-fuzz-project-name: 'mruby' 11 | dry-run: false 12 | - name: Run Fuzzers 13 | uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master 14 | with: 15 | oss-fuzz-project-name: 'mruby' 16 | fuzz-seconds: 600 17 | dry-run: false 18 | - name: Upload Crash 19 | uses: actions/upload-artifact@v1 20 | if: failure() 21 | with: 22 | name: artifacts 23 | path: ./out/artifacts 24 | 25 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-exit/src/mruby-exit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static mrb_value 5 | f_exit(mrb_state *mrb, mrb_value self) 6 | { 7 | mrb_value status = mrb_true_value(); 8 | int istatus; 9 | 10 | mrb_get_args(mrb, "|o", &status); 11 | istatus = mrb_true_p(status) ? EXIT_SUCCESS : 12 | mrb_false_p(status) ? EXIT_FAILURE : 13 | (int)mrb_int(mrb, status); 14 | exit(istatus); 15 | 16 | /* not reached */ 17 | return status; 18 | } 19 | 20 | void 21 | mrb_mruby_exit_gem_init(mrb_state* mrb) 22 | { 23 | mrb_define_method(mrb, mrb->kernel_module, "exit", f_exit, MRB_ARGS_OPT(1)); 24 | } 25 | 26 | void 27 | mrb_mruby_exit_gem_final(mrb_state* mrb) 28 | { 29 | } 30 | -------------------------------------------------------------------------------- /example/auth/authn_basic.rb: -------------------------------------------------------------------------------- 1 | # Basic Authentication Sample 2 | # 3 | # Apache configuration 4 | # 5 | # 6 | # AuthType basic 7 | # AuthName "Message for clients" 8 | # AuthBasicProvider mruby 9 | # mrubyAuthnCheckPassword /path/to/authn_basic.rb 10 | # require valid-user 11 | # 12 | # 13 | 14 | user_list = { 15 | "bilbo" => "foo", 16 | "frodo" => "bar", 17 | "samwise" => "baz", 18 | "aragorn" => "qux", 19 | "legolas" => "quux", 20 | "gimli" => "corge", 21 | } 22 | 23 | anp = Apache::AuthnProvider.new 24 | 25 | if user_list[anp.user] == anp.password 26 | Apache.return(Apache::AuthnProvider::AUTH_GRANTED) 27 | else 28 | Apache.return(Apache::AuthnProvider::AUTH_DENIED) 29 | end 30 | -------------------------------------------------------------------------------- /mruby_test/.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CIFuzz 2 | on: [pull_request] 3 | jobs: 4 | Fuzzing: 5 | runs-on: ubuntu-latest 6 | steps: 7 | - name: Build Fuzzers 8 | uses: google/oss-fuzz/infra/cifuzz/actions/build_fuzzers@master 9 | with: 10 | oss-fuzz-project-name: 'mruby' 11 | dry-run: false 12 | - name: Run Fuzzers 13 | uses: google/oss-fuzz/infra/cifuzz/actions/run_fuzzers@master 14 | with: 15 | oss-fuzz-project-name: 'mruby' 16 | fuzz-seconds: 600 17 | dry-run: false 18 | - name: Upload Crash 19 | uses: actions/upload-artifact@v1 20 | if: failure() 21 | with: 22 | name: artifacts 23 | path: ./out/artifacts 24 | 25 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-exit/src/mruby-exit.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | static mrb_value 5 | f_exit(mrb_state *mrb, mrb_value self) 6 | { 7 | mrb_value status = mrb_true_value(); 8 | int istatus; 9 | 10 | mrb_get_args(mrb, "|o", &status); 11 | istatus = mrb_true_p(status) ? EXIT_SUCCESS : 12 | mrb_false_p(status) ? EXIT_FAILURE : 13 | (int)mrb_int(mrb, status); 14 | exit(istatus); 15 | 16 | /* not reached */ 17 | return status; 18 | } 19 | 20 | void 21 | mrb_mruby_exit_gem_init(mrb_state* mrb) 22 | { 23 | mrb_define_method(mrb, mrb->kernel_module, "exit", f_exit, MRB_ARGS_OPT(1)); 24 | } 25 | 26 | void 27 | mrb_mruby_exit_gem_final(mrb_state* mrb) 28 | { 29 | } 30 | -------------------------------------------------------------------------------- /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/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 | -------------------------------------------------------------------------------- /example/filter/ouput_filter/filter2.rb: -------------------------------------------------------------------------------- 1 | # 2 | # httpd.conf 3 | # 4 | # SetOutputFilter mruby 5 | # mrubyOutputFilter /usr/local/apache/htdocs/filter.rb 6 | # 7 | f = Apache::Filter.new 8 | 9 | # read all body data 10 | data = f.flatten 11 | 12 | # cleanup old brigade 13 | f.cleanup 14 | 15 | # create new data 16 | # create string 17 | f.puts "foofoo-puts" 18 | 19 | # modify body data 20 | f.insert_tail data.upcase 21 | 22 | # insert string to tail 23 | f.insert_tail "hogehoge-tail" 24 | 25 | # insert string to head 26 | f.insert_head "fugafuga-head" 27 | 28 | # insert End of String 29 | f.insert_eos 30 | 31 | # $ curl http://127.0.0.1/index.html 32 | # fugafuga-headfoofoo-puts

IT WORKS!

33 | # hogehoge-tail 34 | -------------------------------------------------------------------------------- /mruby/examples/targets/build_config_android_armeabi_v7a_neon_hard.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | 3 | # Gets set by the VS command prompts. 4 | if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] 5 | toolchain :visualcpp 6 | else 7 | toolchain :gcc 8 | end 9 | 10 | enable_debug 11 | 12 | # include the default GEMs 13 | conf.gembox 'default' 14 | end 15 | 16 | # Requires Android NDK r13 or later. 17 | MRuby::CrossBuild.new('android-armeabi-v7a-neon-hard') do |conf| 18 | params = { 19 | :arch => 'armeabi-v7a', 20 | :mfpu => 'neon', 21 | :mfloat_abi => 'hard', 22 | :platform => 'android-24', 23 | :toolchain => :clang, 24 | } 25 | toolchain :android, params 26 | 27 | conf.gembox 'default' 28 | end 29 | -------------------------------------------------------------------------------- /example/unified_with_ngx_mruby/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 ngxin.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 | -------------------------------------------------------------------------------- /mruby_test/examples/targets/build_config_android_armeabi_v7a_neon_hard.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new do |conf| 2 | 3 | # Gets set by the VS command prompts. 4 | if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] 5 | toolchain :visualcpp 6 | else 7 | toolchain :gcc 8 | end 9 | 10 | enable_debug 11 | 12 | # include the default GEMs 13 | conf.gembox 'default' 14 | end 15 | 16 | # Requires Android NDK r13 or later. 17 | MRuby::CrossBuild.new('android-armeabi-v7a-neon-hard') do |conf| 18 | params = { 19 | :arch => 'armeabi-v7a', 20 | :mfpu => 'neon', 21 | :mfloat_abi => 'hard', 22 | :platform => 'android-24', 23 | :toolchain => :clang, 24 | } 25 | toolchain :android, params 26 | 27 | conf.gembox 'default' 28 | end 29 | -------------------------------------------------------------------------------- /mruby/src/mruby_core.rake: -------------------------------------------------------------------------------- 1 | MRuby.each_target do 2 | current_dir = File.dirname(__FILE__).relative_path_from(Dir.pwd) 3 | relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT) 4 | current_build_dir = "#{build_dir}/#{relative_from_root}" 5 | 6 | objs = Dir.glob("#{current_dir}/*.c").map { |f| 7 | next nil if cxx_exception_enabled? and f =~ /(error|vm).c$/ 8 | objfile(f.pathmap("#{current_build_dir}/%n")) 9 | }.compact 10 | 11 | if cxx_exception_enabled? 12 | objs += %w(vm error).map { |v| compile_as_cxx "#{current_dir}/#{v}.c", "#{current_build_dir}/#{v}.cxx" } 13 | end 14 | self.libmruby_objs << objs 15 | 16 | file libmruby_core_static => objs do |t| 17 | archiver.run t.name, t.prerequisites 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /mruby_test/src/mruby_core.rake: -------------------------------------------------------------------------------- 1 | MRuby.each_target do 2 | current_dir = File.dirname(__FILE__).relative_path_from(Dir.pwd) 3 | relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT) 4 | current_build_dir = "#{build_dir}/#{relative_from_root}" 5 | 6 | objs = Dir.glob("#{current_dir}/*.c").map { |f| 7 | next nil if cxx_exception_enabled? and f =~ /(error|vm).c$/ 8 | objfile(f.pathmap("#{current_build_dir}/%n")) 9 | }.compact 10 | 11 | if cxx_exception_enabled? 12 | objs += %w(vm error).map { |v| compile_as_cxx "#{current_dir}/#{v}.c", "#{current_build_dir}/#{v}.cxx" } 13 | end 14 | self.libmruby_objs << objs 15 | 16 | file libmruby_core_static => objs do |t| 17 | archiver.run t.name, t.prerequisites 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /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.each do |m| 26 | m.append_features(self) 27 | m.included(self) 28 | end 29 | self 30 | end 31 | 32 | def prepend(*args) 33 | args.reverse.each do |m| 34 | m.prepend_features(self) 35 | m.prepended(self) 36 | end 37 | self 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /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/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 Fixnum, 1234.class 38 | end 39 | -------------------------------------------------------------------------------- /mruby_test/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.each do |m| 26 | m.append_features(self) 27 | m.included(self) 28 | end 29 | self 30 | end 31 | 32 | def prepend(*args) 33 | args.reverse.each do |m| 34 | m.prepend_features(self) 35 | m.prepended(self) 36 | end 37 | self 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /mruby_test/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 | -------------------------------------------------------------------------------- /example/limit_control/file_limit_inc_by_redis.rb: -------------------------------------------------------------------------------- 1 | # file limit control 2 | # 3 | # mrubyAccessCheckerMiddle /var/www/html/file_limit_inc_by_redis.rb 4 | # mrubyLogTransactionMiddle /var/www/html/file_limit_dec_by_redis.rb 5 | 6 | redis = Apache::Redis.new("127.0.0.1", 6379) 7 | req = Apache::Request.new 8 | limit = 1 9 | 10 | Apache.rputs "pahse 1" 11 | 12 | fcounter = redis.get req.filename 13 | 14 | if fcounter.nil? or fcounter.to_i < 0 15 | fcounter = 0.to_s 16 | end 17 | 18 | fcounter = (fcounter.to_i + 1).to_s 19 | Apache.errlogger(4, "fcounter inc: #{req.filename}: #{fcounter.to_s}") 20 | 21 | if fcounter.to_i > limit 22 | redis.set req.filename, fcounter 23 | Apache.return(503) 24 | else 25 | redis.set req.filename, fcounter 26 | end 27 | 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /mruby_test/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 Fixnum, 1234.class 38 | end 39 | -------------------------------------------------------------------------------- /example/limit_control/traffic_rate_limit.rb: -------------------------------------------------------------------------------- 1 | # LoadModule mruby_module modules/mod_mruby.so 2 | # ExtendedStatus On 3 | # mrubyAccessCheckerMiddle /var/www/html/traffic_rate_limit.rb 4 | 5 | class Traffic 6 | def initialize(rate) 7 | @rate = rate 8 | end 9 | def kbcheck 10 | sb = Apache::Scoreboard.new() 11 | kbpersec = sb.total_kbyte / sb.uptime * 100 12 | Apache.errlogger(4, "kbpersec: " + kbpersec.to_s) 13 | if kbpersec > @rate 14 | true 15 | else 16 | false 17 | end 18 | end 19 | end 20 | 21 | # traffic kbyte / sec is 10000(10MB/sec) 22 | t = Traffic.new(10000) 23 | if t.kbcheck 24 | Apache::return(Apache::HTTP_SERVICE_UNAVAILABLE) 25 | else 26 | Apache::return(Apache::DECLINED) 27 | end 28 | -------------------------------------------------------------------------------- /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/mrblib/mrblib.rake: -------------------------------------------------------------------------------- 1 | MRuby.each_target do 2 | current_dir = File.dirname(__FILE__) 3 | relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT) 4 | current_build_dir = "#{build_dir}/#{relative_from_root}" 5 | 6 | self.libmruby_objs << objfile("#{current_build_dir}/mrblib") 7 | 8 | file objfile("#{current_build_dir}/mrblib") => "#{current_build_dir}/mrblib.c" 9 | file "#{current_build_dir}/mrblib.c" => [mrbcfile, __FILE__] + Dir.glob("#{current_dir}/*.rb").sort do |t| 10 | _, _, *rbfiles = t.prerequisites 11 | mkdir_p File.dirname(t.name) 12 | open(t.name, 'w') do |f| 13 | _pp "GEN", "*.rb", "#{t.name.relative_path}" 14 | f.puts File.read("#{current_dir}/init_mrblib.c") 15 | mrbc.run f, rbfiles, 'mrblib_irep' 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /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 | 10 | /* internal method `__update_hash(oldhash, index, itemhash)` */ 11 | static mrb_value 12 | enum_update_hash(mrb_state *mrb, mrb_value self) 13 | { 14 | mrb_int hash; 15 | mrb_int index; 16 | mrb_int hv; 17 | 18 | mrb_get_args(mrb, "iii", &hash, &index, &hv); 19 | hash ^= ((uint32_t)hv << (index % 16)); 20 | 21 | return mrb_fixnum_value(hash); 22 | } 23 | 24 | void 25 | mrb_init_enumerable(mrb_state *mrb) 26 | { 27 | struct RClass *enumerable; 28 | enumerable = mrb_define_module(mrb, "Enumerable"); /* 15.3.2 */ 29 | mrb_define_module_function(mrb, enumerable, "__update_hash", enum_update_hash, MRB_ARGS_REQ(3)); 30 | } 31 | -------------------------------------------------------------------------------- /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#id2name', '15.2.11.3.2') do 21 | assert_equal 'abc', :abc.id2name 22 | end 23 | 24 | assert('Symbol#to_s', '15.2.11.3.3') do 25 | assert_equal 'abc', :abc.to_s 26 | end 27 | 28 | assert('Symbol#to_sym', '15.2.11.3.4') do 29 | assert_equal :abc, :abc.to_sym 30 | end 31 | 32 | assert('Symbol#to_proc') do 33 | assert_equal 5, :abs.to_proc[-5] 34 | end 35 | -------------------------------------------------------------------------------- /mruby_test/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 | -------------------------------------------------------------------------------- /example/proxy/proxy_by_scboard.rb: -------------------------------------------------------------------------------- 1 | backends = [ 2 | "http://192.168.0.101:8888/", 3 | "http://192.168.0.102:8888/", 4 | "http://192.168.0.103:8888/", 5 | "http://192.168.0.104:8888/", 6 | ] 7 | 8 | sb = Apache::Scoreboard.new() 9 | busyrate = sb.busy_worker / (sb.process_limit * sb.worker_limit) 10 | 11 | if busyrate * 100 > 50 12 | proxy_rate = backends.length - 2 13 | else if busyrate * 100 > 70 14 | proxy_rate = backends.length - 1 15 | else if busyrate * 100 > 90 16 | proxy_rate = backends.length 17 | else 18 | proxy_rate = backends.length - 3 19 | end 20 | 21 | r = Apache::Request.new() 22 | 23 | r.handler = "proxy-server" 24 | r.proxyreq = Apache::PROXYREQ_REVERSE 25 | r.filename = "proxy:" + backends[rand(proxy_late)] + r.uri 26 | 27 | Apache::return(Apache::OK) 28 | -------------------------------------------------------------------------------- /mruby_test/mrblib/mrblib.rake: -------------------------------------------------------------------------------- 1 | MRuby.each_target do 2 | current_dir = File.dirname(__FILE__) 3 | relative_from_root = File.dirname(__FILE__).relative_path_from(MRUBY_ROOT) 4 | current_build_dir = "#{build_dir}/#{relative_from_root}" 5 | 6 | self.libmruby_objs << objfile("#{current_build_dir}/mrblib") 7 | 8 | file objfile("#{current_build_dir}/mrblib") => "#{current_build_dir}/mrblib.c" 9 | file "#{current_build_dir}/mrblib.c" => [mrbcfile, __FILE__] + Dir.glob("#{current_dir}/*.rb").sort do |t| 10 | _, _, *rbfiles = t.prerequisites 11 | mkdir_p File.dirname(t.name) 12 | open(t.name, 'w') do |f| 13 | _pp "GEN", "*.rb", "#{t.name.relative_path}" 14 | f.puts File.read("#{current_dir}/init_mrblib.c") 15 | mrbc.run f, rbfiles, 'mrblib_irep' 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /mruby_test/src/enum.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** enum.c - Enumerable module 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #include 8 | #include 9 | 10 | /* internal method `__update_hash(oldhash, index, itemhash)` */ 11 | static mrb_value 12 | enum_update_hash(mrb_state *mrb, mrb_value self) 13 | { 14 | mrb_int hash; 15 | mrb_int index; 16 | mrb_int hv; 17 | 18 | mrb_get_args(mrb, "iii", &hash, &index, &hv); 19 | hash ^= ((uint32_t)hv << (index % 16)); 20 | 21 | return mrb_fixnum_value(hash); 22 | } 23 | 24 | void 25 | mrb_init_enumerable(mrb_state *mrb) 26 | { 27 | struct RClass *enumerable; 28 | enumerable = mrb_define_module(mrb, "Enumerable"); /* 15.3.2 */ 29 | mrb_define_module_function(mrb, enumerable, "__update_hash", enum_update_hash, MRB_ARGS_REQ(3)); 30 | } 31 | -------------------------------------------------------------------------------- /mruby_test/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#id2name', '15.2.11.3.2') do 21 | assert_equal 'abc', :abc.id2name 22 | end 23 | 24 | assert('Symbol#to_s', '15.2.11.3.3') do 25 | assert_equal 'abc', :abc.to_s 26 | end 27 | 28 | assert('Symbol#to_sym', '15.2.11.3.4') do 29 | assert_equal :abc, :abc.to_sym 30 | end 31 | 32 | assert('Symbol#to_proc') do 33 | assert_equal 5, :abs.to_proc[-5] 34 | end 35 | -------------------------------------------------------------------------------- /mruby/lib/mruby-core-ext.rb: -------------------------------------------------------------------------------- 1 | autoload :Pathname, 'pathname' 2 | 3 | class Object 4 | class << self 5 | def attr_block(*syms) 6 | syms.flatten.each do |sym| 7 | class_eval "def #{sym}(&block);block.call(@#{sym}) if block_given?;@#{sym};end" 8 | end 9 | end 10 | end 11 | end 12 | 13 | class String 14 | def relative_path_from(dir) 15 | Pathname.new(File.expand_path(self)).relative_path_from(Pathname.new(File.expand_path(dir))).to_s 16 | end 17 | 18 | def relative_path 19 | relative_path_from(Dir.pwd) 20 | end 21 | end 22 | 23 | def _pp(cmd, src, tgt=nil, options={}) 24 | return if Rake.verbose 25 | 26 | width = 5 27 | template = options[:indent] ? "%#{width*options[:indent]}s %s %s" : "%-#{width}s %s %s" 28 | puts template % [cmd, src, tgt ? "-> #{tgt}" : nil] 29 | end 30 | -------------------------------------------------------------------------------- /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/mrbgems/mruby-sprintf/src/kernel.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** kernel.c - Kernel module suppliment 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #include 8 | 9 | mrb_value mrb_f_sprintf(mrb_state *mrb, mrb_value obj); /* in sprintf.c */ 10 | 11 | void 12 | mrb_mruby_sprintf_gem_init(mrb_state* mrb) 13 | { 14 | struct RClass *krn; 15 | 16 | if (mrb->kernel_module == NULL) { 17 | mrb->kernel_module = mrb_define_module(mrb, "Kernel"); /* Might be PARANOID. */ 18 | } 19 | krn = mrb->kernel_module; 20 | 21 | mrb_define_method(mrb, krn, "sprintf", mrb_f_sprintf, MRB_ARGS_REQ(1)|MRB_ARGS_REST()); 22 | mrb_define_method(mrb, krn, "format", mrb_f_sprintf, MRB_ARGS_REQ(1)|MRB_ARGS_REST()); 23 | } 24 | 25 | void 26 | mrb_mruby_sprintf_gem_final(mrb_state* mrb) 27 | { 28 | /* nothing to do. */ 29 | } 30 | 31 | -------------------------------------------------------------------------------- /mruby_test/lib/mruby-core-ext.rb: -------------------------------------------------------------------------------- 1 | autoload :Pathname, 'pathname' 2 | 3 | class Object 4 | class << self 5 | def attr_block(*syms) 6 | syms.flatten.each do |sym| 7 | class_eval "def #{sym}(&block);block.call(@#{sym}) if block_given?;@#{sym};end" 8 | end 9 | end 10 | end 11 | end 12 | 13 | class String 14 | def relative_path_from(dir) 15 | Pathname.new(File.expand_path(self)).relative_path_from(Pathname.new(File.expand_path(dir))).to_s 16 | end 17 | 18 | def relative_path 19 | relative_path_from(Dir.pwd) 20 | end 21 | end 22 | 23 | def _pp(cmd, src, tgt=nil, options={}) 24 | return if Rake.verbose 25 | 26 | width = 5 27 | template = options[:indent] ? "%#{width*options[:indent]}s %s %s" : "%-#{width}s %s %s" 28 | puts template % [cmd, src, tgt ? "-> #{tgt}" : nil] 29 | end 30 | -------------------------------------------------------------------------------- /mruby_test/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/mrbgems/mruby-sprintf/src/kernel.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** kernel.c - Kernel module suppliment 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #include 8 | 9 | mrb_value mrb_f_sprintf(mrb_state *mrb, mrb_value obj); /* in sprintf.c */ 10 | 11 | void 12 | mrb_mruby_sprintf_gem_init(mrb_state* mrb) 13 | { 14 | struct RClass *krn; 15 | 16 | if (mrb->kernel_module == NULL) { 17 | mrb->kernel_module = mrb_define_module(mrb, "Kernel"); /* Might be PARANOID. */ 18 | } 19 | krn = mrb->kernel_module; 20 | 21 | mrb_define_method(mrb, krn, "sprintf", mrb_f_sprintf, MRB_ARGS_REQ(1)|MRB_ARGS_REST()); 22 | mrb_define_method(mrb, krn, "format", mrb_f_sprintf, MRB_ARGS_REQ(1)|MRB_ARGS_REST()); 23 | } 24 | 25 | void 26 | mrb_mruby_sprintf_gem_final(mrb_state* mrb) 27 | { 28 | /* nothing to do. */ 29 | } 30 | 31 | -------------------------------------------------------------------------------- /Makefile.w32: -------------------------------------------------------------------------------- 1 | SOURCE = \ 2 | ap_mrb_authnprovider.c \ 3 | ap_mrb_connection.c \ 4 | ap_mrb_env.c \ 5 | ap_mrb_init.c \ 6 | ap_mrb_request.c \ 7 | ap_mrb_scoreboard.c \ 8 | ap_mrb_server.c \ 9 | ap_mrb_utils.c \ 10 | mod_mruby.c 11 | 12 | INC=-I. -Imruby/include 13 | APACHE_ROOT=c:/progra~1/apache~1/apache2.2 14 | APXS=perl "$(APACHE_ROOT)/bin/apxs" 15 | LIB=-lm mruby/build/host/lib/libmruby.a -llibapr-1 -llibaprutil-1 -llibhttpd -lws2_32 16 | DEF=-DAP_DECLARE_EXPORT -DAPR_DECLARE_EXPORT 17 | 18 | all: mod_mruby.so 19 | 20 | mod_mruby.so: $(SOURCE) mruby/build/host/lib/libmruby.a 21 | $(APXS) -o mod_mruby.so -c $(DEF) $(INC) $(SOURCE) -static-libgcc $(LIB) 22 | 23 | mruby/build/host/lib/libmruby.a: 24 | (cd mruby && rake) 25 | 26 | install: all 27 | $(APXS) -i -a -n "mruby" mod_mruby.so 28 | 29 | clean: 30 | -rm -rf .libs *.o *.so *.lo *.la *.slo *.loT 31 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-config/mruby-config: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | while [ $# -gt 0 ]; do 4 | case $1 in 5 | --cflags) echo MRUBY_CFLAGS;; 6 | --ldflags) echo MRUBY_LDFLAGS;; 7 | --ldflags-before-libs) echo MRUBY_LDFLAGS_BEFORE_LIBS;; 8 | --libs) echo MRUBY_LIBS;; 9 | --libmruby-path) echo MRUBY_LIBMRUBY_PATH;; 10 | --help) echo "Usage: mruby-config [switches]" 11 | echo " switches:" 12 | echo " --cflags print flags passed to compiler" 13 | echo " --ldflags print flags passed to linker" 14 | echo " --ldflags-before-libs print flags passed to linker before linked libraries" 15 | echo " --libs print linked libraries" 16 | echo " --libmruby-path print libmruby path" 17 | exit 0;; 18 | esac 19 | shift 20 | done 21 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-bin-config/mruby-config: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | while [ $# -gt 0 ]; do 4 | case $1 in 5 | --cflags) echo MRUBY_CFLAGS;; 6 | --ldflags) echo MRUBY_LDFLAGS;; 7 | --ldflags-before-libs) echo MRUBY_LDFLAGS_BEFORE_LIBS;; 8 | --libs) echo MRUBY_LIBS;; 9 | --libmruby-path) echo MRUBY_LIBMRUBY_PATH;; 10 | --help) echo "Usage: mruby-config [switches]" 11 | echo " switches:" 12 | echo " --cflags print flags passed to compiler" 13 | echo " --ldflags print flags passed to linker" 14 | echo " --ldflags-before-libs print flags passed to linker before linked libraries" 15 | echo " --libs print linked libraries" 16 | echo " --libmruby-path print libmruby path" 17 | exit 0;; 18 | esac 19 | shift 20 | done 21 | -------------------------------------------------------------------------------- /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/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/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 | -------------------------------------------------------------------------------- /example/limit_control/worker_rate_limit.rb: -------------------------------------------------------------------------------- 1 | # LoadModule mruby_module modules/mod_mruby.so 2 | # ExtendedStatus On 3 | # mrubyAccessCheckerMiddle /var/www/html/worker_rate_limit.rb 4 | 5 | class Worker 6 | def initialize 7 | @sb = Apache::Scoreboard.new() 8 | end 9 | def busyrate 10 | @sb.busy_worker / (@sb.server_limit * @sb.thread_limit) * 100 11 | end 12 | def accessrate 13 | @sb.total_access / @sb.uptime 14 | end 15 | end 16 | 17 | # busy worker thread rate is 90 and access per sec is 1000 18 | w = Worker.new() 19 | if w.busyrate > 90 20 | Apache.errlogger(4, "busy worker rate: " + busyrate.to_s) 21 | Apache::return(Apache::HTTP_SERVICE_UNAVAILABLE) 22 | elsif w.accessrate > 10000 23 | Apache.errlogger(4, "access per sec: " + accesspsec.to_s) 24 | Apache::return(Apache::HTTP_SERVICE_UNAVAILABLE) 25 | else 26 | Apache::return(Apache::DECLINED) 27 | end 28 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-compar-ext/mrblib/compar.rb: -------------------------------------------------------------------------------- 1 | module Comparable 2 | ## 3 | # Returns min if obj <=> min is less 4 | # than zero, max if obj <=> max is 5 | # greater than zero and obj otherwise. 6 | # 7 | # 12.clamp(0, 100) #=> 12 8 | # 523.clamp(0, 100) #=> 100 9 | # -3.123.clamp(0, 100) #=> 0 10 | # 11 | # 'd'.clamp('a', 'f') #=> 'd' 12 | # 'z'.clamp('a', 'f') #=> 'f' 13 | # 14 | def clamp(min, max) 15 | if (min <=> max) > 0 16 | raise ArgumentError, "min argument must be smaller than max argument" 17 | end 18 | c = self <=> min 19 | if c == 0 20 | return self 21 | elsif c < 0 22 | return min 23 | end 24 | c = self <=> max 25 | if c > 0 26 | return max 27 | else 28 | return self 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /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(s) 7 | case RbConfig::CONFIG['host_os'] 8 | when /mswin(?!ce)|mingw|bccwin/ 9 | "bin\\#{s}.exe" 10 | else 11 | "bin/#{s}" 12 | end 13 | end 14 | 15 | def shellquote(s) 16 | case RbConfig::CONFIG['host_os'] 17 | when /mswin(?!ce)|mingw|bccwin/ 18 | "\"#{s}\"" 19 | else 20 | "'#{s}'" 21 | end 22 | end 23 | 24 | print "bintest - Command Binary Test\n\n" 25 | 26 | ARGV.each do |gem| 27 | case gem 28 | when '-v'; $mrbtest_verbose = true 29 | end 30 | 31 | case RbConfig::CONFIG['host_os'] 32 | when /mswin(?!ce)|mingw|bccwin/ 33 | gem = gem.gsub('\\', '/') 34 | end 35 | 36 | Dir["#{gem}/bintest/**/*.rb"].each do |file| 37 | GEMNAME.replace(File.basename(gem)) 38 | load file 39 | end 40 | end 41 | 42 | exit report 43 | -------------------------------------------------------------------------------- /mruby_test/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/mrbgems/mruby-compar-ext/mrblib/compar.rb: -------------------------------------------------------------------------------- 1 | module Comparable 2 | ## 3 | # Returns min if obj <=> min is less 4 | # than zero, max if obj <=> max is 5 | # greater than zero and obj otherwise. 6 | # 7 | # 12.clamp(0, 100) #=> 12 8 | # 523.clamp(0, 100) #=> 100 9 | # -3.123.clamp(0, 100) #=> 0 10 | # 11 | # 'd'.clamp('a', 'f') #=> 'd' 12 | # 'z'.clamp('a', 'f') #=> 'f' 13 | # 14 | def clamp(min, max) 15 | if (min <=> max) > 0 16 | raise ArgumentError, "min argument must be smaller than max argument" 17 | end 18 | c = self <=> min 19 | if c == 0 20 | return self 21 | elsif c < 0 22 | return min 23 | end 24 | c = self <=> max 25 | if c > 0 26 | return max 27 | else 28 | return self 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /mruby_test/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(s) 7 | case RbConfig::CONFIG['host_os'] 8 | when /mswin(?!ce)|mingw|bccwin/ 9 | "bin\\#{s}.exe" 10 | else 11 | "bin/#{s}" 12 | end 13 | end 14 | 15 | def shellquote(s) 16 | case RbConfig::CONFIG['host_os'] 17 | when /mswin(?!ce)|mingw|bccwin/ 18 | "\"#{s}\"" 19 | else 20 | "'#{s}'" 21 | end 22 | end 23 | 24 | print "bintest - Command Binary Test\n\n" 25 | 26 | ARGV.each do |gem| 27 | case gem 28 | when '-v'; $mrbtest_verbose = true 29 | end 30 | 31 | case RbConfig::CONFIG['host_os'] 32 | when /mswin(?!ce)|mingw|bccwin/ 33 | gem = gem.gsub('\\', '/') 34 | end 35 | 36 | Dir["#{gem}/bintest/**/*.rb"].each do |file| 37 | GEMNAME.replace(File.basename(gem)) 38 | load file 39 | end 40 | end 41 | 42 | exit report 43 | -------------------------------------------------------------------------------- /update-mruby-subtree: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | update_subtree() { 4 | git remote | grep ${REMOTE_REPO_NAME} > /dev/null 5 | if [ $? -ne 0 ]; then 6 | echo "Missing remote repository ${REMOTE_REPO_NAME}" 7 | echo -n "Do you want to add (y/n)? " 8 | read answer 9 | if [ X$answer == "Xy" -o X$answer == "XY" ]; then 10 | git remote add ${REMOTE_REPO_NAME} ${REMOTE_REPO_URL} 11 | echo "Added ${REMOTE_REPO_URL} as ${REMOTE_REPO_NAME}." 12 | else 13 | echo "Aborted." 14 | exit 1 15 | fi 16 | fi 17 | 18 | git subtree pull --prefix=${SUBTREE_DIR} --squash ${REMOTE_REPO_NAME} master 19 | } 20 | 21 | REMOTE_REPO_NAME=dep-mruby 22 | REMOTE_REPO_URL=https://github.com/mruby/mruby.git 23 | SUBTREE_DIR=mruby 24 | 25 | update_subtree 26 | 27 | REMOTE_REPO_NAME=dep-mruby-test 28 | REMOTE_REPO_URL=https://github.com/mruby/mruby.git 29 | SUBTREE_DIR=mruby_test 30 | 31 | update_subtree 32 | 33 | exit 0 34 | 35 | -------------------------------------------------------------------------------- /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_test/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/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/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_test/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_test/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 | -------------------------------------------------------------------------------- /webif/README.md: -------------------------------------------------------------------------------- 1 | # Apache HTTP Server Status Realtime Moniter by mod_mruby 2 | Implemented in ApacheCon NA 2013 Hackathon 3 | ## Author 4 | - MATSUMOTO Ryosuke 5 | - TSUZAKI Yoshiharu 6 | - OKAMOTO Hiroki 7 | 8 | ## Install 9 | ### Install mod_mruby 10 | 11 | see [mod_mruby](https://github.com/matsumoto-r/mod_mruby). 12 | 13 | ### httpd.conf 14 | LoadModule mruby_module modules/mod_mruby.so 15 | mrubyTranslateNameFirst "/tmp/api_request.rb" 16 | 17 | ### file setteing 18 | git clone git://github.com/matsumoto-r/mod_mruby_hackathon.git 19 | cp api/api_request.rb /tmp/. 20 | touch #{document_root}/dummy 21 | 22 | ## Start 23 | cd interface 24 | node app.js 25 | 26 | ## Access 27 | http://127.0.0.1:3000/ 28 | 29 | ## Sample 30 | ![sample_display](https://raw.github.com/matsumoto-r/mod_mruby_hackathon/master/interface/views/sample_image.jpeg) 31 | 32 | ## License 33 | under the MIT License: 34 | 35 | * http://www.opensource.org/licenses/mit-license.php 36 | 37 | -------------------------------------------------------------------------------- /lib/hello/hello.c: -------------------------------------------------------------------------------- 1 | /* 2 | // hello.c - hello name class for mod_mruby 3 | // 4 | // See Copyright Notice in mod_mruby.h 5 | */ 6 | 7 | #include "mod_mruby.h" 8 | #include "ap_mrb_request.h" 9 | 10 | #ifdef ENABLE_HELLO 11 | 12 | mrb_value ap_mrb_hello_name(mrb_state *mrb, mrb_value self) 13 | { 14 | mrb_value name; 15 | request_rec *r = ap_mrb_get_request(); 16 | 17 | mrb_get_args(mrb, "o", &name); 18 | char *hello_string = apr_psprintf(r->pool, "hello %s-san", RSTRING_PTR(name)); 19 | 20 | return mrb_str_new2(mrb, hello_string); 21 | } 22 | 23 | // Add init function to ap_mruby_ext_calss_init() in ap_mrb_init.c 24 | // and prototype to ap_mrb_init.c 25 | void ap_mruby_hello_init(mrb_state *mrb, struct RClass *class_core) 26 | { 27 | struct RClass *class_hello; 28 | 29 | class_hello = mrb_define_class_under(mrb, class_core, "Hello", mrb->object_class); 30 | mrb_define_method(mrb, class_hello, "hello", ap_mrb_hello_name, ARGS_ANY()); 31 | } 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /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_test/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/src/crc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** crc.c - calculate CRC 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | /* Calculate CRC (CRC-16-CCITT) 12 | ** 13 | ** 0000_0000_0000_0000_0000_0000_0000_0000 14 | ** ^|------- CRC -------|- work --| 15 | ** carry 16 | */ 17 | #define CRC_16_CCITT 0x11021ul /* x^16+x^12+x^5+1 */ 18 | #define CRC_XOR_PATTERN (CRC_16_CCITT << 8) 19 | #define CRC_CARRY_BIT (0x01000000) 20 | 21 | uint16_t 22 | calc_crc_16_ccitt(const uint8_t *src, size_t nbytes, uint16_t crc) 23 | { 24 | size_t ibyte; 25 | uint32_t ibit; 26 | uint32_t crcwk = crc << 8; 27 | 28 | for (ibyte = 0; ibyte < nbytes; ibyte++) { 29 | crcwk |= *src++; 30 | for (ibit = 0; ibit < CHAR_BIT; ibit++) { 31 | crcwk <<= 1; 32 | if (crcwk & CRC_CARRY_BIT) { 33 | crcwk ^= CRC_XOR_PATTERN; 34 | } 35 | } 36 | } 37 | return (uint16_t)(crcwk >> 8); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /mruby_test/src/crc.c: -------------------------------------------------------------------------------- 1 | /* 2 | ** crc.c - calculate CRC 3 | ** 4 | ** See Copyright Notice in mruby.h 5 | */ 6 | 7 | #include 8 | #include 9 | #include 10 | 11 | /* Calculate CRC (CRC-16-CCITT) 12 | ** 13 | ** 0000_0000_0000_0000_0000_0000_0000_0000 14 | ** ^|------- CRC -------|- work --| 15 | ** carry 16 | */ 17 | #define CRC_16_CCITT 0x11021ul /* x^16+x^12+x^5+1 */ 18 | #define CRC_XOR_PATTERN (CRC_16_CCITT << 8) 19 | #define CRC_CARRY_BIT (0x01000000) 20 | 21 | uint16_t 22 | calc_crc_16_ccitt(const uint8_t *src, size_t nbytes, uint16_t crc) 23 | { 24 | size_t ibyte; 25 | uint32_t ibit; 26 | uint32_t crcwk = crc << 8; 27 | 28 | for (ibyte = 0; ibyte < nbytes; ibyte++) { 29 | crcwk |= *src++; 30 | for (ibit = 0; ibit < CHAR_BIT; ibit++) { 31 | crcwk <<= 1; 32 | if (crcwk & CRC_CARRY_BIT) { 33 | crcwk ^= CRC_XOR_PATTERN; 34 | } 35 | } 36 | } 37 | return (uint16_t)(crcwk >> 8); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-mirb/bintest/mirb.rb: -------------------------------------------------------------------------------- 1 | require 'open3' 2 | 3 | assert('mirb normal operations') do 4 | o, s = Open3.capture2('bin/mirb', :stdin_data => "a=1\nb=2\na+b\n") 5 | assert_true o.include?('=> 3') 6 | assert_true o.include?('=> 2') 7 | end 8 | 9 | assert('regression for #1563') do 10 | o, s = Open3.capture2('bin/mirb', :stdin_data => "a=1;b=2;c=3\nb\nc") 11 | assert_true o.include?('=> 3') 12 | end 13 | 14 | assert('mirb -d option') do 15 | o, _ = Open3.capture2('bin/mirb', :stdin_data => "$DEBUG\n") 16 | assert_true o.include?('=> false') 17 | o, _ = Open3.capture2('bin/mirb -d', :stdin_data => "$DEBUG\n") 18 | assert_true o.include?('=> true') 19 | end 20 | 21 | assert('mirb -r option') do 22 | lib = Tempfile.new('lib.rb') 23 | lib.write < "Hoge.new.hoge\n") 33 | assert_true o.include?('=> :hoge') 34 | end 35 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-bin-mirb/bintest/mirb.rb: -------------------------------------------------------------------------------- 1 | require 'open3' 2 | 3 | assert('mirb normal operations') do 4 | o, s = Open3.capture2('bin/mirb', :stdin_data => "a=1\nb=2\na+b\n") 5 | assert_true o.include?('=> 3') 6 | assert_true o.include?('=> 2') 7 | end 8 | 9 | assert('regression for #1563') do 10 | o, s = Open3.capture2('bin/mirb', :stdin_data => "a=1;b=2;c=3\nb\nc") 11 | assert_true o.include?('=> 3') 12 | end 13 | 14 | assert('mirb -d option') do 15 | o, _ = Open3.capture2('bin/mirb', :stdin_data => "$DEBUG\n") 16 | assert_true o.include?('=> false') 17 | o, _ = Open3.capture2('bin/mirb -d', :stdin_data => "$DEBUG\n") 18 | assert_true o.include?('=> true') 19 | end 20 | 21 | assert('mirb -r option') do 22 | lib = Tempfile.new('lib.rb') 23 | lib.write < "Hoge.new.hoge\n") 33 | assert_true o.include?('=> :hoge') 34 | end 35 | -------------------------------------------------------------------------------- /mruby/travis_config.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new('full-debug') do |conf| 2 | toolchain :gcc 3 | enable_debug 4 | 5 | # include all core GEMs 6 | conf.gembox 'full-core' 7 | conf.cc.flags += %w(-Werror=declaration-after-statement) 8 | conf.cc.defines += %w(MRB_GC_STRESS MRB_METHOD_CACHE MRB_ENABLE_DEBUG_HOOK) 9 | 10 | conf.enable_test 11 | end 12 | 13 | MRuby::Build.new do |conf| 14 | toolchain :gcc 15 | 16 | # include all core GEMs 17 | conf.gembox 'full-core' 18 | conf.cc.flags += %w(-Werror=declaration-after-statement) 19 | conf.compilers.each do |c| 20 | c.defines += %w(MRB_GC_FIXED_ARENA) 21 | end 22 | conf.enable_bintest 23 | conf.enable_test 24 | end 25 | 26 | MRuby::Build.new('cxx_abi') do |conf| 27 | toolchain :gcc 28 | 29 | conf.gembox 'full-core' 30 | conf.cc.flags += %w(-fpermissive) 31 | conf.compilers.each do |c| 32 | c.defines += %w(MRB_GC_FIXED_ARENA) 33 | end 34 | conf.enable_bintest 35 | conf.enable_test 36 | 37 | enable_cxx_abi 38 | 39 | build_mrbc_exec 40 | end 41 | -------------------------------------------------------------------------------- /mruby_test/travis_config.rb: -------------------------------------------------------------------------------- 1 | MRuby::Build.new('full-debug') do |conf| 2 | toolchain :gcc 3 | enable_debug 4 | 5 | # include all core GEMs 6 | conf.gembox 'full-core' 7 | conf.cc.flags += %w(-Werror=declaration-after-statement) 8 | conf.cc.defines += %w(MRB_GC_STRESS MRB_METHOD_CACHE MRB_ENABLE_DEBUG_HOOK) 9 | 10 | conf.enable_test 11 | end 12 | 13 | MRuby::Build.new do |conf| 14 | toolchain :gcc 15 | 16 | # include all core GEMs 17 | conf.gembox 'full-core' 18 | conf.cc.flags += %w(-Werror=declaration-after-statement) 19 | conf.compilers.each do |c| 20 | c.defines += %w(MRB_GC_FIXED_ARENA) 21 | end 22 | conf.enable_bintest 23 | conf.enable_test 24 | end 25 | 26 | MRuby::Build.new('cxx_abi') do |conf| 27 | toolchain :gcc 28 | 29 | conf.gembox 'full-core' 30 | conf.cc.flags += %w(-fpermissive) 31 | conf.compilers.each do |c| 32 | c.defines += %w(MRB_GC_FIXED_ARENA) 33 | end 34 | conf.enable_bintest 35 | conf.enable_test 36 | 37 | enable_cxx_abi 38 | 39 | build_mrbc_exec 40 | end 41 | -------------------------------------------------------------------------------- /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/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_test/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/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 | # internal method for inspect 43 | def _inspect(_recur_list) 44 | self.inspect 45 | end 46 | 47 | def to_enum(*a) 48 | raise NotImplementedError.new("fiber required for enumerator") 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /mruby_test/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_test/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 | # internal method for inspect 43 | def _inspect(_recur_list) 44 | self.inspect 45 | end 46 | 47 | def to_enum(*a) 48 | raise NotImplementedError.new("fiber required for enumerator") 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-bin-config/mrbgem.rake: -------------------------------------------------------------------------------- 1 | unless MRuby::Build.current.kind_of?(MRuby::CrossBuild) 2 | MRuby::Gem::Specification.new('mruby-bin-config') do |spec| 3 | name = 'mruby-config' 4 | spec.license = 'MIT' 5 | spec.author = 'mruby developers' 6 | spec.summary = "#{name} command" 7 | 8 | mruby_config_dir = "#{build.build_dir}/bin" 9 | mruby_config = name + (ENV['OS'] == 'Windows_NT' ? '.bat' : '') 10 | mruby_config_path = "#{mruby_config_dir}/#{mruby_config}" 11 | make_cfg = "#{build.build_dir}/lib/libmruby.flags.mak" 12 | tmplt_path = "#{__dir__}/#{mruby_config}" 13 | build.bins << mruby_config 14 | 15 | directory mruby_config_dir 16 | 17 | file mruby_config_path => [mruby_config_dir, make_cfg, tmplt_path] do |t| 18 | config = Hash[File.readlines(make_cfg).map!(&:chomp).map! {|l| 19 | l.gsub('\\"', '"').split(' = ', 2).map! {|s| s.sub(/^(?=.)/, 'echo ')} 20 | }] 21 | tmplt = File.read(tmplt_path) 22 | File.write(t.name, tmplt.gsub(/(#{Regexp.union(*config.keys)})\b/, config)) 23 | chmod(0755, t.name) 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-string-ext/test/numeric.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | assert('Integer#chr') do 4 | assert_equal("A", 65.chr) 5 | assert_equal("B", 0x42.chr) 6 | assert_equal("\xab", 171.chr) 7 | assert_raise(RangeError) { -1.chr } 8 | assert_raise(RangeError) { 256.chr } 9 | 10 | assert_equal("A", 65.chr("ASCII-8BIT")) 11 | assert_equal("B", 0x42.chr("BINARY")) 12 | assert_equal("\xab", 171.chr("ascii-8bit")) 13 | assert_raise(RangeError) { -1.chr("binary") } 14 | assert_raise(RangeError) { 256.chr("Ascii-8bit") } 15 | assert_raise(ArgumentError) { 65.chr("ASCII") } 16 | assert_raise(ArgumentError) { 65.chr("ASCII-8BIT", 2) } 17 | assert_raise(TypeError) { 65.chr(:BINARY) } 18 | 19 | if __ENCODING__ == "ASCII-8BIT" 20 | assert_raise(ArgumentError) { 65.chr("UTF-8") } 21 | else 22 | assert_equal("A", 65.chr("UTF-8")) 23 | assert_equal("B", 0x42.chr("UTF-8")) 24 | assert_equal("«", 171.chr("utf-8")) 25 | assert_equal("あ", 12354.chr("Utf-8")) 26 | assert_raise(RangeError) { -1.chr("utf-8") } 27 | assert_raise(RangeError) { 0x110000.chr.chr("UTF-8") } 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-bin-config/mrbgem.rake: -------------------------------------------------------------------------------- 1 | unless MRuby::Build.current.kind_of?(MRuby::CrossBuild) 2 | MRuby::Gem::Specification.new('mruby-bin-config') do |spec| 3 | name = 'mruby-config' 4 | spec.license = 'MIT' 5 | spec.author = 'mruby developers' 6 | spec.summary = "#{name} command" 7 | 8 | mruby_config_dir = "#{build.build_dir}/bin" 9 | mruby_config = name + (ENV['OS'] == 'Windows_NT' ? '.bat' : '') 10 | mruby_config_path = "#{mruby_config_dir}/#{mruby_config}" 11 | make_cfg = "#{build.build_dir}/lib/libmruby.flags.mak" 12 | tmplt_path = "#{__dir__}/#{mruby_config}" 13 | build.bins << mruby_config 14 | 15 | directory mruby_config_dir 16 | 17 | file mruby_config_path => [mruby_config_dir, make_cfg, tmplt_path] do |t| 18 | config = Hash[File.readlines(make_cfg).map!(&:chomp).map! {|l| 19 | l.gsub('\\"', '"').split(' = ', 2).map! {|s| s.sub(/^(?=.)/, 'echo ')} 20 | }] 21 | tmplt = File.read(tmplt_path) 22 | File.write(t.name, tmplt.gsub(/(#{Regexp.union(*config.keys)})\b/, config)) 23 | chmod(0755, t.name) 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-string-ext/test/numeric.rb: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | 3 | assert('Integer#chr') do 4 | assert_equal("A", 65.chr) 5 | assert_equal("B", 0x42.chr) 6 | assert_equal("\xab", 171.chr) 7 | assert_raise(RangeError) { -1.chr } 8 | assert_raise(RangeError) { 256.chr } 9 | 10 | assert_equal("A", 65.chr("ASCII-8BIT")) 11 | assert_equal("B", 0x42.chr("BINARY")) 12 | assert_equal("\xab", 171.chr("ascii-8bit")) 13 | assert_raise(RangeError) { -1.chr("binary") } 14 | assert_raise(RangeError) { 256.chr("Ascii-8bit") } 15 | assert_raise(ArgumentError) { 65.chr("ASCII") } 16 | assert_raise(ArgumentError) { 65.chr("ASCII-8BIT", 2) } 17 | assert_raise(TypeError) { 65.chr(:BINARY) } 18 | 19 | if __ENCODING__ == "ASCII-8BIT" 20 | assert_raise(ArgumentError) { 65.chr("UTF-8") } 21 | else 22 | assert_equal("A", 65.chr("UTF-8")) 23 | assert_equal("B", 0x42.chr("UTF-8")) 24 | assert_equal("«", 171.chr("utf-8")) 25 | assert_equal("あ", 12354.chr("Utf-8")) 26 | assert_raise(RangeError) { -1.chr("utf-8") } 27 | assert_raise(RangeError) { 0x110000.chr.chr("UTF-8") } 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /MITL: -------------------------------------------------------------------------------- 1 | Copyright (c) 2014 mod_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/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020 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 | 21 | -------------------------------------------------------------------------------- /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_test/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2020 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 | 21 | -------------------------------------------------------------------------------- /mruby_test/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-bin-config/mruby-config.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :top 4 | shift 5 | if "%0" equ "" goto :eof 6 | if "%0" equ "--cflags" goto cflags 7 | if "%0" equ "--ldflags" goto ldflags 8 | if "%0" equ "--ldflags-before-libs" goto ldflagsbeforelibs 9 | if "%0" equ "--libs" goto libs 10 | if "%0" equ "--libmruby-path" goto libmrubypath 11 | if "%0" equ "--help" goto showhelp 12 | echo Invalid Option 13 | goto :eof 14 | 15 | :cflags 16 | echo MRUBY_CFLAGS 17 | goto top 18 | 19 | :libs 20 | echo MRUBY_LIBS 21 | goto top 22 | 23 | :ldflags 24 | echo MRUBY_LDFLAGS 25 | goto top 26 | 27 | :ldflagsbeforelibs 28 | echo MRUBY_LDFLAGS_BEFORE_LIBS 29 | goto top 30 | 31 | :libmrubypath 32 | echo MRUBY_LIBMRUBY_PATH 33 | goto top 34 | 35 | :showhelp 36 | echo Usage: mruby-config [switches] 37 | echo switches: 38 | echo --cflags print flags passed to compiler 39 | echo --ldflags print flags passed to linker 40 | echo --ldflags-before-libs print flags passed to linker before linked libraries 41 | echo --libs print linked libraries 42 | echo --libmruby-path print libmruby path 43 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-socket/test/ipsocket.rb: -------------------------------------------------------------------------------- 1 | unless SocketTest.win? 2 | 3 | # Note: most of tests below will fail if UDPSocket is broken. 4 | 5 | assert('IPSocket.getaddress') do 6 | l = IPSocket.getaddress("localhost") 7 | assert_true (l == "127.0.0.1" or l == "::1") 8 | end 9 | 10 | assert('IPSocket.addr') do 11 | localhost = "127.0.0.1" 12 | s = UDPSocket.new 13 | s.bind(localhost, 0) 14 | port = Addrinfo.new(s.getsockname).ip_port 15 | 16 | a = s.addr 17 | assert_equal "AF_INET", a[0] 18 | assert_equal port, a[1] 19 | assert_equal localhost, a[2] 20 | assert_equal localhost, a[3] 21 | s.close 22 | true 23 | end 24 | 25 | assert('IPSocket.peeraddr') do 26 | localhost = "127.0.0.1" 27 | server = UDPSocket.new 28 | server.bind(localhost, 0) 29 | port = server.local_address.ip_port 30 | 31 | client = UDPSocket.new 32 | client.connect(localhost, port) 33 | 34 | a = client.peeraddr 35 | assert_equal "AF_INET", a[0] 36 | assert_equal port, a[1] 37 | assert_equal localhost, a[2] 38 | assert_equal localhost, a[3] 39 | client.close 40 | server.close 41 | true 42 | end 43 | 44 | end # win? 45 | -------------------------------------------------------------------------------- /mruby/mrbgems/mruby-print/mrblib/print.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # Kernel 3 | # 4 | # ISO 15.3.1 5 | module Kernel 6 | ## 7 | # Invoke method +print+ on STDOUT and passing +*args+ 8 | # 9 | # ISO 15.3.1.2.10 10 | def print(*args) 11 | i = 0 12 | len = args.size 13 | while i < len 14 | __printstr__ args[i].to_s 15 | i += 1 16 | end 17 | end 18 | 19 | ## 20 | # Invoke method +puts+ on STDOUT and passing +*args*+ 21 | # 22 | # ISO 15.3.1.2.11 23 | def puts(*args) 24 | i = 0 25 | len = args.size 26 | while i < len 27 | s = args[i].to_s 28 | __printstr__ s 29 | __printstr__ "\n" if (s[-1] != "\n") 30 | i += 1 31 | end 32 | __printstr__ "\n" if len == 0 33 | nil 34 | end 35 | 36 | ## 37 | # Print human readable object description 38 | # 39 | # ISO 15.3.1.3.34 40 | def p(*args) 41 | i = 0 42 | len = args.size 43 | while i < len 44 | __printstr__ args[i].inspect 45 | __printstr__ "\n" 46 | i += 1 47 | end 48 | args.__svalue 49 | end 50 | 51 | def printf(*args) 52 | __printstr__(sprintf(*args)) 53 | nil 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-bin-config/mruby-config.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :top 4 | shift 5 | if "%0" equ "" goto :eof 6 | if "%0" equ "--cflags" goto cflags 7 | if "%0" equ "--ldflags" goto ldflags 8 | if "%0" equ "--ldflags-before-libs" goto ldflagsbeforelibs 9 | if "%0" equ "--libs" goto libs 10 | if "%0" equ "--libmruby-path" goto libmrubypath 11 | if "%0" equ "--help" goto showhelp 12 | echo Invalid Option 13 | goto :eof 14 | 15 | :cflags 16 | echo MRUBY_CFLAGS 17 | goto top 18 | 19 | :libs 20 | echo MRUBY_LIBS 21 | goto top 22 | 23 | :ldflags 24 | echo MRUBY_LDFLAGS 25 | goto top 26 | 27 | :ldflagsbeforelibs 28 | echo MRUBY_LDFLAGS_BEFORE_LIBS 29 | goto top 30 | 31 | :libmrubypath 32 | echo MRUBY_LIBMRUBY_PATH 33 | goto top 34 | 35 | :showhelp 36 | echo Usage: mruby-config [switches] 37 | echo switches: 38 | echo --cflags print flags passed to compiler 39 | echo --ldflags print flags passed to linker 40 | echo --ldflags-before-libs print flags passed to linker before linked libraries 41 | echo --libs print linked libraries 42 | echo --libmruby-path print libmruby path 43 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-socket/test/ipsocket.rb: -------------------------------------------------------------------------------- 1 | unless SocketTest.win? 2 | 3 | # Note: most of tests below will fail if UDPSocket is broken. 4 | 5 | assert('IPSocket.getaddress') do 6 | l = IPSocket.getaddress("localhost") 7 | assert_true (l == "127.0.0.1" or l == "::1") 8 | end 9 | 10 | assert('IPSocket.addr') do 11 | localhost = "127.0.0.1" 12 | s = UDPSocket.new 13 | s.bind(localhost, 0) 14 | port = Addrinfo.new(s.getsockname).ip_port 15 | 16 | a = s.addr 17 | assert_equal "AF_INET", a[0] 18 | assert_equal port, a[1] 19 | assert_equal localhost, a[2] 20 | assert_equal localhost, a[3] 21 | s.close 22 | true 23 | end 24 | 25 | assert('IPSocket.peeraddr') do 26 | localhost = "127.0.0.1" 27 | server = UDPSocket.new 28 | server.bind(localhost, 0) 29 | port = server.local_address.ip_port 30 | 31 | client = UDPSocket.new 32 | client.connect(localhost, port) 33 | 34 | a = client.peeraddr 35 | assert_equal "AF_INET", a[0] 36 | assert_equal port, a[1] 37 | assert_equal localhost, a[2] 38 | assert_equal localhost, a[3] 39 | client.close 40 | server.close 41 | true 42 | end 43 | 44 | end # win? 45 | -------------------------------------------------------------------------------- /mruby_test/mrbgems/mruby-print/mrblib/print.rb: -------------------------------------------------------------------------------- 1 | ## 2 | # Kernel 3 | # 4 | # ISO 15.3.1 5 | module Kernel 6 | ## 7 | # Invoke method +print+ on STDOUT and passing +*args+ 8 | # 9 | # ISO 15.3.1.2.10 10 | def print(*args) 11 | i = 0 12 | len = args.size 13 | while i < len 14 | __printstr__ args[i].to_s 15 | i += 1 16 | end 17 | end 18 | 19 | ## 20 | # Invoke method +puts+ on STDOUT and passing +*args*+ 21 | # 22 | # ISO 15.3.1.2.11 23 | def puts(*args) 24 | i = 0 25 | len = args.size 26 | while i < len 27 | s = args[i].to_s 28 | __printstr__ s 29 | __printstr__ "\n" if (s[-1] != "\n") 30 | i += 1 31 | end 32 | __printstr__ "\n" if len == 0 33 | nil 34 | end 35 | 36 | ## 37 | # Print human readable object description 38 | # 39 | # ISO 15.3.1.3.34 40 | def p(*args) 41 | i = 0 42 | len = args.size 43 | while i < len 44 | __printstr__ args[i].inspect 45 | __printstr__ "\n" 46 | i += 1 47 | end 48 | args.__svalue 49 | end 50 | 51 | def printf(*args) 52 | __printstr__(sprintf(*args)) 53 | nil 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /mruby/tasks/doc.rake: -------------------------------------------------------------------------------- 1 | desc 'generate document' 2 | task :doc => [:api_doc, :capi_doc] do 3 | 4 | end 5 | 6 | desc 'generate yard docs' 7 | task :api_doc do 8 | begin 9 | sh "mrbdoc" 10 | rescue 11 | puts "ERROR: To generate yard documentation, you should install yard-mruby gem." 12 | puts " $ gem install yard-mruby yard-coderay" 13 | end 14 | end 15 | 16 | desc 'generate doxygen docs' 17 | task :capi_doc do 18 | begin 19 | sh "doxygen Doxyfile" 20 | rescue 21 | puts "ERROR: To generate C API documents, you need Doxygen." 22 | puts " $ sudo apt-get install doxygen" 23 | end 24 | end 25 | 26 | desc 'clean all built docs' 27 | task :clean_api_doc do 28 | rm_rf 'doc/api' 29 | end 30 | 31 | desc 'clean all built docs' 32 | task :clean_capi_doc do 33 | rm_rf 'doc/capi' 34 | end 35 | 36 | desc 'clean all built docs' 37 | task :clean_doc => [:clean_api_doc, :clean_capi_doc] do 38 | end 39 | 40 | desc 'clean all built docs' 41 | task :view_api => [:api_doc] do 42 | sh 'xdg-open doc/api/index.html' 43 | end 44 | 45 | desc 'clean all built docs' 46 | task :view_capi => [:capi_doc] do 47 | sh 'xdg-open doc/capi/html/index.html' 48 | end 49 | --------------------------------------------------------------------------------