Class: MRubyTools
- Inherits:
-
Object
show all
- Defined in:
- lib/mruby_tools.rb
Defined Under Namespace
Modules: C, CLI
Classes: MRubyNotFound
Constant Summary
collapse
- MRUBY_DIR =
File.expand_path("../mruby", __dir__)
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(mruby_dir = nil) ⇒ MRubyTools
Returns a new instance of MRubyTools.
14
15
16
17
18
|
# File 'lib/mruby_tools.rb', line 14
def initialize(mruby_dir = nil)
@mruby_dir = mruby_dir || self.class.mruby_dir
@inc_path = File.join(@mruby_dir, 'include')
@ar_path = File.join(@mruby_dir, 'build', 'host', 'lib', 'libmruby.a')
end
|
Instance Attribute Details
#ar_path ⇒ Object
Returns the value of attribute ar_path.
12
13
14
|
# File 'lib/mruby_tools.rb', line 12
def ar_path
@ar_path
end
|
#inc_path ⇒ Object
Returns the value of attribute inc_path.
12
13
14
|
# File 'lib/mruby_tools.rb', line 12
def inc_path
@inc_path
end
|
#mruby_dir ⇒ Object
Returns the value of attribute mruby_dir.
12
13
14
|
# File 'lib/mruby_tools.rb', line 12
def mruby_dir
@mruby_dir
end
|
Class Method Details
.mruby_dir ⇒ Object
8
9
10
|
# File 'lib/mruby_tools.rb', line 8
def self.mruby_dir
ENV['MRUBY_DIR'] || MRUBY_DIR
end
|
Instance Method Details
#built? ⇒ Boolean
24
25
26
|
# File 'lib/mruby_tools.rb', line 24
def built?
File.readable?(@ar_path)
end
|
#compile(c_file, out_file) ⇒ Object
38
39
40
|
# File 'lib/mruby_tools.rb', line 38
def compile(c_file, out_file)
system('gcc', *self.gcc_args(c_file, out_file))
end
|
#gcc_args(c_file, out_file) ⇒ Object
34
35
36
|
# File 'lib/mruby_tools.rb', line 34
def gcc_args(c_file, out_file)
['-std=c99', "-I", @inc_path, c_file, "-o", out_file, @ar_path, '-lm']
end
|
#src? ⇒ Boolean
20
21
22
|
# File 'lib/mruby_tools.rb', line 20
def src?
File.directory?(@inc_path)
end
|
#validate! ⇒ Object
28
29
30
31
32
|
# File 'lib/mruby_tools.rb', line 28
def validate!
raise(MRubyNotFound, @inc_path) unless File.directory? @inc_path
raise(MRubyNotFound, @ar_path) unless File.readable? @ar_path
self
end
|