IO: Difference between revisions
(Created page with "= IO = The '''IO''' module provides functions for input and output operations, environment handling, file streaming, server control, and argument parsing in SCM. ← Back to Full SCM API documentation == print == Prints values to stdout (only in IO environment) '''Allowed number of parameters:''' 1–1000 '''Parameters:''' * '''value...''' (<code>any</code>): values to print '''Returns:''' <code>bool</code> == env == returns the content of a environment vari...") |
No edit summary |
||
| Line 9: | Line 9: | ||
Prints values to stdout (only in IO environment) | Prints values to stdout (only in IO environment) | ||
'''Allowed number of parameters:''' | '''Allowed number of parameters:''' 0–10000 | ||
<span id="parameters"></span> | |||
=== Parameters === | |||
''' | * '''value...''' (<code>any</code>): values to print ''(variadic)'' | ||
<span id="returns"></span> | |||
=== Returns === | |||
<code>bool</code> | |||
== env == | == env == | ||
| Line 22: | Line 27: | ||
'''Allowed number of parameters:''' 1–2 | '''Allowed number of parameters:''' 1–2 | ||
<span id="parameters-1"></span> | |||
=== Parameters === | |||
* '''var''' (<code>string</code>): envvar | * '''var''' (<code>string</code>): envvar | ||
* '''default''' (<code>string</code>): default if the env is not found | * '''default''' (<code>string</code>): default if the env is not found ''(optional)'' | ||
<span id="returns-1"></span> | |||
=== Returns === | |||
<code>string</code> | |||
== help == | == help == | ||
Lists all functions or | Lists all functions or returns help for a specific function as a string | ||
'''Allowed number of parameters:''' 0–1 | '''Allowed number of parameters:''' 0–1 | ||
<span id="parameters-2"></span> | |||
* '''topic''' (<code>string</code>): function to | === Parameters === | ||
* '''topic''' (<code>string</code>): function to get help about ''(optional)'' | |||
<span id="returns-2"></span> | |||
=== Returns === | |||
<code>string</code> | |||
== import == | == import == | ||
Imports a .scm file into current namespace | Imports a file .scm file into current namespace | ||
'''Allowed number of parameters:''' 1–1 | '''Allowed number of parameters:''' 1–1 | ||
<span id="parameters-3"></span> | |||
* '''filename''' (<code>string</code>): filename relative to folder of source file | === Parameters === | ||
* '''filename''' (<code>string</code>): filename relative to folder of source file or absolute path | |||
<span id="returns-3"></span> | |||
=== Returns === | |||
<code>any</code> | |||
== load == | == load == | ||
| Line 56: | Line 76: | ||
'''Allowed number of parameters:''' 1–3 | '''Allowed number of parameters:''' 1–3 | ||
<span id="parameters-4"></span> | |||
=== Parameters === | |||
''' | * '''filenameOrStream''' (<code>string|stream</code>): filename relative to folder of source file, absolute path, or stream to read from | ||
* '''linehandler''' (<code>func(line:string) -> any</code>): handler that reads each line; each line may end with delimiter ''(optional)'' | |||
* '''delimiter''' (<code>string</code>): delimiter to extract; if no delimiter is given, the file is read as whole and returned or passed to linehandler ''(optional)'' | |||
<span id="returns-4"></span> | |||
=== Returns === | |||
<code>string|bool</code> | |||
== stream == | == stream == | ||
| Line 69: | Line 94: | ||
'''Allowed number of parameters:''' 1–1 | '''Allowed number of parameters:''' 1–1 | ||
<span id="parameters-5"></span> | |||
* '''filename''' (<code>string</code>): filename | === Parameters === | ||
* '''filename''' (<code>string</code>): filename relative to folder of source file or absolute path | |||
<span id="returns-5"></span> | |||
=== Returns === | |||
<code>stream</code> | |||
== watch == | == watch == | ||
Loads a file and calls | Loads a file and calls the callback. Whenever the file changes on disk, the file is load again. | ||
'''Allowed number of parameters:''' 2–2 | '''Allowed number of parameters:''' 2–2 | ||
<span id="parameters-6"></span> | |||
=== Parameters === | |||
''' | * '''filename''' (<code>string</code>): filename relative to folder of source file or absolute path | ||
* '''updatehandler''' (<code>func(content:string) -> any</code>): handler that receives the file content func(content) | |||
<span id="returns-6"></span> | |||
=== Returns === | |||
<code>bool</code> | |||
== serve == | == serve == | ||
| Line 92: | Line 127: | ||
'''Allowed number of parameters:''' 2–2 | '''Allowed number of parameters:''' 2–2 | ||
<span id="parameters-7"></span> | |||
=== Parameters === | |||
''' | * '''port''' (<code>number</code>): port number for HTTP server | ||
* '''handler''' (<code>func(req:any, res:any) -> any</code>): handler: lambda(req res) that handles the http request | |||
<span id="returns-7"></span> | |||
=== Returns === | |||
<code>bool</code> | |||
<span id="servestatic"></span> | |||
== serveStatic == | == serveStatic == | ||
creates a static handler for use as a callback in (serve) - returns a handler lambda(req res) | |||
'''Allowed number of parameters:''' 1–1 | '''Allowed number of parameters:''' 1–1 | ||
<span id="parameters-8"></span> | |||
* '''directory''' (<code>string</code>): folder with files | === Parameters === | ||
* '''directory''' (<code>string</code>): folder with the files to serve | |||
<span id="returns-8"></span> | |||
=== Returns === | |||
<code>func(req:any, res:any) -> any</code> | |||
== mysql == | == mysql == | ||
Imports a file .scm file into current namespace | |||
'''Allowed number of parameters:''' 4–4 | |||
<span id="parameters-9"></span> | |||
=== Parameters === | |||
* '''port''' (<code>number</code>): port number for MySQL server | |||
* '''getPassword''' (<code>func(username:string) -> string|nil</code>): lambda(username string) string|nil has to return the password for a user or nil to deny login | |||
* '''schemacallback''' (<code>func(username:string, schema:string) -> bool</code>): lambda(username schema) bool handler check whether user is allowed to schema - you should check access rights here | |||
* '''handler''' (<code>func(schema:string, sql:string, resultrow:func, session:func) -> any</code>): lambda(schema sql resultrow session) handler to process sql query in schema. resultrow is a lambda(list) | |||
<span id="returns-9"></span> | |||
=== Returns === | |||
<code>bool</code> | |||
== mysql_socket == | |||
Listen on a Unix domain socket for MySQL protocol | |||
'''Allowed number of parameters:''' 4–4 | '''Allowed number of parameters:''' 4–4 | ||
<span id="parameters-10"></span> | |||
=== Parameters === | |||
''' | * '''socketpath''' (<code>string</code>): path to the Unix domain socket | ||
* '''getPassword''' (<code>func(username:string) -> string|nil</code>): lambda(username string) string|nil has to return the password for a user or nil to deny login | |||
* '''schemacallback''' (<code>func(username:string, schema:string) -> bool</code>): lambda(username schema) bool handler check whether user is allowed to schema - you should check access rights here | |||
* '''handler''' (<code>func(schema:string, sql:string, resultrow:func, session:func) -> any</code>): lambda(schema sql resultrow session) handler to process sql query in schema. resultrow is a lambda(list) | |||
<span id="returns-10"></span> | |||
=== Returns === | |||
<code>bool</code> | |||
== password == | == password == | ||
Hashes a password with sha1 | Hashes a password with sha1 (for mysql user authentication) | ||
'''Allowed number of parameters:''' 1–1 | '''Allowed number of parameters:''' 1–1 | ||
<span id="parameters-11"></span> | |||
=== Parameters === | |||
'''Returns:''' <code>string</code> | * '''password''' (<code>string</code>): plain text password to hash | ||
<span id="returns-11"></span> | |||
=== Returns === | |||
<code>string</code> | |||
== shutdown == | |||
Initiates a graceful shutdown of memcp after a short delay | |||
'''Allowed number of parameters:''' 0–0 | |||
<span id="parameters-12"></span> | |||
=== Parameters === | |||
''This function has no parameters.'' | |||
<span id="returns-12"></span> | |||
=== Returns === | |||
<code>bool</code> | |||
== crash == | |||
Hard process exit with no cleanup (kill -9 equivalent) for crash testing. SCM only, not exposed to SQL. | |||
'''Allowed number of parameters:''' 0–0 | |||
<span id="parameters-13"></span> | |||
=== Parameters === | |||
''This function has no parameters.'' | |||
<span id="returns-13"></span> | |||
=== Returns === | |||
<code>bool</code> | |||
== path == | |||
Joins path segments using the OS path separator and cleans the result | |||
'''Allowed number of parameters:''' 0–10000 | |||
<span id="parameters-14"></span> | |||
=== Parameters === | |||
* '''segments''' (<code>string</code>): path segments to join ''(variadic)'' | |||
<span id="returns-14"></span> | |||
=== Returns === | |||
<code>string</code> | |||
== args == | == args == | ||
| Line 140: | Line 263: | ||
'''Allowed number of parameters:''' 0–0 | '''Allowed number of parameters:''' 0–0 | ||
<span id="parameters-15"></span> | |||
=== Parameters === | |||
'''Returns | ''This function has no parameters.'' | ||
<span id="returns-15"></span> | |||
=== Returns === | |||
<code>list</code> | |||
== arg == | == arg == | ||
| Line 150: | Line 279: | ||
'''Allowed number of parameters:''' 2–3 | '''Allowed number of parameters:''' 2–3 | ||
<span id="parameters-16"></span> | |||
* '''longname''' (<code>string</code>): long argument name | === Parameters === | ||
* '''shortname''' (<code>string</code>): short argument or default | |||
* '''default''' (<code>any</code>): | * '''longname''' (<code>string</code>): long argument name (without --) | ||
* '''shortname''' (<code>string|any</code>): short argument name (without -) or default value if only 2 args | |||
* '''default''' (<code>any</code>): default value if argument not found ''(optional)'' | |||
<span id="returns-16"></span> | |||
=== Returns === | |||
<code>any</code> | |||
Revision as of 08:12, 27 August 2026
IO
The IO module provides functions for input and output operations, environment handling, file streaming, server control, and argument parsing in SCM.
← Back to Full SCM API documentation
Prints values to stdout (only in IO environment)
Allowed number of parameters: 0–10000
Parameters
- value... (
any): values to print (variadic)
Returns
bool
env
returns the content of a environment variable
Allowed number of parameters: 1–2
Parameters
- var (
string): envvar - default (
string): default if the env is not found (optional)
Returns
string
help
Lists all functions or returns help for a specific function as a string
Allowed number of parameters: 0–1
Parameters
- topic (
string): function to get help about (optional)
Returns
string
import
Imports a file .scm file into current namespace
Allowed number of parameters: 1–1
Parameters
- filename (
string): filename relative to folder of source file or absolute path
Returns
any
load
Loads a file or stream and returns the string or iterates line-wise
Allowed number of parameters: 1–3
Parameters
- filenameOrStream (
string|stream): filename relative to folder of source file, absolute path, or stream to read from - linehandler (
func(line:string) -> any): handler that reads each line; each line may end with delimiter (optional) - delimiter (
string): delimiter to extract; if no delimiter is given, the file is read as whole and returned or passed to linehandler (optional)
Returns
string|bool
stream
Opens a file readonly as stream
Allowed number of parameters: 1–1
Parameters
- filename (
string): filename relative to folder of source file or absolute path
Returns
stream
watch
Loads a file and calls the callback. Whenever the file changes on disk, the file is load again.
Allowed number of parameters: 2–2
Parameters
- filename (
string): filename relative to folder of source file or absolute path - updatehandler (
func(content:string) -> any): handler that receives the file content func(content)
Returns
bool
serve
Opens a HTTP server at a given port
Allowed number of parameters: 2–2
Parameters
- port (
number): port number for HTTP server - handler (
func(req:any, res:any) -> any): handler: lambda(req res) that handles the http request
Returns
bool
serveStatic
creates a static handler for use as a callback in (serve) - returns a handler lambda(req res)
Allowed number of parameters: 1–1
Parameters
- directory (
string): folder with the files to serve
Returns
func(req:any, res:any) -> any
mysql
Imports a file .scm file into current namespace
Allowed number of parameters: 4–4
Parameters
- port (
number): port number for MySQL server - getPassword (
func(username:string) -> string|nil): lambda(username string) string|nil has to return the password for a user or nil to deny login - schemacallback (
func(username:string, schema:string) -> bool): lambda(username schema) bool handler check whether user is allowed to schema - you should check access rights here - handler (
func(schema:string, sql:string, resultrow:func, session:func) -> any): lambda(schema sql resultrow session) handler to process sql query in schema. resultrow is a lambda(list)
Returns
bool
mysql_socket
Listen on a Unix domain socket for MySQL protocol
Allowed number of parameters: 4–4
Parameters
- socketpath (
string): path to the Unix domain socket - getPassword (
func(username:string) -> string|nil): lambda(username string) string|nil has to return the password for a user or nil to deny login - schemacallback (
func(username:string, schema:string) -> bool): lambda(username schema) bool handler check whether user is allowed to schema - you should check access rights here - handler (
func(schema:string, sql:string, resultrow:func, session:func) -> any): lambda(schema sql resultrow session) handler to process sql query in schema. resultrow is a lambda(list)
Returns
bool
password
Hashes a password with sha1 (for mysql user authentication)
Allowed number of parameters: 1–1
Parameters
- password (
string): plain text password to hash
Returns
string
shutdown
Initiates a graceful shutdown of memcp after a short delay
Allowed number of parameters: 0–0
Parameters
This function has no parameters.
Returns
bool
crash
Hard process exit with no cleanup (kill -9 equivalent) for crash testing. SCM only, not exposed to SQL.
Allowed number of parameters: 0–0
Parameters
This function has no parameters.
Returns
bool
path
Joins path segments using the OS path separator and cleans the result
Allowed number of parameters: 0–10000
Parameters
- segments (
string): path segments to join (variadic)
Returns
string
args
Returns command line arguments
Allowed number of parameters: 0–0
Parameters
This function has no parameters.
Returns
list
arg
Gets a command line argument value
Allowed number of parameters: 2–3
Parameters
- longname (
string): long argument name (without --) - shortname (
string|any): short argument name (without -) or default value if only 2 args - default (
any): default value if argument not found (optional)
Returns
any