Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-base

Source of release 0.46.0

0.46.0 / src / std / interop / module.lucb

#==============================================================================================
#
#   interop - Explicit native ownership shared with managed consumers
#
#   DESCRIPTION:
#       Explicit native ownership shared with managed consumers. Package types remain
#       ordinary structs with init and methods; a Type declaration supplies their
#       disposal, trace and affinity contract. Reference values are manual in Base.
#
#==============================================================================================

import memory
import ownership
import thread
import sync
import time
## The carrier or its native value is not valid.
pub let invalid: ErrorCode = ErrorCode.package(101)
## The value was touched from a thread other than its owner.
pub let wrong_thread: ErrorCode = ErrorCode.package(102)
## The lease or scope backing the value has ended.
pub let expired: ErrorCode = ErrorCode.package(103)

## A package's constant declaration of native ownership. Dispose releases native
## resources and strong edges exactly once, including after an explicit close.
## A closeable export binds its public disposal method as the terminal operation.
pub struct Type[T]:
    ## The type's name.
    pub let name: str
    ## Releases the value's native resources and strong edges, exactly once.
    pub let dispose: func(T*) -> unit
    ## Visits the strong references the value holds, when it holds any.
    pub let trace: (func(const T*, func(ownership.Object*, void*) -> unit, void*) -> unit)? = none
    ## Whether the export binds a public disposal method as its terminal operation.
    pub let closeable: bool = false
    ## Whether the value must live on the process's main thread.
    pub let main_thread: bool = false