2

I am trying my hand on with mRuby. I compiled the mRuby source locally. I tried this simple example:

inc.rb

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

test1.rb

require_relative 'inc.rb'

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

end

helloworld('test')

test2.rb

require 'inc.rb'

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

end

helloworld('test')

I executed both the test programs using mruby. mruby.exe test1.rb mruby.exe test2.rb

In both the cases I get the error:

"undefined method 'require_relative' for main (NoMethodError)"

"undefined method 'require' for main (NoMethodError)"

Does mRuby not support 'require'?

programmer
  • 582
  • 2
  • 4
  • 16

1 Answers1

2

mruby doesn't have require functionality. But you can use mruby-require mgem. https://github.com/mattn/mruby-require If you build mruby with mruby-require, then you can use require. require_relative is not supported.

yasuyuki
  • 31
  • 4
  • how do I build mruby with mruby-require? – programmer Jun 15 '15 at 02:15
  • Just look "install by mrbgems" section of previous link. – yasuyuki Jun 17 '15 at 01:37
  • I got the the code to compile, thank you :). Now I have another issue. I am getting this error: NoMethodError: undefined method 'puts' for main Can you help me? This is the url: http://stackoverflow.com/questions/31140687/mruby-require-error-nomethoderror-undefined-method-puts-for-main – programmer Jun 30 '15 at 14:12