silverbullet/website/API/system.md

117 lines
2.2 KiB
Markdown
Raw Normal View History

2025-01-17 03:41:52 +08:00
# System API
The System API provides system-level functions for interacting with the SilverBullet environment.
## Function Operations
### system.invokeFunction(name, ...)
2025-01-17 03:41:52 +08:00
Invokes a plug function by name.
Example:
```lua
-- Invoke a function from a plug
system.invokeFunction("myplug.processData", "input", 123)
2025-01-17 03:41:52 +08:00
```
### system.invokeCommand(name, args)
2025-01-17 03:41:52 +08:00
Invokes a client command by name.
Example:
```lua
system.invokeCommand("editor.save", {})
2025-01-17 03:41:52 +08:00
```
### system.invokeSpaceFunction(name, ...)
2025-01-17 03:41:52 +08:00
Invokes a space function by name.
Example:
```lua
local result = system.invokeSpaceFunction("customFunction", "arg1", "arg2")
2025-01-17 03:41:52 +08:00
print("Function result:", result)
```
## System Information
### system.listCommands()
2025-01-17 03:41:52 +08:00
Lists all available commands.
Example:
```lua
local commands = system.listCommands()
2025-01-17 03:41:52 +08:00
for name, def in pairs(commands) do
print(name .. ": " .. def.description)
end
```
### system.listSyscalls()
2025-01-17 03:41:52 +08:00
Lists all available syscalls.
Example:
```lua
local syscalls = system.listSyscalls()
2025-01-17 03:41:52 +08:00
for _, syscall in ipairs(syscalls) do
print(syscall.name)
end
```
### system.getEnv()
2025-01-17 03:41:52 +08:00
Returns the runtime environment ("server", "client", or undefined for hybrid).
Example:
```lua
local env = system.getEnv()
2025-01-17 03:41:52 +08:00
print("Running in environment: " .. (env or "hybrid"))
```
### system.getMode()
2025-01-17 03:41:52 +08:00
Returns the current mode of the system ("ro" or "rw").
Example:
```lua
local mode = system.getMode()
2025-01-17 03:41:52 +08:00
print("System mode: " .. mode)
```
### system.getVersion()
2025-01-17 03:41:52 +08:00
Returns the SilverBullet version.
Example:
```lua
local version = system.getVersion()
2025-01-17 03:41:52 +08:00
print("SilverBullet version: " .. version)
```
## Configuration
### system.getSpaceConfig(key, defaultValue)
2025-01-17 03:41:52 +08:00
Loads space configuration values.
Example:
```lua
-- Get specific config value
local value = system.getSpaceConfig("theme", "light")
2025-01-17 03:41:52 +08:00
-- Get all config values
local config = system.getSpaceConfig()
2025-01-17 03:41:52 +08:00
for key, value in pairs(config) do
print(key .. ": " .. value)
end
```
### system.reloadConfig()
2025-01-17 03:41:52 +08:00
Triggers an explicit reload of the configuration.
Example:
```lua
system.reloadConfig()
2025-01-17 03:41:52 +08:00
print("Configuration reloaded")
```
### system.reloadPlugs()
2025-01-17 03:41:52 +08:00
Triggers a reload of all plugs.
Example:
```lua
system.reloadPlugs()
2025-01-17 03:41:52 +08:00
print("All plugs reloaded")