diff options
| author | dearblue <[email protected]> | 2020-11-21 10:17:27 +0900 |
|---|---|---|
| committer | dearblue <[email protected]> | 2020-11-21 19:05:46 +0900 |
| commit | a045b6b8d93f70d7bf57a94ed5c7e0432190d584 (patch) | |
| tree | 54bdd026a2fbf6d6c6b607086f505ac75fdae1df /include | |
| parent | 55e127577863e0f913a4b7b8653fcba577c29b86 (diff) | |
| download | mruby-a045b6b8d93f70d7bf57a94ed5c7e0432190d584.tar.gz mruby-a045b6b8d93f70d7bf57a94ed5c7e0432190d584.zip | |
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.
Diffstat (limited to 'include')
| -rw-r--r-- | include/mruby/compile.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/include/mruby/compile.h b/include/mruby/compile.h index 36adf5a32..ce874da6b 100644 --- a/include/mruby/compile.h +++ b/include/mruby/compile.h @@ -116,6 +116,7 @@ struct mrb_parser_state { mrb_ast_node *cells; const char *s, *send; #ifndef MRB_DISABLE_STDIO + /* If both f and s are non-null, it will be taken preferentially from s until s < send. */ FILE *f; #endif mrbc_context *cxt; @@ -193,6 +194,7 @@ MRB_API mrb_value mrb_load_exec(mrb_state *mrb, struct mrb_parser_state *p, mrbc #ifndef MRB_DISABLE_STDIO MRB_API mrb_value mrb_load_file(mrb_state*,FILE*); MRB_API mrb_value mrb_load_file_cxt(mrb_state*,FILE*, mrbc_context *cxt); +MRB_API mrb_value mrb_load_detect_file_cxt(mrb_state *mrb, FILE *fp, mrbc_context *c); #endif MRB_API mrb_value mrb_load_string(mrb_state *mrb, const char *s); MRB_API mrb_value mrb_load_nstring(mrb_state *mrb, const char *s, size_t len); |
