Module: Neutron::Valac

Defined in:
lib/neutron/valac.rb

Class Method Summary collapse

Class Method Details

.compile(*files, **opts) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/neutron/valac.rb', line 4

def self.compile(*files, **opts)
  o = {
    prog: 'valac',
    debug: false,
    type: :object,
    gen_vapi: false,
    gen_header: false,
    args: ''
  }.merge(opts)

  specific = ''
  
  if o[:debug]
    specific << ' -g'
  end

  case o[:type]
  when :object
    specific << ' -c'
  when :ccode
    specific << ' -C'
  else
    raise TypeError, "Invalid output type: #{o[:type]}!"
  end

  files.each do |file|
    file = File.expand_path(file)

    iter_specific = ''
    
    if o[:gen_vapi]
      puts "Warning: this part of Neutron::Valac module is not finished. Use it at own risk!"
      iter_specific << " --vapi #{Neutron.file_to_ext(file, '.vapi')}"
    end

    if o[:gen_header]
      iter_specific << " --header #{Neutron.file_to_ext(file, '.h')}"
    end

    Neutron.execute("#{o[:prog]} #{file} #{specific} #{iter_specific} -b ./ --thread #{o[:args]}", must_success: true)
  end
end

.to_c(*files, **opts) ⇒ Object



47
48
49
50
51
52
# File 'lib/neutron/valac.rb', line 47

def self.to_c(*files, **opts)
  o = {
    proc: 'valac',
    args: ''
  }
end

.vapi_header(header) ⇒ Object



54
55
56
# File 'lib/neutron/valac.rb', line 54

def self.vapi_header(header)
  "[CCode (cheader_filename = \"#{header}\")]\n\n"
end