IO

From MemCP
Revision as of 08:12, 27 August 2026 by Carli (talk | contribs)
Jump to navigation Jump to search

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: 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