Skip to content

[ext]

ext

The settings of a loaded extension. An extension is code that runs in a sandbox beside your program, loaded by an [[extension]] entry in nvs.toml. An extension may declare settings, and you set them in nvs.toml in a block named after the extension, such as [ext.ledger] for Shop\Ledger.

The extension declares each key, its type and its default. A key you leave out has its default. Each type is one of bool, int, uint, float, string or a list of strings.

The server checks the block when it starts. A key the extension does not declare stops the start with an error that names the extension. A block that belongs to no loaded extension stops it too. So a typo in a setting never goes unnoticed.

Only the person who runs the server sets these values. A program cannot change them: Core\Config::set returns false for every key in an [ext.<name>] block. A setting can only change how the extension behaves. It cannot give the extension access to files or the network.

The example below runs a program with the test extension Shop\Ledger and its settings block.

Only nvs.toml sets this key. A request may not change it.

A change in the file takes effect a few seconds after you save it. The server does not restart.

The examples below run with this configuration file.

nvs.toml
# Loads the extension `Shop\Ledger` and sets its one setting, `currency`.
[[extension]]
path = "../../../../tests/conformance/ext/fixtures/ledger.nvsx"
sha256 = "3112cf3359166c7a83a052ca0f21537ef8e1f87a6873d0b4c7d96b8b7fd4e1b6"
[ext.ledger]
currency = "USD"

Settings for a loaded extension

<?nvs
// Shows a program that runs with an extension and the settings block for it.
use Shop\Ledger;
// `nvs.toml` loads `Shop\Ledger` and sets `currency` in the block `[ext.ledger]`.
// The extension declares that key, so the program starts. This prints 42.
echo Ledger::echoInt(42), "\n";
// The block belongs to the person who runs the server. A program cannot change it,
// so `Core\Config::set` returns `false`. This prints "refused".
string $name = 'ext.ledger.currency';
bool $changed = Core\Config::set($name, 'EUR');
echo $changed ? 'changed' : 'refused', "\n";
Output
42
refused