Chasm scripts don't need a game engine. Top-level statements run directly — no def main() required. Useful for tools, data processing, build scripts, or learning the language.
Running a Script
chasm run script.chasm
The CLI compiles the script and runs the result immediately. Standard output goes to the terminal.
Compiling to C
chasm compile script.chasm
Produces script.c in the current directory. Compile it yourself:
cc -o my_program script.c -I$CHASM_HOME/runtime
./my_program
Example, Data Processing Tool
data = file_read("scores.txt")
total = 0
count = 0
i = 0
while i < data.len do
ch = data[i]
if ch == 10 do # newline
count = count + 1
end
i = i + 1
end
print("Bytes: #{data.len}")
print("Lines: #{count}")The WASM Target
Compile to WebAssembly for running in browsers or WASM runtimes:
chasm compile --target wasm script.chasm
This produces a .wat file (WebAssembly text format). Assemble it with:
wat2wasm script.wat -o script.wasm
Load in a browser with the provided JavaScript runtime:
<script type="module">
import { chasmLoad } from './runtime/chasm_wasm_rt.js'
const chasm = await chasmLoad('./script.wasm')
chasm.main()
</script>
WASM limitations
The WASM target supports strings, structs, and arrays. Engine-specific functions (draw_rectangle, key_down, etc.) are not available, WASM is for standalone logic only.
No Engine Globals
Without an engine, these are not available:
key_down,key_pressed,mouse_x,mouse_ydraw_*,clear_backgroundload_texture,load_font,load_soundscreen_width,screen_height,get_fps
Only the core built-ins work in standalone mode: math, strings, file I/O, print, assert.