Interaction with C

object f64
    val min "DBL_MIN" : f64
    val max "DBL_MAX" : f64
    val epsilon "DBL_EPSILON" : f64

External constants DBL_MIN, DBL_MAX and DBL_EPSILON are represented as fields of the f64 object.

Types

type i32 @c
type c_char "char"

The @c attribute is required for types with a name equal to external.

type VkInstance = MutPtr
type CString = Ptr<c_char>

Named tuple with a single item is represented in C as the item itself, so VkInstance and CString can be used in definitions of external functions instead of void* and const char*.

typealias DebugUtilsMessengerCallbackExt = fn
    (message_severity : DebugUtilsMessageSeverityFlagsExt)
    * (message_types : DebugUtilsMessageTypeFlagsExt)
    * (callback_data : ptr DebugUtilsMessengerCallbackDataExt)
    * (user_data : MutPtr) -> u32

typealias CharFun = fn GlfwWindow * u32 -> Unit

Aliases for function pointer types.

type SampleCountFlags = flags
    | 1
    | 2
    | 4
    | 8
    | 16
    | 32
    | 64

Symbols of flags can be numbers or start from a digit.

type InstanceCreateInfo = struct
    type : StructureType
    next : Ptr
    flags : InstanceCreateFlags
    application_info : ptr ApplicationInfo
    enabled_layer_count : u32
    enabled_layer_names : ptr CString
    enabled_extension_count : u32
    enabled_extension_names : ptr CString

type ClearValue = union
    color : ClearColorValue
    depth_stencil : ClearDepthStencilValue

Structures and unions match corresponding C constructs.

Functions

module vk

def create_semaphore "vkCreateSemaphore"
    (device : VkDevice)
    (create_info : ptr SemaphoreCreateInfo)
    (allocator : Allocator)
    (semaphore : mut ptr VkSemaphore) : Result

endmodule

Library function vkCreateSemaphore is available under the name vk/create_semaphore.

def create_semaphore (device : VkDevice) =
    let semaphore_create_info = SemaphoreCreateInfo
        type = StructureType/SemaphoreCreateInfo
        next = null
        flags = SemaphoreCreateFlags@zero

    let mut semaphore = null
    vk/create_semaphore device semaphore_create_info@ptr null
                        semaphore@mut_ptr
    |> assert_success

    semaphore

Modifiers @ptr and @mut_ptr return a pointer to a value, @fn — pointer to a function, @zero — a block of zeroed memory.

type f32 @c =
    def sin "sinf" : f32
    def cos "cosf" : f32
    
type f64 @c =
    def sin @c : f64
    def cos @c : f64    

External function can also be a method.