Class: InterfaceComposedOut

Inherits:
Object show all
Includes:
Interface
Defined in:
lib/white_gold/abi/interface/interface_composed_out.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Interface

abi_const_string_method_suffix, fiddle_type, packer_fiddle_type, parse_packer, parse_unpacker

Constructor Details

#initialize(packer, unpacker, fiddle_types) ⇒ InterfaceComposedOut



9
10
11
12
13
14
15
16
# File 'lib/white_gold/abi/interface/interface_composed_out.rb', line 9

def initialize packer, unpacker, fiddle_types
  @packer = packer
  @unpacker = unpacker
  # unpacking in block caller allows abi side to free memory on return eg. for strings passed by value

  @block_caller = Fiddle::Closure::BlockCaller.new(0, fiddle_types) do |*a|
    @unpacked = @unpacker.zip(a).map{ _1.call @host, _2 }
  end
end

Class Method Details

.from(packer, unpacker) ⇒ Object



4
5
6
# File 'lib/white_gold/abi/interface/interface_composed_out.rb', line 4

def self.from packer, unpacker
  self.new Interface.parse_packer(packer), unpacker.map{ Interface.parse_unpacker _1 }, unpacker.map{ Interface.fiddle_type _1 }
end

Instance Method Details

#call(host, name, *a) ⇒ Object

Works propertly only for single thread (like whole TGUI btw.)



19
20
21
22
23
24
25
26
27
# File 'lib/white_gold/abi/interface/interface_composed_out.rb', line 19

def call host, name, *a
  a = @packer.call host, *a if @packer
  @host = host
  host.send name, *a, @block_caller
  unpacked = @unpacked
  @unpacked = nil
  @host = nil
  unpacked
end