lmaudio reference
Every type, method, flag and exit code of lmaudio 0.2.2, generated from the schema and signature list that the released binary prints, with notes from the repository README and examples.
Command line
usage: lmaudio --version | --notices | --lmcode-schema [--json] | --lmcode-signatures | [--dry-run] --lmcode FILE [FILE ...]
| Command or variable | Effect |
|---|---|
| lmaudio --version | Prints the release identity, for example lmaudio 0.2.2. |
| lmaudio --notices | Prints the third-party software notices with the upstream license texts. |
| lmaudio --lmcode-schema | Prints the embedded schema as readable JSON. |
| lmaudio --lmcode-schema --json | Prints the exact schema bytes the compiler binds a program to (schema version 2, name lmaudio). |
| lmaudio --lmcode-signatures | Prints every canonical signature the host registry provides, one per line, standard catalog included. |
| lmaudio --lmcode FILE [FILE ...] | Runs compiled lmcode program files. This is what run_lmcode calls; the compiler owns the program files. |
| lmaudio --dry-run --lmcode FILE | Runs a program without writing any file. The flag comes before --lmcode. The result envelope carries dry true. |
| LMAUDIO_MAX_MEMORY_MB | Environment variable: total memory budget in MiB, default 4096. A value that is not a positive whole number is a usage error on every command. |
Exit codes and result envelope
| Exit code | Envelope | Meaning |
|---|---|---|
| 0 | ok true | The program ran and every audio.assert_close held. |
| 2 | phase cli, code CLI_USAGE | Unknown or misplaced arguments, or an invalid LMAUDIO_MAX_MEMORY_MB. |
| 3 | phase load, for example code LOAD_BAD_BYTECODE or LOAD_UNBOUND | The program file cannot be read, or it imports a function the host does not provide. |
| 3 | phase run, code RUN_HOST | A host error with a source line and column: a failed audio.assert_close, a missing WAV file, an invalid argument, or the memory budget being exceeded. |
| Envelope field | Type | Present | Meaning |
|---|---|---|---|
| ok | bool | always | true when the run succeeded |
| result | JSON value | success | what the block stored with lmcode_return_set or lmcode_return_put; null when it stored nothing |
| dry | bool | dry runs | true for a --dry-run invocation |
| phase | string | failure | cli, load or run |
| code | string | failure | for example CLI_USAGE, LOAD_BAD_BYTECODE, LOAD_UNBOUND, RUN_HOST |
| message | string | failure | readable message; run errors start with the block line and column |
| line, column | int | run failures | position inside the block |
Schema summary
| Item | Value |
|---|---|
| dsl.schema | 2 |
| name | lmaudio |
| context | audio: Audio |
| enums | none |
| host free functions | none |
| host types | Audio, Buffer, Spectrum, Spectrogram, Biquad |
| host signatures | 171 (Audio 49, Buffer 83, Spectrum 17, Spectrogram 10, Biquad 11, plus the context declaration) |
Units: durations in seconds, frequencies in Hz, sr is the sample rate (100 to 384000 Hz, 44100 when the overload without it is used). Where a note names parameters, the names come from the repository README; rows without a parameter list show the types only, because the schema does not publish parameter names.
Audio (context object audio)
The context object audio. Generators return a Buffer.
| Method | Signatures | Notes |
|---|---|---|
| silence | silence(int, float) -> Buffer; silence(float, int) -> Buffer; silence(float) -> Buffer | silence(dur, sr). Sample rate defaults to 44100 when omitted. |
| sine | sine(float, float, float, int) -> Buffer; sine(float, float, float) -> Buffer; sine(float, float) -> Buffer | sine(f, dur, amp, sr). |
| cosine | cosine(float, float, float, int) -> Buffer; cosine(float, float, float) -> Buffer | cosine(f, dur, amp, sr). |
| saw | saw(float, float, float, int) -> Buffer; saw(float, float, float) -> Buffer | saw(f, dur, amp, sr). PolyBLEP band-limited. |
| square | square(float, float, float, float, int) -> Buffer; square(float, float, float, int) -> Buffer; square(float, float, float) -> Buffer | square(f, dur, amp, duty, sr). PolyBLEP band-limited. |
| triangle | triangle(float, float, float, int) -> Buffer; triangle(float, float, float) -> Buffer | triangle(f, dur, amp, sr). |
| chirp | chirp(float, float, float, float, string, int) -> Buffer; chirp(float, float, float, float, string) -> Buffer | chirp(f0, f1, dur, amp, mode, sr); mode is linear or log. |
| impulse | impulse(float, float, float, int) -> Buffer; impulse(float, float, float) -> Buffer | impulse(dur, at, amp, sr). |
| noise | noise(string, float, float, int, int) -> Buffer; noise(string, float, float, int) -> Buffer | noise(color, dur, amp, seed, sr); color is white, pink or brown. Seeded, so repeatable. |
| expr | expr(string, float, int) -> Buffer; expr(string, float) -> Buffer | expr(formula, dur, sr). Any formula in t, n, sr and dur, for example 0.5*sin(2*pi*440*t). |
| fm | fm(float, float, float, float, float, int) -> Buffer; fm(float, float, float, float, float) -> Buffer | fm(fc, ratio, index, dur, amp, sr). Chowning two-operator FM; index is β in radians. |
| pluck | pluck(float, float, float, float, float, int) -> Buffer; pluck(float, float, float) -> Buffer | DaisySP string voice. |
| modal | modal(float, float, float, float, float, float, int) -> Buffer; modal(float, float, float) -> Buffer | DaisySP modal voice. |
| bar | bar(int, int, float, float, float, float, int) -> Buffer | bar(bc_left, bc_right, stiffness, t60, dur, amp, sr). Euler-Bernoulli bar; boundary 1 clamped, 2 pinned, 3 free. |
| drum | drum(string, float, float, float, float, float, int) -> Buffer; drum(string, float, float, float) -> Buffer | drum(kind, f, dur, decay, tone, accent, sr); kind is kick, synth_kick, snare, synth_snare or hihat. |
| sequence | sequence(string, float, string, int) -> Buffer; sequence(string, float, string) -> Buffer | sequence(notes, bpm, instrument, sr). Notes as text such as C4:1 E4:0.5 R:0.5 C4+E4+G4:2; instruments sine, saw, square, triangle, fm, pluck, karplus, modal, pad. |
| note_freq | note_freq(string) -> float | Frequency of a note name such as A4. |
| midi_freq | midi_freq(float) -> float | Frequency of a MIDI note number such as 69. |
| load_wav | load_wav(string) -> Buffer | Reads PCM16, PCM24, float32 and WAVE_FORMAT_EXTENSIBLE files. |
| stereo | stereo(Buffer, Buffer) -> Buffer | stereo(left, right) builds a two-channel buffer. |
| biquad_design | biquad_design(string, float, float, float, int) -> Biquad; biquad_design(string, float, float, int) -> Biquad | biquad_design(kind, f, q, gain_db, sr). Returns the filter object for exact response queries. |
| print(string) -> void | Writes one report line to stderr. | |
| cents | cents(float, float) -> float | cents(f, ref): pitch distance in cents. |
| db | db(float) -> float | db(x): level in decibels. |
| save_text | save_text(string, string) -> void | save_text(path, text) writes a text file, for example a table for a plotting host. |
| karplus | karplus(float, float, float, float, int, int) -> Buffer; karplus(float, float, float, float) -> Buffer | karplus(f, dur, amp, t60, seed, sr). Karplus-Strong string with an allpass for fractional-delay tuning. |
| additive | additive(float, float, float, string, int) -> Buffer; additive(float, float, float, string) -> Buffer | additive(f0, dur, amp, partials, sr). Partials are amplitudes such as 1 0.5 0.33, or ratio:amplitude pairs such as 1:1 2.76:0.5. Band-limited. |
| assert_close | assert_close(float, float, float) -> void | assert_close(actual, expected, tol). A failure stops the run with exit code 3. |
Buffer
Mono or stereo 32-bit float audio, at most 200 million frames. Processing methods return a new Buffer.
| Method | Signatures | Notes |
|---|---|---|
| sr | sr() -> int | Sample rate in Hz. |
| channels | channels() -> int | 1 or 2. |
| frames | frames() -> int | Number of sample frames. |
| duration | duration() -> float | Length in seconds. |
| get | get(int) -> float; get(int, int) -> float | get(i) or get(i, ch): one sample. |
| channel | channel(int) -> Buffer | One channel as a mono buffer. |
| to_mono | to_mono() -> Buffer | Downmix. |
| gain | gain(float) -> Buffer | Linear gain. |
| gain_db | gain_db(float) -> Buffer | Gain in decibels. |
| normalize | normalize(float) -> Buffer; normalize() -> Buffer | normalize() or normalize(peak). |
| lufs | lufs() -> float | ITU-R BS.1770-4 integrated loudness with gating. Needs a sample rate of at least 8 kHz. |
| normalize_lufs | normalize_lufs(float) -> Buffer | normalize_lufs(target). |
| multiply | multiply(Buffer) -> Buffer | multiply(env): sample-wise product, used for envelopes and ring modulation. |
| convolve | convolve(Buffer) -> Buffer | convolve(ir): FFT convolution with an impulse response. |
| pattern | pattern(string, float, int) -> Buffer; pattern(string, float) -> Buffer | pattern(steps, bpm, steps_per_beat). Step sequencer: X accent, x hit, o ghost, digits 1 to 9 gain, a dot is a rest and | is a bar line. |
| granular | granular(float, float, float, float, float, float, int) -> Buffer | granular(dur, grain, density, position, pos_spread, pitch_spread, seed). Grain clouds and time-stretch. |
| schroeder_db | schroeder_db() -> Buffer | The Schroeder decay curve as a buffer. |
| rt60 | rt60() -> float | Reverberation time from T30, falling back to T20. |
| pitch_track_csv | pitch_track_csv(string, float, float, float, float) -> Buffer | pitch_track_csv(path, hop, win, fmin, fmax) writes a YIN pitch track. |
| normalize_rms | normalize_rms(float) -> Buffer | Normalize to an RMS level. |
| fade | fade(float, float, string) -> Buffer; fade(float, float) -> Buffer | fade(in, out) or fade(in, out, shape); shape is linear or cosine. |
| adsr | adsr(float, float, float, float, float) -> Buffer; adsr(float, float, float, float) -> Buffer | adsr(a, d, s, r) or adsr(a, d, s, r, gate). |
| pan | pan(float) -> Buffer | pan(position) from -1 to 1, equal power. Stereo input is downmixed to mono first. |
| slice | slice(float, float) -> Buffer | slice(start, end) in seconds. |
| pad | pad(float, float) -> Buffer | pad(before, after) adds silence in seconds. |
| concat | concat(Buffer) -> Buffer | Appends another buffer. |
| mix | mix(Buffer, float, float) -> Buffer; mix(Buffer, float) -> Buffer; mix(Buffer) -> Buffer | mix(other), mix(other, gain) or mix(other, gain, offset). |
| reverse | reverse() -> Buffer | Time reversal. |
| resample | resample(int) -> Buffer | resample(sr). Kaiser-windowed sinc conversion. |
| biquad | biquad(string, float, float, float) -> Buffer; biquad(string, float, float) -> Buffer | biquad(kind, f, q) or biquad(kind, f, q, gain_db). RBJ biquads; the repository examples use lowpass, highpass, bandpass, notch, peak, lowshelf and highshelf. |
| svf | svf(string, float, float, float) -> Buffer; svf(string, float, float) -> Buffer | State-variable filter. |
| ladder | ladder(float, float, float, string) -> Buffer; ladder(float, float) -> Buffer | ladder(cutoff, res) or ladder(cutoff, res, drive, mode). Moog ladder filter; the examples use mode lp24. |
| lpf_sweep | lpf_sweep(float, float, float) -> Buffer | lpf_sweep(f0, f1, res): resonant low-pass sweep. |
| delay | delay(float, float, float) -> Buffer | Delay effect. |
| reverb | reverb(float, float, float) -> Buffer | reverb(feedback, lpf, wet). Feedback-delay-network reverb. |
| zitarev | zitarev(float, float, float, float) -> Buffer | zitarev(rt60_low, rt60_mid, damping, wet). A clean-room FDN with zita-rev1-style controls, not zita-rev1. |
| chorus | chorus(float, float, float, float) -> Buffer | Modulation effect. |
| flanger | flanger(float, float, float, float) -> Buffer | Modulation effect. |
| phaser | phaser(float, float, float, int, float) -> Buffer | Modulation effect. |
| overdrive | overdrive(float, float) -> Buffer | Distortion. |
| wavefold | wavefold(float, float) -> Buffer | Wavefolding distortion. |
| bitcrush | bitcrush(int, float) -> Buffer | Bit-depth and rate reduction. |
| compress | compress(float, float, float, float, float) -> Buffer | compress(ratio, thresh_db, attack, release, makeup_db). Feed-forward compressor. |
| paulstretch | paulstretch(float, float) -> Buffer | Extreme time-stretch. |
| rms | rms() -> float; rms(int) -> float | RMS level; the int overload selects a channel. |
| peak | peak() -> float; peak(int) -> float | Peak level. |
| dc_offset | dc_offset() -> float; dc_offset(int) -> float | Mean value. |
| energy | energy() -> float; energy(int) -> float | Signal energy. |
| zcr | zcr() -> float; zcr(int) -> float | Zero-crossing rate. |
| pitch | pitch() -> float; pitch(float, float) -> float | pitch() or pitch(fmin, fmax). One YIN estimate for the most energetic window; 0 when unvoiced. |
| peak_freq | peak_freq() -> float; peak_freq(string) -> float | Frequency of the strongest spectral peak; the string overload names the window. |
| centroid | centroid() -> float; centroid(string) -> float | Spectral centroid in Hz. |
| thd | thd() -> float; thd(float, int) -> float | Total harmonic distortion; the examples call the second overload as thd(f0, 9). |
| snr_db | snr_db(Buffer) -> float | snr_db(ref): signal-to-noise ratio against a reference buffer. |
| spectrum | spectrum() -> Spectrum; spectrum(string) -> Spectrum; spectrum(string, int) -> Spectrum | spectrum(), spectrum(window) or spectrum(window, nfft). FFT of any length; windows rect, hann, hamming, blackman, flattop. |
| spectrogram | spectrogram(int, int, string, float) -> Spectrogram; spectrogram(int, int) -> Spectrogram | spectrogram(win, hop) or spectrogram(win, hop, window, fmax). STFT. |
| save_wav | save_wav(string) -> Buffer; save_wav(string, int) -> Buffer | save_wav(path) or save_wav(path, bits) with bits 16, 24 or 32. Returns the buffer. |
| save_csv | save_csv(string) -> Buffer; save_csv(string, int) -> Buffer; save_csv(string, int, int) -> Buffer | save_csv(path), save_csv(path, max_points) or save_csv(path, max_points, stride). |
Spectrum
Returned by Buffer.spectrum.
| Method | Signatures | Notes |
|---|---|---|
| bins | bins() -> int | Number of bins. |
| nfft | nfft() -> int | Transform length. |
| sr | sr() -> int | Sample rate. |
| freq_at | freq_at(int) -> float | Frequency of bin i. |
| mag_at | mag_at(int) -> float | Magnitude of bin i. |
| db_at | db_at(int) -> float | Level of bin i in dB. |
| phase_at | phase_at(int) -> float | Phase of bin i. |
| mag_at_freq | mag_at_freq(float) -> float | Magnitude at a frequency. |
| peak_bin | peak_bin() -> int | Index of the strongest bin. |
| peak_freq_in | peak_freq_in(float, float) -> float | peak_freq_in(lo, hi): strongest peak between two frequencies. |
| peak_freq | peak_freq() -> float | Frequency of the strongest peak. |
| peak_mag | peak_mag() -> float | Magnitude of the strongest peak. |
| centroid | centroid() -> float | Spectral centroid. |
| parseval_energy | parseval_energy() -> float | Energy computed from the spectrum. |
| ifft | ifft() -> Buffer | Inverse transform back to a buffer. |
| save_csv | save_csv(string) -> Spectrum; save_csv(string, float) -> Spectrum | Writes freq_hz, magnitude, db and phase_rad columns. The optional float is the highest frequency written. |
Spectrogram
Returned by Buffer.spectrogram.
| Method | Signatures | Notes |
|---|---|---|
| frames | frames() -> int | Number of time frames. |
| bins | bins() -> int | Number of frequency bins. |
| sr | sr() -> int | Sample rate. |
| time_at | time_at(int) -> float | Time of frame i. |
| freq_at | freq_at(int) -> float | Frequency of bin i. |
| mag_at | mag_at(int, int) -> float | Magnitude at frame and bin. |
| db_at | db_at(int, int) -> float | Level at frame and bin. |
| ridge_freq | ridge_freq(int) -> float | Strongest frequency in one frame. |
| save_csv | save_csv(string) -> Spectrogram; save_csv(string, float) -> Spectrogram | Writes the grid for a plotting host; the examples pass a dB floor such as -80.0 as the second argument. |
Biquad
Returned by audio.biquad_design.
| Method | Signatures | Notes |
|---|---|---|
| b0 | b0() -> float | Coefficient. |
| b1 | b1() -> float | Coefficient. |
| b2 | b2() -> float | Coefficient. |
| a1 | a1() -> float | Coefficient. |
| a2 | a2() -> float | Coefficient. |
| gain_at | gain_at(float) -> float | Exact magnitude at a frequency. |
| db_at | db_at(float) -> float | Exact level in dB at a frequency. |
| phase_deg_at | phase_deg_at(float) -> float | Exact phase in degrees at a frequency. |
| apply | apply(Buffer) -> Buffer | Filters a buffer. |
| save_response_csv | save_response_csv(string) -> Biquad; save_response_csv(string, int, float, float) -> Biquad | save_response_csv(path) or save_response_csv(path, points, f_lo, f_hi). Writes freq_hz, gain, db and phase_deg columns. |
String arguments
The schema declares no enums; these string values are the ones documented in the repository README or used by its examples.
| Argument | Values |
|---|---|
| chirp mode | linear, log |
| noise color | white, pink, brown |
| drum kind | kick, synth_kick, snare, synth_snare, hihat |
| sequence instrument | sine, saw, square, triangle, fm, pluck, karplus, modal, pad |
| biquad and biquad_design kind | lowpass, highpass, bandpass, notch, peak, lowshelf, highshelf |
| ladder mode | lp24 |
| spectrum and spectrogram window | rect, hann, hamming, blackman, flattop |
| fade shape | linear, cosine |
| bar boundary (int) | 1 clamped, 2 pinned, 3 free |
| save_wav bits (int) | 16, 24, 32 |
| pattern steps | X accent, x hit, o ghost, 1 to 9 gain, a dot for a rest, | bar line |
Limits
| Limit | Value |
|---|---|
| Sample rate | 100 to 384000 Hz |
| Channels | 1 or 2 |
| Buffer length | at most 200 million frames |
| Memory budget | 4096 MiB by default, LMAUDIO_MAX_MEMORY_MB to change |
| Audio output format | WAV, 16, 24 or 32 bit |
| WAV input formats | PCM16, PCM24, float32, WAVE_FORMAT_EXTENSIBLE |
Standard library (lmcode_std_v3)
The lmcode runtime inside lmaudio registers the standard catalog itself, so every block can call it next to the host API. lmaudio 0.2.2 reports 377 canonical signatures from lmaudio --lmcode-signatures: 171 host signatures and 206 standard ones. The current lmcode_std_v3 catalog has 226 canonical signatures; the 20 that this release does not ship are the REST and CLI group described at the end of this section. The lmaudio implementation source is private, so the public repository carries no std.lock; the count above is what the released binary reports. lmaudio picks up the remaining 20 signatures when a release built on the newer runtime ships; confirm with lmaudio --lmcode-signatures.
| Group | Signatures | In lmaudio 0.2.2 | Names |
|---|---|---|---|
| Strings | 17 | yes | str_contains, str_ends_with, str_find, str_is_float, str_is_int, str_len, str_lower, str_match, str_repeat, str_replace, str_starts_with, str_substr, str_to_float, str_to_int, str_trim, str_upper, template_render |
| Math | 16 | yes | math_abs, math_ceil, math_floor, math_max, math_min, math_pow, math_round, math_sqrt |
| Files | 5 | yes | file_append, file_exists, file_lines, file_read, file_write |
| Encoding | 4 | yes | str_base64_decode, str_base64_encode, str_hex_decode, str_hex_encode |
| JSON and templates | 12 | yes | json_parse, Json methods |
| Return values (runtime) | 24 | yes | lmcode_return_null, lmcode_return_put, lmcode_return_put_null, lmcode_return_set |
| Collections | 124 | yes | float_list, float_map, float_pq, float_queue, float_stack, int_list, int_map, int_pq, int_queue, int_stack, str_list, str_map, str_pq, str_queue, str_split, str_stack, FloatList methods, FloatMap methods, FloatPQ methods, FloatQueue methods, FloatStack methods, IntList methods, IntMap methods, IntPQ methods, IntQueue methods, IntStack methods, StrList methods, StrMap methods, StrPQ methods, StrQueue methods, StrStack methods |
| Containers | 4 | yes | FloatMap methods, IntMap methods |
| REST and CLI | 20 | no | rest_config, rest_route, rest_serve, rest_stop, rest_cli and 15 RestExchange methods |
Strings are raw bytes: lengths and offsets are byte based. Standard collections and Json values live for one run. Relative file paths resolve against the working directory of the host process, and the standard file functions apply no sandbox or root check. In lmaudio the lmcode_return functions are the way to send values back to LMScript.
String functions
| Function | Behavior |
|---|---|
| str_contains(string, string) -> bool | Byte substring search; an empty needle matches. |
| str_ends_with(string, string) -> bool | Byte suffix comparison; an empty suffix matches. |
| str_find(string, string) -> int | Return the first byte offset or -1; an empty needle returns 0. |
| str_is_float(string) -> bool | Accept a complete signed decimal with optional decimal point and exponent, including representable subnormals. Reject whitespace, hex, NaN/infinity, overflow and underflow to zero. |
| str_is_int(string) -> bool | Report whether the complete signed decimal token fits int64. |
| str_len(string) -> int | Return the raw byte length, including NUL and invalid UTF-8 bytes. |
| str_lower(string) -> string | Lowercase ASCII A-Z bytes; preserve every other byte. |
| str_match(string, string) -> bool | Match a whole byte string with *, ?, classes, ranges, negation, and backslash escapes. |
| str_repeat(string, int) -> string | Repeat raw bytes; reject negative counts and platform-unrepresentable result sizes. |
| str_replace(string, string, string) -> string | Replace nonoverlapping byte matches left to right; an empty search leaves bytes unchanged. No implicit result-size budget. |
| str_starts_with(string, string) -> bool | Byte prefix comparison; an empty prefix matches. |
| str_substr(string, int, int) -> string | Return a byte slice; clamp negative starts and overlong counts, with nonpositive counts empty. |
| str_to_float(string) -> float | Parse the same complete decimal grammar as str_is_float; return 0.0 on invalid input, overflow or underflow to zero. Preserve valid signed zero. |
| str_to_int(string) -> int | Parse a complete signed decimal int64 token; return zero on failure. |
| str_trim(string) -> string | Remove ASCII space and bytes 0x09 through 0x0d from both ends. |
| str_upper(string) -> string | Uppercase ASCII a-z bytes; preserve every other byte. |
| template_render(string, Json) -> string | Render arbitrary text with <path>, <items[0]>, <items:{item|body}; separator=", "> and <if(flag)>yes<else>no<endif>. Loop index is zero-based. << emits <. Inserted values remain literal. |
Math functions
| Function | Behavior |
|---|---|
| math_abs(float) -> float | Absolute value; integer arithmetic wraps, and float signed zero is cleared. |
| math_abs(int) -> int | Absolute value; integer arithmetic wraps, and float signed zero is cleared. |
| math_ceil(float) -> float | Identity for int; ceiling for binary64 while preserving signed zero. |
| math_ceil(int) -> int | Identity for int; ceiling for binary64 while preserving signed zero. |
| math_floor(float) -> float | Identity for int; floor for binary64 while preserving signed zero. |
| math_floor(int) -> int | Identity for int; floor for binary64 while preserving signed zero. |
| math_max(float, float) -> float | Maximum; integer comparison, or NaN propagation with first-operand ties for floats. |
| math_max(int, int) -> int | Maximum; integer comparison, or NaN propagation with first-operand ties for floats. |
| math_min(float, float) -> float | Minimum; integer comparison, or NaN propagation with first-operand ties for floats. |
| math_min(int, int) -> int | Minimum; integer comparison, or NaN propagation with first-operand ties for floats. |
| math_pow(float, float) -> float | Float power follows IEEE/libm special cases. |
| math_pow(int, int) -> int | Integer exponentiation wraps modulo 2^64; the exponent must be nonnegative. |
| math_round(float) -> float | Identity for int; binary64 nearest integer with halfway cases away from zero. |
| math_round(int) -> int | Identity for int; binary64 nearest integer with halfway cases away from zero. |
| math_sqrt(float) -> float | Binary64 square root for float. |
| math_sqrt(int) -> int | Exact floor integer square root; the argument must be nonnegative. |
File functions
| Function | Behavior |
|---|---|
| file_append(string, string) -> void | Create or append all raw bytes to a regular file. |
| file_exists(string) -> bool | Return true only when metadata identifies a regular file; missing and nonregular paths return false. |
| file_lines(string) -> StrList | Read raw bytes and split on every LF, preserving CR and empty fields: empty file gives [""], and "a\n" gives ["a", ""]. Return an arena-owned StrList. |
| file_read(string) -> string | Read a complete regular file as raw bytes. |
| file_write(string, string) -> void | Create or truncate a regular file and write all raw bytes. |
Encoding functions
| Function | Behavior |
|---|---|
| str_base64_decode(string) -> string | Decode canonical padded RFC 4648 Base64; reject whitespace, URL-safe symbols, invalid padding and nonzero pad bits. Empty input is legal. |
| str_base64_encode(string) -> string | Encode bytes as canonical padded RFC 4648 Base64 without line breaks. Empty input is legal. |
| str_hex_decode(string) -> string | Decode an even number of ASCII 0-9/a-f/A-F digits; reject separators, prefixes and whitespace. Empty input is legal. |
| str_hex_encode(string) -> string | Encode bytes as lowercase ASCII hex. Empty input is legal. |
JSON, templates and constructors
| Function | Behavior |
|---|---|
| float_list() -> FloatList | Construct an empty FloatList in the active collection arena. |
| float_map() -> FloatMap | Create an insertion-ordered byte-key map. |
| float_pq() -> FloatPQ | Create an empty FloatPQ in the run arena. |
| float_queue() -> FloatQueue | Create an empty FloatQueue in the run arena. |
| float_stack() -> FloatStack | Create an empty FloatStack in the run arena. |
| int_list() -> IntList | Construct an empty IntList in the active collection arena. |
| int_map() -> IntMap | Create an insertion-ordered byte-key map. |
| int_pq() -> IntPQ | Create an empty IntPQ in the run arena. |
| int_queue() -> IntQueue | Create an empty IntQueue in the run arena. |
| int_stack() -> IntStack | Create an empty IntStack in the run arena. |
| json_parse(string) -> Json | Parse strict UTF-8 JSON eagerly; int64 integers, finite binary64 decimals, depth <=256, duplicate decoded keys rejected. |
| str_list() -> StrList | Construct an empty StrList in the active collection arena. |
| str_map() -> StrMap | Construct an empty insertion-ordered StrMap in the active collection arena. |
| str_pq() -> StrPQ | Create an empty StrPQ in the run arena. |
| str_queue() -> StrQueue | Create an empty StrQueue in the run arena. |
| str_split(string, string) -> StrList | Split raw bytes on every nonoverlapping nonempty separator into a StrList. |
| str_stack() -> StrStack | Create an empty StrStack in the run arena. |
Return value functions
lmcode_return_set replaces the block result with one value, lmcode_return_put adds one named field, and the null forms store JSON null. The accepted value types are listed in the table.
| Function | Overloads | Signatures |
|---|---|---|
| lmcode_return_null | 1 | lmcode_return_null() -> void |
| lmcode_return_put | 11 | lmcode_return_put(string, FloatList) -> void; lmcode_return_put(string, FloatMap) -> void; lmcode_return_put(string, IntList) -> void; lmcode_return_put(string, IntMap) -> void; lmcode_return_put(string, Json) -> void; lmcode_return_put(string, StrList) -> void; lmcode_return_put(string, StrMap) -> void; lmcode_return_put(string, bool) -> void; lmcode_return_put(string, float) -> void; lmcode_return_put(string, int) -> void; lmcode_return_put(string, string) -> void |
| lmcode_return_put_null | 1 | lmcode_return_put_null(string) -> void |
| lmcode_return_set | 11 | lmcode_return_set(FloatList) -> void; lmcode_return_set(FloatMap) -> void; lmcode_return_set(IntList) -> void; lmcode_return_set(IntMap) -> void; lmcode_return_set(Json) -> void; lmcode_return_set(StrList) -> void; lmcode_return_set(StrMap) -> void; lmcode_return_set(bool) -> void; lmcode_return_set(float) -> void; lmcode_return_set(int) -> void; lmcode_return_set(string) -> void |
Standard types and their methods
| Type | Methods | Signatures |
|---|---|---|
| FloatList | 7 | add(float) -> FloatList; at(int) -> float; clear() -> FloatList; contains(float) -> bool; index_of(float) -> int; len() -> int; set(int, float) -> FloatList |
| FloatMap | 10 | clear() -> FloatMap; get(string) -> float; get_or(string, float) -> float; has(string) -> bool; key_at(int) -> string; keys() -> StrList; len() -> int; remove(string) -> bool; set(string, float) -> FloatMap; values() -> FloatList |
| FloatPQ | 6 | clear() -> FloatPQ; empty() -> bool; len() -> int; peek() -> float; pop() -> float; push(float, float) -> FloatPQ |
| FloatQueue | 7 | at(int) -> float; clear() -> FloatQueue; empty() -> bool; len() -> int; peek() -> float; pop() -> float; push(float) -> FloatQueue |
| FloatStack | 7 | at(int) -> float; clear() -> FloatStack; empty() -> bool; len() -> int; peek() -> float; pop() -> float; push(float) -> FloatStack |
| IntList | 7 | add(int) -> IntList; at(int) -> int; clear() -> IntList; contains(int) -> bool; index_of(int) -> int; len() -> int; set(int, int) -> IntList |
| IntMap | 10 | clear() -> IntMap; get(string) -> int; get_or(string, int) -> int; has(string) -> bool; key_at(int) -> string; keys() -> StrList; len() -> int; remove(string) -> bool; set(string, int) -> IntMap; values() -> IntList |
| IntPQ | 6 | clear() -> IntPQ; empty() -> bool; len() -> int; peek() -> int; pop() -> int; push(int, float) -> IntPQ |
| IntQueue | 7 | at(int) -> int; clear() -> IntQueue; empty() -> bool; len() -> int; peek() -> int; pop() -> int; push(int) -> IntQueue |
| IntStack | 7 | at(int) -> int; clear() -> IntStack; empty() -> bool; len() -> int; peek() -> int; pop() -> int; push(int) -> IntStack |
| Json | 11 | as_bool() -> bool; as_float() -> float; as_int() -> int; as_string() -> string; at(int) -> Json; get(string) -> Json; has(string) -> bool; keys() -> StrList; kind() -> string; len() -> int; to_json() -> string |
| StrList | 8 | add(string) -> StrList; at(int) -> string; clear() -> StrList; contains(string) -> bool; index_of(string) -> int; join(string) -> string; len() -> int; set(int, string) -> StrList |
| StrMap | 10 | clear() -> StrMap; get(string) -> string; get_or(string, string) -> string; has(string) -> bool; key_at(int) -> string; keys() -> StrList; len() -> int; remove(string) -> bool; set(string, string) -> StrMap; values() -> StrList |
| StrPQ | 6 | clear() -> StrPQ; empty() -> bool; len() -> int; peek() -> string; pop() -> string; push(string, float) -> StrPQ |
| StrQueue | 7 | at(int) -> string; clear() -> StrQueue; empty() -> bool; len() -> int; peek() -> string; pop() -> string; push(string) -> StrQueue |
| StrStack | 7 | at(int) -> string; clear() -> StrStack; empty() -> bool; len() -> int; peek() -> string; pop() -> string; push(string) -> StrStack |
A for loop can iterate any standard list directly, because each list type provides len and at.
REST endpoints and stateless CLI interfaces
The current lmcode_std_v3 catalog includes the former lmcode_std_rest_v1 module: 10 standard interfaces, 5 functions and 15 RestExchange methods. They are documented here so that a program written for another host reads the same way, but lmaudio 0.2.2 does not provide them: a block that calls one of them compiles with a current lmscript and is then refused by the host at load time with code LOAD_UNBOUND, before any host work starts.
| Interface | Signature | Role |
|---|---|---|
| RestGet | (exchange: RestExchange) -> void | handler for GET routes |
| RestPost | (exchange: RestExchange) -> void | handler for POST routes |
| RestPut | (exchange: RestExchange) -> void | handler for PUT routes |
| RestDelete | (exchange: RestExchange) -> void | handler for DELETE routes |
| RestPatch | (exchange: RestExchange) -> void | handler for PATCH routes |
| RestHead | (exchange: RestExchange) -> void | handler for HEAD routes |
| RestOptions | (exchange: RestExchange) -> void | handler for OPTIONS routes |
| RestHandler | (exchange: RestExchange) -> void | handler bound to a route by rest_route |
| CliCommand | (exchange: RestExchange) -> void | command handler dispatched by rest_cli |
| CliOption | (exchange: RestExchange) -> void | option handler dispatched by rest_cli |
| Signature | Behavior in the catalog |
|---|---|
| rest_cli(StrList) -> string | Auto-register annotated REST and CLI routes, dispatch a single stateless CLI argv request through CliOption and CliCommand/REST handlers, and return the response body. |
| rest_config(string, string) -> void | Set a configuration or initial session store entry on the global single-session REST controller before serving. |
| rest_route(string, string, string) -> void | Register a route pattern for an HTTP method and bind it to a @tag RestHandler entry. |
| rest_serve() -> void | Auto-register annotated REST routes, validate route bindings, and arm the global single-session stdio server loop. |
| rest_stop() -> void | Stop the active REST stdio server loop after the current exchange finishes. |
| RestExchange.body() -> string | Return the raw request body bytes. |
| RestExchange.get(string) -> string | Read a string value from the global single-session store, or empty string when absent. |
| RestExchange.has_header(string) -> bool | Return whether the request contains a case-insensitive header name. |
| RestExchange.has_query(string) -> bool | Return whether the request URL contains the query key. |
| RestExchange.header(string) -> string | Read a case-insensitive request header value, or empty string when absent. |
| RestExchange.increment(string) -> int | Increment a decimal integer counter in the global single-session store and return the new value. |
| RestExchange.json(string) -> void | Validate strict UTF-8 JSON, set default content-type to application/json, and replace the response body. |
| RestExchange.method() -> string | Return the canonical uppercase HTTP method of the request. |
| RestExchange.param(string) -> string | Read a matched path parameter by name. |
| RestExchange.path() -> string | Return the decoded request path without query string. |
| RestExchange.query(string) -> string | Read the last decoded query value for a key, or empty string when absent. |
| RestExchange.send(string) -> void | Set default content-type to text/plain; charset=utf-8 if unset and replace the response body. |
| RestExchange.set(string, string) -> void | Store a key-value pair in the global single-session store. |
| RestExchange.set_header(string, string) -> void | Set or replace a case-insensitive response header. |
| RestExchange.status(int) -> void | Set the HTTP response status code (100..599). |
Route templates accept {param} and {rest...} placeholders as well as :param and :rest... placeholders. rest_cli(argv) is the stateless CLI mode: it dispatches options, commands and REST routes for one argument list and returns the response body.