Search code examples
mruby

mruby-require error: NoMethodError: undefined method 'puts' for main


I managed to compile the mruby code adding the mrubygem - mruby-require from https://github.com/mattn/mruby-require

However when I try to call the require './' I get an error. Below is my code:

inc.rb

def test(a, b)
    print "Inside the include->test(..)"
    return a+b
end

test1.rb

require 'inc.rb'

def helloworld(var1)
    print 'hello world ' + var1 + ". Test number = " + test(4, 5)

end

helloworld('test')

When I execute test1.rb I get this error from mruby:

NoMethodError: undefined method 'puts' for main

After some analysis I found out the 'puts' is not working with mruby. Infact after adding mruby-require gem, no ruby code gets execute. Do I need to add any dependency with mruby-require?

Can someone help me please?

Update: Pasting the content of build_config.rb as requested. I have removed the lines which are commented.

build_config.rb

MRuby::Build.new do |conf|

  if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR']
    toolchain :visualcpp
  else
    toolchain :gcc
  end

  enable_debug

  # adding the mruby-require library
  conf.gem 'mrbgems/mruby-require'

  conf.gembox 'default'


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(ENABLE_DEBUG)


  conf.gem :core => "mruby-bin-debugger"


end

Solution

  • The following quote is from its README.md:

    When mruby-require is being used, additional mrbgems that appear after mruby-require in build_config.rb must be required to be used.

    This is from your build_config.rb:

      conf.gem 'mrbgems/mruby-require'
    
      conf.gembox 'default'
    

    The default gembox contains mruby-print. So either require mruby-print or preferably swap the lines to make it a built-in gem (the default behavior without mruby-require).