Class: SWIG::Context
- Inherits:
-
Object
show all
- Defined in:
- lib/crequire/swig.rb
Instance Method Summary
collapse
Constructor Details
#initialize(name) ⇒ Context
Returns a new instance of Context.
3
4
5
6
7
|
# File 'lib/crequire/swig.rb', line 3
def initialize(name)
@name = name
@functions = []
@pointers = []
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
|
# File 'lib/crequire/swig.rb', line 14
def method_missing(m, *args)
if args.size == 1 and args[0].class <= Function
func = args[0]
func.return = m
@functions << func
elsif args.size == 0
Unknown.new(m.to_s, self)
else
Function.new(m.to_s, args.map {|arg| arg.to_s})
end
end
|
Instance Method Details
#<<(input) ⇒ Object
26
27
28
29
|
# File 'lib/crequire/swig.rb', line 26
def <<(input)
@pointers << input if input.is_a? Pointer
@functions << input if input.is_a? Function
end
|
9
10
11
12
|
# File 'lib/crequire/swig.rb', line 9
def input(&block)
instance_eval &block
self
end
|
#interface ⇒ Object
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/crequire/swig.rb', line 35
def interface
output = "%module #{@name}\n"
if @pointers.size > 0
output << "%include \"cpointer.i\"\n" +
@pointers.map {|p| p.to_s}.join("\n")
end
output << "%{\n"
output << if @functions.size > 0
@functions.map {|f| f.to_s}.join("\n")
else
"#include \"#{@name}.h\""
end
output << "\n%}\n"
output << if @functions.size > 0
@functions.map {|f| f.to_swig_s}.join("\n")
else
"%include \"#{@name}.h\""
end
end
|
#pointer(p, name = nil) ⇒ Object
31
32
33
|
# File 'lib/crequire/swig.rb', line 31
def pointer(p, name = nil)
@pointers << Pointer.new(p, name)
end
|