class Candiru::Fn

Overview

Helps call C functions with IValues as arguments.

point_new_handle = loader.find_symbol("Point_New")
point_add_handle = loader.find_symbol("Point_Add")
point_see_handle = loader.find_symbol("Point_See")
point_free_handle = loader.find_symbol("Point_Free")

point_struct = StructScaffold[Float64, Float64]

point_new = Fn.new(point_new_handle, takes: [Float64, Float64], returns: point_struct)
point_add = Fn.new(point_add_handle, takes: [point_struct, point_struct], returns: point_struct)
point_see = Fn.new(point_see_handle, takes: [point_struct])
point_free = Fn.new(point_free_handle, takes: [point_struct])

a = point_new_fn.call(100f64, 200f64)
b = point_new_fn.call(200f64, 300f64)

# a : StructInstance
# b : StructInstance

point_see_fn.call(a)
point_see_fn.call(b)

c = point_add_fn.call(a, b)

point_see_fn.call(c)

point_free_fn.call(a)
point_free_fn.call(b)
point_free_fn.call(c)

Defined in:

candiru.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(handle : Pointer(Void), takes params = [] of IValueClassType, returns ret : IValueClassType | Nil = nil) #

Initializes a function given a dlopen handle, a type list of params it takes (each is IValueClassType), and the type of its return value, also an IValueClassType.


[View source]

Instance Method Detail

def call(args : Array(IValueInstanceType) = [] of IValueInstanceType) #

[View source]
def call(*args) #

[View source]