silverbullet/website/API/system.md

2.2 KiB

System API

The System API provides system-level functions for interacting with the SilverBullet environment.

Function Operations

system.invoke_function(name, ...)

Invokes a plug function by name.

Example:

-- Invoke a function from a plug
system.invoke_function("myplug.process_data", "input", 123)

system.invoke_command(name, args)

Invokes a client command by name.

Example:

system.invoke_command("editor.save", {})

system.invoke_space_function(name, ...)

Invokes a space function by name.

Example:

local result = system.invoke_space_function("custom_function", "arg1", "arg2")
print("Function result:", result)

System Information

system.list_commands()

Lists all available commands.

Example:

local commands = system.list_commands()
for name, def in pairs(commands) do
    print(name .. ": " .. def.description)
end

system.list_syscalls()

Lists all available syscalls.

Example:

local syscalls = system.list_syscalls()
for _, syscall in ipairs(syscalls) do
    print(syscall.name)
end

system.get_env()

Returns the runtime environment ("server", "client", or undefined for hybrid).

Example:

local env = system.get_env()
print("Running in environment: " .. (env or "hybrid"))

system.get_mode()

Returns the current mode of the system ("ro" or "rw").

Example:

local mode = system.get_mode()
print("System mode: " .. mode)

system.get_version()

Returns the SilverBullet version.

Example:

local version = system.get_version()
print("SilverBullet version: " .. version)

Configuration

system.get_space_config(key, default_value)

Loads space configuration values.

Example:

-- Get specific config value
local value = system.get_space_config("theme", "light")

-- Get all config values
local config = system.get_space_config()
for key, value in pairs(config) do
    print(key .. ": " .. value)
end

system.reload_config()

Triggers an explicit reload of the configuration.

Example:

local new_config = system.reload_config()
print("Configuration reloaded")

system.reload_plugs()

Triggers a reload of all plugs.

Example:

system.reload_plugs()
print("All plugs reloaded")