1

I use mruby 1.3.0 (2017-7-4) with build_config.rb:

MRuby::Build.new do |conf|
  if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
    toolchain :visualcpp
  else
    toolchain :gcc
  end
  enable_debug
  conf.gembox 'default'
  conf.gem :git => 'https://github.com/mattn/mruby-uv'
  conf.gem :git => 'https://github.com/mattn/mruby-http'
  conf.gem :git => 'https://github.com/iij/mruby-socket'
  conf.gem :git => 'https://github.com/luisbebop/mruby-polarssl.git'
  conf.gem :git => 'https://github.com/iij/mruby-digest'
  conf.gem :git => 'https://github.com/iij/mruby-pack'
  conf.gem :git => 'https://github.com/matsumoto-r/mruby-simplehttp.git'
  conf.gem :git => 'https://github.com/matsumotory/mruby-httprequest'
  conf.gem :git => 'https://github.com/iij/mruby-aws-s3.git'
end

MRuby::Build.new('host-debug') do |conf|
  if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
    toolchain :visualcpp
  else
      toolchain :gcc
  end

  enable_debug
  conf.gembox 'default'
  conf.cc.defines = %w(MRB_ENABLE_DEBUG_HOOK)
  conf.gem :core => "mruby-bin-debugger"
end

MRuby::Build.new('test') do |conf|
  if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
    toolchain :visualcpp
  else
    toolchain :gcc
  end
  enable_debug
  conf.enable_bintest
  conf.enable_test
  conf.gembox 'default'
end

I found const_get method different in mruby from in ruby. In ruby (2.4.0p0), Class.const_get('Fixnum') returns the constant Fixnum, while in mruby Class.const_get('Fixnum') results in error uninitialized constant Class::Fixnum (NameError).

Then, I tried another example: class Hoge; end; class Hoge::Fuga; end. In ruby, both Class.const_get('Hoge::Fuga') and Hoge.const_get('Fuga') give the constant Hoge::Fuga. In mruby, it is only Hoge.const_get('Fuga') that returns Hoge::Fuga.

naughie
  • 315
  • 2
  • 14
  • While I cannot explain to you how `const_get` works in `mruby` I actually prefer this methodology over the native ruby version. I am not very versed in C code (I know shame shame) but the direct answer to your question is [mruby `Module#const_get`](https://github.com/mruby/mruby/blob/master/src/class.c#L2296) and [ruby `Module#const_get`](https://github.com/ruby/ruby/blob/trunk/object.c#L2417) as you can see given that `mruby` is lightweight is has a lighter weight implementation as well – engineersmnky Dec 14 '17 at 14:22

1 Answers1

0

mruby's Module#const_get works like 2nd argument(which is named inherit to search for superclasses) false in CRuby. If you use Object.const_get(:Integer) instead it should behave the same as what you expected in both mruby and CRuby.

  • I overlooked the second argument of `Module#const_get`, and since `Module#const_get` in mruby takes only 1 argument, the only solution seems to be using `Object#const_get`. Thank you. – naughie Dec 19 '17 at 10:34