From a045b6b8d93f70d7bf57a94ed5c7e0432190d584 Mon Sep 17 00:00:00 2001 From: dearblue Date: Sat, 21 Nov 2020 10:17:27 +0900 Subject: Allow to mixed and specify `*.rb` and `*.mrb` in `bin/mruby` It is not decides by the extension. In order to be recognized as a `.mrb` file, the following three points must be satisfied: - File starts with "RITE" - At least `sizeof(struct rite_binary_header)` bytes can be read - `NUL` is included in the first 64 bytes of the file If these are not met, it is judged as a text file and it is processed as a Ruby script. The `bin/mruby -b` switch is still available which treats the given file as a `.mrb` file. New `MRB_API` function: - `include/mruby/compile.h` and `mrbgems/mruby-compiler/core/parse.y` - `mrb_load_detect_file_cxt()` (remove with `MRB_DISABLE_STDIO`) NOTE: - Even script files now always open in binary mode for `bin/mruby`. The `\r\n` is handled by the `nextc()` function already, so there is no problem even on Windows. - The `nextc0()` function in `mrbgems/mruby-compiler/core/parse.y` can now specify a string buffer and a file pointer at the same time. In this case, get it from the string buffer first. This patch includes modifies by comment of https://github.com/mruby/mruby/pull/5157. --- mrbgems/mruby-bin-mruby/bintest/mruby.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'mrbgems/mruby-bin-mruby/bintest/mruby.rb') diff --git a/mrbgems/mruby-bin-mruby/bintest/mruby.rb b/mrbgems/mruby-bin-mruby/bintest/mruby.rb index e8b4c6d0f..35a108a9d 100644 --- a/mrbgems/mruby-bin-mruby/bintest/mruby.rb +++ b/mrbgems/mruby-bin-mruby/bintest/mruby.rb @@ -19,7 +19,7 @@ assert('regression for #1572') do script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb') File.write script.path, 'p "ok"' system "#{cmd('mrbc')} -g -o #{bin.path} #{script.path}" - o = `#{cmd('mruby')} -b #{bin.path}`.strip + o = `#{cmd('mruby')} #{bin.path}`.strip assert_equal '"ok"', o end @@ -33,7 +33,7 @@ assert '$0 value' do # .mrb file `#{cmd('mrbc')} -o "#{bin.path}" "#{script.path}"` - assert_equal "\"#{bin.path}\"", `#{cmd('mruby')} -b "#{bin.path}"`.chomp + assert_equal "\"#{bin.path}\"", `#{cmd('mruby')} "#{bin.path}"`.chomp # one liner assert_equal '"-e"', `#{cmd('mruby')} -e #{shellquote('p $0')}`.chomp @@ -48,7 +48,7 @@ assert('float literal') do script, bin = Tempfile.new('test.rb'), Tempfile.new('test.mrb') File.write script.path, 'p [3.21, 2e308.infinite?, -2e308.infinite?]' system "#{cmd('mrbc')} -g -o #{bin.path} #{script.path}" - assert_equal "[3.21, 1, -1]", `#{cmd('mruby')} -b #{bin.path}`.chomp! + assert_equal "[3.21, 1, -1]", `#{cmd('mruby')} #{bin.path}`.chomp! end assert '__END__', '8.6' do -- cgit v1.2.3