KScript docs
EN

Built-in variables

Variables every script or page has without declaring them. Some come with a package, and exist once it is imported.

VariableTypePackageDescription
$argslistKScript.CoreThe command line arguments after the script path.
$configconfigKScript.CoreThe project's settings: the "config" section of kscript.json, with kscript.<env>.json and config.kscript laid over it: $config.database.host.
$envmapKScript.CoreEnvironment variables: $env.HOME, $env['PATH'].
$eventmapKScript.CoreThe event a handler runs for, in on-* attributes and <on> blocks: $event.value, $event.key, $event.data... Its fields depend on the handler.
$logloggerKScript.CoreThe script's logger: $log->info('Saved', { id: $id }), $log->named('db')->debug(...). Providers and levels come from $config.logging.
$osmapKScript.CoreThe computer: $os.name (windows, macos or linux), $os.user, $os.machine, $os.home, $os.temp, $os.separator, $os.newline.
$scriptmapKScript.CoreThis script: $script.path, $script.dir, $script.name.
$sessionsessionKScript.AuthThe request's session: values kept between requests by a cookie. $session->set('cart', $items), $session->get('cart'), and $session->flash('status', 'Saved') for a message after a redirect.
$cachecacheKScript.CacheThe app's cache in memory: $cache->remember('repos', fn() => @get_json($url), ttl: 10m). It lasts while kscript runs, so in kscript serve it is shared by every request. @cache(file) keeps values between runs.
$dbdatabaseKScript.DataThe default database connection: $db->table('users'), $db->tables(), $db->create_table(User). With no config it is SQLite in data/app.sqlite in the project folder; database.connections in your config sets others.
$requestrequestKScript.HttpThe HTTP request. Inside a matched route it also contains the client ip, parsed json, combined input and route name.
$enumberKScript.Mathe, about 2.71828.
$pinumberKScript.Mathπ, about 3.14159.
$taunumberKScript.Mathτ (2π), about 6.28318.
$varsmapKScript.StyleValues given to the stylesheet: @stylesheet(path, vars) or kscript css --var name=value.