Closed fab1an2 closed 2 years ago
There is no Regexp
in mruby itself.
However, if Regexp
is provided by a third party, there is a mechanism to include it at build time so that it can be used.
If you look at https://github.com/mruby/mgem-list, you will see multiple regular expression GEMs.
If you want to use a GEM that uses the onigmo library, which is a regular expression library used in CRuby, for example, put the following in your build configuration file.
# myconf.rb
MRuby::Build.new do |conf|
conf.toolchain
conf.gembox "default"
conf.gem mgem: "mruby-onig-regexp"
end
Build with this and you can use regular expressions.
% rake MRUBY_CONFIG=myconf.rb clean all
...snip...
% bin/mruby -e " puts 'test'.split(//).join('#') "
t#e#s#t
For most of the cases for embedded programming, we don't use Regexp, so it's intentionally optional. As @dearblue explained, link regexp mrbgem explicitly.
How I can init Regexp? This is normal default mruby 3.1.0 configuration without modifications.
I call from mruby
include <mruby/re.h>
.... wynik = mrb_funcall(mrb, mrb_top_self(mrb), "napis", 1, mrb_str_new_cstr(mrb, "żółw"));
I get empty string if (!mrb_undef_p(wynik)) { mrb_print_error(mrb); }
my mruby code