All built-in functions available in Osprey.

Channel #

Signature: Channel(capacity: int) -> Channel

Creates a new channel with the specified capacity.

List #

Signature: List() -> List<T>

Creates a new empty list.

Map #

Signature: Map() -> Map<K, V>

Creates a new empty map.

awaitProcess #

Signature: awaitProcess(handle: int) -> int

Waits for a spawned process to complete and returns its exit code. Blocks until the process finishes.

cleanupProcess #

Signature: cleanupProcess(handle: int) -> Unit

Cleans up resources associated with a completed process. Should be called after awaitProcess.

contains #

Signature: contains(haystack: string, needle: string) -> bool

Checks if a string contains a substring.

fiber_await #

Signature: fiber_await(fiber: Fiber) -> any

Waits for a fiber to complete and returns its result.

fiber_spawn #

Signature: fiber_spawn(fn: () -> any) -> Fiber

Spawns a new fiber to execute the given function concurrently.

fiber_yield #

Signature: fiber_yield(value: any) -> any

Yields control to the fiber scheduler with an optional value.

filter #

Signature: filter(iterator: iterator, predicate: function) -> iterator

Filters elements in an iterator based on a predicate function.

fold #

Signature: fold(iterator: Iterator<T>, initial: U, function: (U, T) -> U) -> U

Reduces an iterator to a single value by repeatedly applying a function.

forEach #

Signature: forEach(iterator: iterator, function: function) -> int

Applies a function to each element in an iterator.

httpCloseClient #

Signature: httpCloseClient(clientID: int) -> int

Closes the HTTP client and cleans up resources.

httpCreateClient #

Signature: httpCreateClient(base_url: string, timeout: int) -> int

Creates an HTTP client for making requests to a base URL.

httpCreateServer #

Signature: httpCreateServer(port: int, address: string) -> int

Creates an HTTP server bound to the specified port and address.

httpDelete #

Signature: httpDelete(clientID: int, path: string, headers: string) -> int

Makes an HTTP DELETE request to the specified path.

httpGet #

Signature: httpGet(clientID: int, path: string, headers: string) -> int

Makes an HTTP GET request to the specified path.

httpListen #

Signature: httpListen(serverID: int, handler: (string, string, string, string) -> HttpResponse) -> int

Starts the HTTP server listening for requests with a handler function.

httpPost #

Signature: httpPost(clientID: int, path: string, body: string, headers: string) -> int

Makes an HTTP POST request with a request body.

httpPut #

Signature: httpPut(clientID: int, path: string, body: string, headers: string) -> int

Makes an HTTP PUT request with a request body.

httpRequest #

Signature: httpRequest(clientID: int, method: int, path: string, headers: string, body: string) -> int

Makes a generic HTTP request with any method.

httpStopServer #

Signature: httpStopServer(serverID: int) -> int

Stops the HTTP server and closes all connections.

input #

Signature: input() -> Result<string, Error>

Reads a string from the user’s input.

join #

Signature: join(list: list<string>, separator: string) -> string

Joins a list of strings with a separator.

length #

Signature: length(text: string) -> int

Returns the length of a string.

map #

Signature: map(iterator: iterator, fn: function) -> iterator

Transforms each element in an iterator using a function, returning a new iterator.

parseInt #

Signature: parseInt(s: string) -> Result<int, string>

Parses a string to an integer, returns error if parsing fails.

print #

Signature: print(value: any) -> Unit

Prints a value to the console. Automatically converts the value to a string representation.

range #

Signature: range(start: int, end: int) -> iterator

Creates an iterator that generates numbers from start to end (exclusive).

readFile #

Signature: readFile(filename: string) -> Result<string, Error>

Reads the entire contents of a file as a string.

recv #

Signature: recv(channel: Channel) -> any

Receives a value from a channel.

send #

Signature: send(channel: Channel, value: any) -> int

Sends a value to a channel. Returns 1 for success, 0 for failure.

sleep #

Signature: sleep(milliseconds: int) -> int

Pauses execution for the specified number of milliseconds.

spawnProcess #

Signature: spawnProcess(command: string, callback: (int, int, string) -> Unit) -> Result<ProcessHandle, string>

Spawns an external async process with MANDATORY callback for stdout/stderr capture. The callback function receives (processID: int, eventType: int, data: string) and is called for stdout (1), stderr (2), and exit (3) events. Returns a handle for the running process. CALLBACK IS REQUIRED - NO FUNCTION OVERLOADING!

substring #

Signature: substring(s: string, start: int, end: int) -> Result<string, Error>

Extracts a substring from start to end index, or returns an error if indices are invalid.

toString #

Signature: toString(value: any) -> string

Converts a value to its string representation.

websocketClose #

Signature: websocketClose(wsID: Int) -> Result<Success, String>

⚠️ SPEC VIOLATION: Current implementation returns raw int64_t instead of Result<Success, String>. Closes the WebSocket connection and cleans up resources.

websocketConnect #

Signature: websocketConnect(url: String, messageHandler: (String) -> Result<Success, String>) -> Result<WebSocketID, String>

⚠️ SPEC VIOLATION: Current implementation returns raw int64_t instead of Result<WebSocketID, String> and takes string handler instead of function pointer. Establishes a WebSocket connection with a message handler callback.

websocketCreateServer #

Signature: websocketCreateServer(port: Int, address: String, path: String) -> Result<ServerID, String>

⚠️ SPEC VIOLATION: Current implementation returns raw int64_t instead of Result<ServerID, String> and has critical runtime issues with port binding failures. Creates a WebSocket server bound to the specified port, address, and path.

websocketKeepAlive #

Signature: websocketKeepAlive() -> Unit

⚠️ SPEC VIOLATION: Current implementation returns int instead of Unit. Keeps the WebSocket server running indefinitely until interrupted (blocking operation).

websocketSend #

Signature: websocketSend(wsID: Int, message: String) -> Result<Success, String>

⚠️ SPEC VIOLATION: Current implementation returns raw int64_t instead of Result<Success, String>. Sends a message through the WebSocket connection.

websocketServerBroadcast #

Signature: websocketServerBroadcast(serverID: Int, message: String) -> Result<Success, String>

⚠️ SPEC VIOLATION: Current implementation returns raw int64_t (number of clients sent to) instead of Result<Success, String>. Broadcasts a message to all connected WebSocket clients.

websocketServerListen #

Signature: websocketServerListen(serverID: Int) -> Result<Success, String>

⚠️ SPEC VIOLATION: Current implementation returns raw int64_t instead of Result<Success, String> and currently returns -4 (bind failed) due to port binding issues. Starts the WebSocket server listening for connections.

websocketStopServer #

Signature: websocketStopServer(serverID: Int) -> Result<Success, String>

⚠️ SPEC VIOLATION: Current implementation returns raw int64_t instead of Result<Success, String>. Stops the WebSocket server and closes all connections.

writeFile #

Signature: writeFile(filename: string, content: string) -> Result<int, Error>

Writes content to a file. Creates the file if it doesn’t exist. Returns number of bytes written.