ludic/fn-words.html
2026-09-17 22:10:03 +00:00

40 lines
No EOL
2.3 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>words — Ludic</title>
<meta name="description" content="Allocate a raw buffer of n 32-bit words, indexable with [i].">
<link rel="stylesheet" href="base.css">
<link rel="stylesheet" href="docs.css">
</head>
<body>
<header class="nav"><div class="wrap nav-in"><a class="brand" href="index.html"><span class="logo">L</span> Ludic</a><button class="nav-toggle" aria-label="Toggle menu" aria-expanded="false">☰</button><nav class="nav-links"><a href="index.html">Home</a><a href="api.html">API Reference</a><a class="nav-cta" href="https://git.workshopsoft.io/workshopsoft/ludic">Source ↗</a></nav></div></header>
<main class="wrap item">
<div class="crumbs"><a href="api.html">API Reference</a> <span>›</span> <a href="api.html#builtins">Builtin functions</a> <span>›</span> <span class="here">words</span></div>
<div class="item-head">
<span class="kind-badge kind-builtin">function</span>
<h1 id="top">words</h1>
</div>
<code class="sig">words(n) -&gt; words</code>
<div class="desc"><p>Allocates a raw buffer of <code>n</code> 32-bit words and returns a <code>words</code> value you can index with <code>buffer[i]</code> to read or write each word as an <code>int</code>. Use it when you want a flat, fixed-size numeric scratch array — a lookup table, a small ring buffer, or per-slot counters — without declaring a model. It is lower-level than a growable <code>[]int</code> slice: the size is chosen up front and there is no <code>push</code>. For byte-granular storage use <code>bytes</code> instead.</p></div>
<div class="params"><h2>Parameters</h2><div class="param" id="param-n"><code class="pname">n</code><span class="pdesc">the number of 32-bit words to allocate</span></div></div>
<div class="examples"><h2>Example</h2><pre data-lang="ludic">program WordScratch {
handler SumScores phase Start {
let scores = words(3)
scores[0] = 10
scores[1] = 20
scores[2] = 30
var total: int = 0
for index in 0 .. 3 {
total = total + scores[index]
}
print(total)
}
}</pre></div>
<a class="back" href="api.html">← All symbols</a>
</main>
<script src="ludic-highlight.js"></script>
<script>Ludic.highlightAll(); Ludic.installCards(); Ludic.flashTarget();</script>
</body></html>