Class: RubyBindgen::Generators::Rice::FunctionPointer

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-bindgen/generators/rice/function_pointer.rb

Overview

Build the C++ pointer-to-function expression Rice needs to bind a method or free function. Most compilers can resolve ‘&Foo::bar` against the surrounding template-deduced signature even when `bar` is overloaded, but MSVC cannot, so when the name refers to an overload set we wrap the address in a `static_cast` whose target type is the signature:

non-overloaded:  &Foo::bar
overloaded MSVC: static_cast<void(int, float)>(&Foo::bar)

Class Method Summary collapse

Class Method Details

.format(cursor, qualified_name, signature) ⇒ Object

Returns the address-of expression for ‘cursor`, optionally wrapped in a disambiguating `static_cast`.



16
17
18
19
20
21
# File 'lib/ruby-bindgen/generators/rice/function_pointer.rb', line 16

def self.format(cursor, qualified_name, signature)
  reference = "&#{qualified_name}"
  return reference unless cast_required?(cursor, signature)
  
  "static_cast<#{signature[1...-1]}>(#{reference})"
end