8. Tutorials
This section provides hands-on tutorials organized by topic:
Language Tutorials — learn daslang syntax and standard library features
C Integration Tutorials — embed daslang in a C host using the
daScriptC.hAPIC++ Integration Tutorials — embed daslang in a C++ host using the native
daScript.hAPIMacro Tutorials — write compile-time code transformations using the daslang macro system
Module Tutorials — dasHV (HTTP), dasLLAMA (local LLM inference), dasOPENAI (LLM / OpenAI-compatible API), dasPUGIXML (XML), dasStbImage, dasAudio, dasMinfft (FFT / DCT), OpenGL / WebGL2 (graphics), dasPEG (parser generator)
8.1. Language Tutorials
These tutorials introduce daslang’s core features step by step.
Each comes with a companion .das file in tutorials/language/ that you
can run directly:
daslang.exe tutorials/language/01_hello_world.das
The tutorials are designed to be followed in order. Each one builds on concepts introduced in earlier tutorials.
- 8.1.1. Hello World
- 8.1.2. Variables and Types
- 8.1.3. Operators
- 8.1.4. Control Flow
- 8.1.5. Functions
- 8.1.6. Arrays
- 8.1.7. Strings
- 8.1.8. Structs
- 8.1.9. Enumerations and Bitfields
- 8.1.10. Tables
- 8.1.11. Tuples and Variants
- 8.1.12. Function Pointers
- 8.1.13. Blocks
- 8.1.14. Lambdas and Closures
- 8.1.15. Iterators and Generators
- 8.1.16. Modules and Program Structure
- 8.1.17. Move, Copy, and Clone
- 8.1.18. Classes and Inheritance
- 8.1.19. Generic Programming
- 8.1.20. Lifetime and Cleanup
- 8.1.21. Error Handling
- 8.1.22. Unsafe and Pointers
- 8.1.23. String Builder and Formatting
- 8.1.24. Pattern Matching
- 8.1.25. Annotations and Options
- 8.1.26. Contracts
- 8.1.27. Testing with dastest
- 8.1.28. LINQ — Language-Integrated Query
- 8.1.29. Functional Programming
- 8.1.30. JSON
- 8.1.31. Regular Expressions
- 8.1.32. Operator Overloading
- 8.1.33. Algorithm
- 8.1.34. Entity Component System (DECS)
- 8.1.35. Job Queue (jobque)
- 8.1.36. Pointers
- 8.1.37. Utility Patterns (defer + static_let)
- 8.1.38. Random Numbers
- 8.1.39. Dynamic Type Checking
- 8.1.40. Coroutines
- 8.1.41. Serialization (archive)
- 8.1.42. Testing Tools (faker + fuzzer)
- 8.1.43. Interfaces
- 8.1.44. Compiling and Running Programs at Runtime
- 8.1.45. Debug Agents
- 8.1.46. Cross-Context Services with apply_in_context
- 8.1.47. Data Walking with DapiDataWalker
- 8.1.48. Compile-Time Field Iteration with apply
- 8.1.49. Async / Await
- 8.1.50. Structure-of-Arrays (SOA)
- 8.1.51. Delegates
- 8.1.52. Option<T> and Result<T, E>
- 8.1.53. Command-Line Argument Parsing (clargs)
- 8.1.54. Glob Pattern Matching
- 8.1.55. LINQ over DECS
- 8.1.56. C#-style LINQ query syntax (
%linq!) - 8.1.57. TOML
- 8.1.58. Logger
8.2. Building from the Installed SDK
Once daslang is installed, you can build the integration tutorials — or your
own projects — against the SDK using CMake’s find_package(DAS).
8.3. C Integration Tutorials
These tutorials show how to embed daslang in a C application using the
daScriptC.h API. Each tutorial comes with a .c source file and a
companion .das script in tutorials/integration/c/.
The installed SDK ships with a standalone CMakeLists.txt that lets you
build all C tutorials directly against the SDK — see
Building Projects Against the Installed SDK.
- 8.3.1. C Integration: Hello World
- 8.3.2. C Integration: Calling daslang Functions
- 8.3.3. C Integration: Binding C Types
- 8.3.4. C Integration: Callbacks and Closures
- 8.3.5. C Integration: Unaligned ABI & Advanced
- 8.3.6. C Integration: Sandbox
- 8.3.7. C Integration: Context Variables
- 8.3.8. C Integration: Serialization
- 8.3.9. C Integration: AOT
- 8.3.10. C Integration: Threading
- 8.3.11. C Integration: Type Introspection
- 8.3.12. C Integration: Mock ECS
- 8.3.13. C Integration: Shared Modules
- 8.3.14. C Integration: Passing Arrays
8.4. C++ Integration Tutorials
These tutorials show how to embed daslang in a C++ application using the
native daScript.h API. Each tutorial comes with a .cpp source file
and a companion .das script in tutorials/integration/cpp/.
The installed SDK ships with a standalone CMakeLists.txt that lets you
build all C++ tutorials directly against the SDK — see
Building Projects Against the Installed SDK.
- 8.4.1. C++ Integration: Hello World
- 8.4.2. C++ Integration: Calling Functions
- 8.4.3. C++ Integration: Binding Functions
- 8.4.4. C++ Integration: Binding Types
- 8.4.5. C++ Integration: Binding Enumerations
- 8.4.6. C++ Integration: Low-Level Interop
- 8.4.7. C++ Integration: Callbacks
- 8.4.8. C++ Integration: Binding Methods
- 8.4.9. C++ Integration: Operators and Properties
- 8.4.10. C++ Integration: Custom Modules
- 8.4.11. C++ Integration: Context Variables
- 8.4.12. C++ Integration: Smart Pointers
- 8.4.13. C++ Integration: AOT Compilation
- 8.4.14. C++ Integration: Serialization
- 8.4.15. C++ Integration: Custom Annotations
- 8.4.16. C++ Integration: Sandbox
- 8.4.17. C++ Integration: Coroutines
- 8.4.18. C++ Integration: Dynamic Scripts
- 8.4.19. C++ Integration: Class Adapters
- 8.4.20. C++ Integration: Standalone Contexts
- 8.4.21. C++ Integration: Threading
- 8.4.22. C++ Integration: Namespace Integration
- 8.4.23. C++ Integration: Binding
shared_ptrviaHandle<T>
8.5. Macro Tutorials
These tutorials teach daslang’s compile-time macro system: call macros,
reader macros, function macros, and AST manipulation. Each tutorial has
two source files — a module (.das) that defines the macros and a
usage file that exercises them — because macros cannot be used in the same
module that defines them.
Run any tutorial from the project root:
daslang.exe tutorials/macros/01_call_macro.das
- 8.5.1. Macro Tutorial 1: Call Macros
- 8.5.2. Macro Tutorial 2: When Expression
- 8.5.3. Macro Tutorial 3: Function Macros
- 8.5.4. Macro Tutorial 4: Advanced Function Macros
- 8.5.5. Macro Tutorial 5: Tag Function Macros
- 8.5.6. Macro Tutorial 6: Structure Macros
- 8.5.7. Macro Tutorial 7: Block Macros
- 8.5.8. Macro Tutorial 8: Variant Macros
- 8.5.9. Macro Tutorial 9: For-Loop Macros
- 8.5.10. Macro Tutorial 10: Capture Macros
- 8.5.11. Macro Tutorial 11: Reader Macros
- 8.5.12. Macro Tutorial 12: Typeinfo Macros
- 8.5.13. Macro Tutorial 13: Enumeration Macros
- 8.5.14. Macro Tutorial 14: Pass Macro
- 8.5.15. Macro Tutorial 15: Type Macro
- 8.5.16. Macro Tutorial 16: Template Type Macro
- 8.5.17. Macro Tutorial 17: Quasi-quotation Reference
- 8.5.18. Macro Tutorial 18:
with_— locked binding of container slots - 8.5.19. Macro Tutorial 19: Custom module options
8.6. dasHV (HTTP / WebSocket) Tutorials
These tutorials cover the dashv module — HTTP client and server
bindings built on libhv. The
companion .das files are in tutorials/dasHV/.
Run any tutorial from the project root:
daslang.exe tutorials/dasHV/01_http_requests.das
8.7. dasLLAMA (CPU LLM Inference) Tutorials
These tutorials cover the dasllama module — CPU large-language-model
inference in pure daslang: loading GGUF models, tokenization, streaming
generation, chat with templates, sampling, sessions and memory, performance,
and the architecture registry. Everything is written against the public
dasllama/dasllama facade.
You’ll need a GGUF model file on disk (models are not shipped with the repo) —
a good tiny one is SmolLM2-135M-Instruct Q8_0 (~145 MB).
Run from the project root, always with -jit:
daslang.exe -jit tutorials/dasLLAMA/01_hello_generate.das -- path/to/model.gguf
- 8.7.1. dasLLAMA-01 — Hello, Generation
- 8.7.2. dasLLAMA-02 — Chat and Templates
- 8.7.3. dasLLAMA-03 — Sampling
- 8.7.4. dasLLAMA-04 — Sessions, the KV Cache, and Memory
- 8.7.5. dasLLAMA-05 — Performance
- 8.7.6. dasLLAMA-06 — The Architecture Registry
- 8.7.7. dasLLAMA-07 — Speech to Text
- 8.7.8. dasLLAMA-08 — Audio Chat
- 8.7.9. dasLLAMA-09 — Embeddings
8.8. dasOPENAI (OpenAI-compatible API) Tutorials
These tutorials cover the openai module — a pure-daslang client for
OpenAI-compatible APIs (OpenAI, Ollama, OpenRouter, Kokoro, …): chat,
conversations, structured outputs, function calling, embeddings, models,
audio, and streaming. Built on dashv (HTTP) and daslib/json_boost.
The companion .das files are in tutorials/dasOPENAI/ and run against a
local mock server, so no live LLM is required.
Run any tutorial from the project root:
daslang.exe tutorials/dasOPENAI/01_first_chat.das
- 8.8.1. OPENAI-01 — Your First Chat
- 8.8.2. OPENAI-02 — Conversations and Parameters
- 8.8.3. OPENAI-03 — Structured Outputs (JSON mode)
- 8.8.4. OPENAI-04 — Tools and Function Calling
- 8.8.5. OPENAI-05 — Embeddings and Models
- 8.8.6. OPENAI-06 — Audio (Speech and Transcription)
- 8.8.7. OPENAI-07 — Streaming Chat
- 8.8.8. OPENAI-08 — Vision (Image Input)
- 8.8.9. OPENAI-09 — Image Generation
- 8.8.10. OPENAI-10 — Moderations
- 8.8.11. OPENAI-11 — Legacy Completions
8.9. dasPUGIXML (XML) Tutorials
These tutorials cover the dasPUGIXML module — XML parsing, building,
XPath queries, and automatic struct serialization using
pugixml. The companion .das files are in
tutorials/dasPUGIXML/.
Run any tutorial from the project root:
daslang.exe tutorials/dasPUGIXML/01_parsing_and_navigation.das
8.10. dasStbImage (Image I/O) Tutorials
These tutorials cover the stbimage_boost module — image loading,
saving, format conversion, and pixel manipulation using
stb_image. The companion
.das files are in tutorials/dasStbImage/.
Run any tutorial from the project root:
daslang.exe tutorials/dasStbImage/01_loading_images.das
- 8.10.1. STBIMAGE-01 — Loading and Inspecting Images
- 8.10.2. STBIMAGE-02 — Saving and Encoding Images
- 8.10.3. STBIMAGE-03 — Image Transforms
- 8.10.4. STBIMAGE-04 — Pixel Access and Format Conversion
- 8.10.5. STBIMAGE-05 — Drawing and Alpha Blending
- 8.10.6. STBIMAGE-06 — TrueType Fonts
- 8.10.7. STBIMAGE-07 — HDR Images
8.11. dasSQLITE (SQL) Tutorials
These tutorials cover the daslib/sql + sqlite/sqlite_boost API
— RAII connection handling, the [sql_table] structure macro, and
the typed CRUD helpers built on top of it. The companion .das
files are in tutorials/sql/.
Run any tutorial from the project root:
daslang.exe tutorials/sql/01-version.das
- 8.11.1. SQL-01 — Hello dasSQLITE
- 8.11.2. SQL-02 — Declare a Table, Insert
- 8.11.3. SQL-03 — Auto-Increment Primary Key
- 8.11.4. SQL-04 — Reading Rows with
_sql - 8.11.5. SQL-05 — Parameter Binding
- 8.11.6. SQL-06 — Error Handling
- 8.11.7. SQL-07 — Anatomy of
_sql - 8.11.8. SQL-08 —
_wherePredicates: the Full Surface - 8.11.9. SQL-09 —
_selectProjections - 8.11.10. SQL-10 —
_order_byand_order_by_descending - 8.11.11. SQL-11 —
takeandskip: Paging - 8.11.12. SQL-12 —
distinct - 8.11.13. SQL-12b — Set operations
- 8.11.14. SQL-13 — Aggregates:
sum/avg/… - 8.11.15. SQL-14 —
_group_byand_having - 8.11.16. SQL-15 —
_join(inner equi-join) - 8.11.17. SQL-16 — All Join Shapes
- 8.11.18. SQL-17 — Subqueries
- 8.11.19. SQL-18 — NULL Handling:
Option<T>Everywhere - 8.11.20. SQL-19 — UPDATE
- 8.11.21. SQL-20 — DELETE
- 8.11.22. SQL-21 — UPSERT
- 8.11.23. SQL-22 — Transactions
- 8.11.24. SQL-23 — Foreign keys
- 8.11.25. SQL-24 — Indexes
- 8.11.26. SQL-25 — Defaults + computed columns
- 8.11.27. SQL-26 — Custom type adapters
- 8.11.28. SQL-27 — BLOB round-trip
- 8.11.29. SQL-28 — JSON and BLOB columns
- 8.11.30. SQL-29 — Column metadata
- 8.11.31. SQL-30 — Listing tables
- 8.11.32. SQL-31 — Views
- 8.11.33. SQL-32 — User-defined SQL scalar functions
- 8.11.34. SQL-33 — PRAGMA tuning
- 8.11.35. SQL-34 — Backup, VACUUM, integrity check
- 8.11.36. SQL-35 — Streaming results with
_each_sql - 8.11.37. SQL-36 —
ATTACH DATABASE: cross-DB queries - 8.11.38. SQL-37 — Bulk operations: making writes fast
- 8.11.39. SQL-38 — Concurrency: threads, contention
- 8.11.40. SQL-39 —
schema_from: struct mirrors the DB - 8.11.41. SQL-40 — FTS5 full-text search
- 8.11.42. SQL-41 — Triggers: DB-level callbacks
- 8.11.43. SQL-42 — multi-version ETL with schema_from
- 8.11.44. SQL-43 — versioned schema migrations
8.12. dasAudio (Audio) Tutorials
These tutorials cover the audio_boost module — audio playback,
3D spatial audio, effects, WAV I/O, and MIDI. The companion
.das files are in tutorials/dasAudio/.
Run any tutorial from the project root:
daslang.exe tutorials/dasAudio/01_hello_sound.das
- 8.12.1. AUDIO-01 — Hello Sound
- 8.12.2. AUDIO-02 — Playing Audio Files
- 8.12.3. AUDIO-03 — Sound Control
- 8.12.4. AUDIO-04 — 3D Spatial Audio
- 8.12.5. AUDIO-05 — Reverb and Effects
- 8.12.6. AUDIO-06 — Streaming Audio
- 8.12.7. AUDIO-07 — WAV File I/O
- 8.12.8. AUDIO-08 — MIDI Files
- 8.12.9. AUDIO-09 — Playback Status
- 8.12.10. AUDIO-10 — Global Controls
- 8.12.11. AUDIO-11 — Recording from the Microphone
8.13. dasMinfft (FFT / DCT) Tutorials
These tutorials cover the minfft module — fast FFT and DCT on
power-of-two lengths, plus the 8x8 block-DCT pipeline at the heart of
JPEG and MPEG. Companion .das files are in tutorials/dasMinfft/.
Run any tutorial from the project root:
daslang.exe tutorials/dasMinfft/01_real_fft.das
8.14. daStrudel (Live-Coding) Tutorials
These tutorials cover the strudel module — pattern-based live-coding
music with mini-notation, time algebra, per-voice effects, samples, SF2
soundfonts, MIDI playback, and live-reload. Companion .das files
are in tutorials/daStrudel/.
Run any tutorial from the project root:
daslang.exe tutorials/daStrudel/daStrudel_01_hello_pattern.das
For the strudel-to-strudel.cc feature comparison, see daslang strudel vs strudel.cc — Feature Comparison.
- 8.14.1. STRUDEL-01 — Hello Pattern
- 8.14.2. STRUDEL-02 — Mini-Notation Fundamentals
- 8.14.3. STRUDEL-03 — Mini-Notation Advanced
- 8.14.4. STRUDEL-04 — Time Manipulation
- 8.14.5. STRUDEL-05 — Euclidean Rhythms
- 8.14.6. STRUDEL-06 — Stacking & Combining
- 8.14.7. STRUDEL-07 — Per-Voice FX & Combinators
- 8.14.8. STRUDEL-08 — Effects & Filters
- 8.14.9. STRUDEL-09 — Signals & Modulation
- 8.14.10. STRUDEL-10 — ADSR & Envelope Shaping
- 8.14.11. STRUDEL-11 — Scales & Music Theory
- 8.14.12. STRUDEL-12 — Synthesis
- 8.14.13. STRUDEL-13 — Samples
- 8.14.14. STRUDEL-14 — SF2 SoundFont Playback
- 8.14.15. STRUDEL-15 — MIDI Files
- 8.14.16. STRUDEL-16 — Live-Reloading Patterns
- 8.14.17. STRUDEL-17 — HRTF: 3D Positional Override for Pan
- 8.14.18. STRUDEL-18 — SFX Lab: a procedural sound-effect workbench
- 8.14.19. STRUDEL-19 — One-Shots: Fire-and-Forget Stings on Events
8.15. OpenGL / WebGL2 Tutorials
A ladder of runnable OpenGL tutorials that mirror the
dasVulkan series shader-for-shader, to
the degree the WebGL2 portable floor allows. Every shader is written in
daslang – the same shared shader builtins (shader_lingua_franca) the
Vulkan rail uses – and lowered to GLSL (GLSL ES 3.00 on the web) at compile time
by dasGlsl. The same daslang shader language, lowered to a third backend.
Each tutorial is one homogeneous program: init / update /
shutdown plus a main driver. On the desktop main() runs the loop in a
GLFW window; on the web the wasm run path drives the three lifecycle functions
from the browser’s animation frame (the daslang Context persists across
frames), so the very same .das runs live in the playground. That live,
click-to-run version in the browser is what the OpenGL rail offers over the
Vulkan tutorials’ recorded video.
The series builds graphics → fragment compute → 3D scene → instancing → environment → multi-pass → modern post. WebGL2 has no compute / SSBO / indirect draw / mesh shaders, so the Vulkan rungs that depend on those (gpu-driven, mesh-shader) have no WebGL2 mirror – and drawing that boundary explicitly is part of the harmonization story: one shader language, one ladder, three backends, with the portable floor made visible.
Run any tutorial from the project root:
daslang.exe tutorials/opengl/01_triangle/01_triangle.das
- 8.15.1. 01 - The Rotating Triangle
- 8.15.2. 02 - The Mandelbrot Set
- 8.15.3. 03 - Signed-Distance-Field Raymarcher
- 8.15.4. 04 - The Synthwave Cube
- 8.15.5. 05 - The Cube Swarm
- 8.15.6. 06 - The Skybox
- 8.15.7. 07 - The Particle Swarm
- 8.15.8. 08 - The Shadow Map
- 8.15.9. 09 - Multisample Anti-Aliasing
- 8.15.10. 10 - Deferred Shading + MRT
- 8.15.11. 11 - HDR + Bloom
- 8.15.12. 12 - glTF PBR Capstone
8.16. JSON-RPC 2.0 Tutorials
These tutorials cover daslib/jsonrpc — the transport-agnostic
JSON-RPC 2.0 library: building requests, implementing servers with
dispatch_line, and the §6 batch semantics. The companion .das
files are in tutorials/jsonrpc/.
Run any tutorial from the project root:
daslang.exe tutorials/jsonrpc/01_request_response.das
8.17. dasPEG (Parser Generator) Tutorials
These tutorials cover the peg module — daslang’s built-in PEG
(Parsing Expression Grammar) parser generator. Define grammars
directly in daslang using the parse macro; the compiler generates
a packrat parser at compile time.
The companion .das files are in tutorials/dasPEG/.
Run any tutorial from the project root:
daslang.exe tutorials/dasPEG/01_hello_parser.das