Class: Dub::Lua::NamespaceGen

Inherits:
Generator show all
Defined in:
lib/dub/lua/namespace_gen.rb

Instance Method Summary collapse

Methods inherited from Generator

#comment

Constructor Details

#initializeNamespaceGen

Returns a new instance of NamespaceGen.


7
8
9
# File 'lib/dub/lua/namespace_gen.rb', line 7

def initialize
  @namespace_template = ::ERB.new(File.read(File.join(File.dirname(__FILE__), 'namespace.cpp.erb')))
end

Instance Method Details

#class_generatorObject


16
17
18
# File 'lib/dub/lua/namespace_gen.rb', line 16

def class_generator
  Lua.class_generator
end

#constants_registration(namespace = @namespace) ⇒ Object


30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/dub/lua/namespace_gen.rb', line 30

def constants_registration(namespace = @namespace)
  res = []
  if namespace.has_enums?
    res << namespace.enums.map do |name|
      "{%-32s, #{namespace.full_type}::#{name}}" % name.inspect
    end.join(",\n")
  end

  if namespace.has_defines?
    res << namespace.defines.map do |name|
      "{%-32s, #{name}}" % name.inspect
    end.join(",\n")
  end

  same = namespace.enums & namespace.defines
  unless same.empty?
    # Should never happen (not sure if it would compile ok in the first place)
    puts "Warning: the following are present both as enum and define: #{same.inspect}"
  end
  res.join(",\n\n")
end

#function_generatorObject


20
21
22
# File 'lib/dub/lua/namespace_gen.rb', line 20

def function_generator
  Lua.function_generator
end

#functions_registration(namespace = @namespace) ⇒ Object


24
25
26
27
28
# File 'lib/dub/lua/namespace_gen.rb', line 24

def functions_registration(namespace = @namespace)
  (namespace.members || []).map do |method|
    "{%-32s, #{method.method_name(0)}}" % method.name.inspect
  end.join(",\n")
end

#members_list(all_members) ⇒ Object


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/dub/lua/namespace_gen.rb', line 52

def members_list(all_members)
  all_members
  #list = (all_members || []).map do |member_or_group|
  #  if member_or_group.kind_of?(Array)
  #    members_list(member_or_group)
  #  elsif ignore_member?(member_or_group)
  #    nil
  #  else
  #    member_or_group
  #  end
  #end
  #
  #list.compact!
  #list == [] ? nil : list
end

#namespace(namespace) ⇒ Object


11
12
13
14
# File 'lib/dub/lua/namespace_gen.rb', line 11

def namespace(namespace)
  @namespace = namespace
  @namespace_template.result(binding)
end