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), dasOPENAI (LLM / OpenAI-compatible API), dasPUGIXML (XML), dasStbImage, dasAudio, dasMinfft (FFT / DCT), 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. 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.7.1. OPENAI-01 — Your First Chat
- 8.7.2. OPENAI-02 — Conversations and Parameters
- 8.7.3. OPENAI-03 — Structured Outputs (JSON mode)
- 8.7.4. OPENAI-04 — Tools and Function Calling
- 8.7.5. OPENAI-05 — Embeddings and Models
- 8.7.6. OPENAI-06 — Audio (Speech and Transcription)
- 8.7.7. OPENAI-07 — Streaming Chat
- 8.7.8. OPENAI-08 — Vision (Image Input)
- 8.7.9. OPENAI-09 — Image Generation
- 8.7.10. OPENAI-10 — Moderations
- 8.7.11. OPENAI-11 — Legacy Completions
8.8. 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.9. 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.9.1. STBIMAGE-01 — Loading and Inspecting Images
- 8.9.2. STBIMAGE-02 — Saving and Encoding Images
- 8.9.3. STBIMAGE-03 — Image Transforms
- 8.9.4. STBIMAGE-04 — Pixel Access and Format Conversion
- 8.9.5. STBIMAGE-05 — Drawing and Alpha Blending
- 8.9.6. STBIMAGE-06 — TrueType Fonts
- 8.9.7. STBIMAGE-07 — HDR Images
8.10. 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.10.1. SQL-01 — Hello dasSQLITE
- 8.10.2. SQL-02 — Declare a Table, Insert
- 8.10.3. SQL-03 — Auto-Increment Primary Key
- 8.10.4. SQL-04 — Reading Rows with
_sql - 8.10.5. SQL-05 — Parameter Binding
- 8.10.6. SQL-06 — Error Handling
- 8.10.7. SQL-07 — Anatomy of
_sql - 8.10.8. SQL-08 —
_wherePredicates: the Full Surface - 8.10.9. SQL-09 —
_selectProjections - 8.10.10. SQL-10 —
_order_byand_order_by_descending - 8.10.11. SQL-11 —
takeandskip: Paging - 8.10.12. SQL-12 —
distinct - 8.10.13. SQL-12b — Set operations
- 8.10.14. SQL-13 — Aggregates:
sum/avg/… - 8.10.15. SQL-14 —
_group_byand_having - 8.10.16. SQL-15 —
_join(inner equi-join) - 8.10.17. SQL-16 — All Join Shapes
- 8.10.18. SQL-17 — Subqueries
- 8.10.19. SQL-18 — NULL Handling:
Option<T>Everywhere - 8.10.20. SQL-19 — UPDATE
- 8.10.21. SQL-20 — DELETE
- 8.10.22. SQL-21 — UPSERT
- 8.10.23. SQL-22 — Transactions
- 8.10.24. SQL-23 — Foreign keys
- 8.10.25. SQL-24 — Indexes
- 8.10.26. SQL-25 — Defaults + computed columns
- 8.10.27. SQL-26 — Custom type adapters
- 8.10.28. SQL-27 — BLOB round-trip
- 8.10.29. SQL-28 — JSON and BLOB columns
- 8.10.30. SQL-29 — Column metadata
- 8.10.31. SQL-30 — Listing tables
- 8.10.32. SQL-31 — Views
- 8.10.33. SQL-32 — User-defined SQL scalar functions
- 8.10.34. SQL-33 — PRAGMA tuning
- 8.10.35. SQL-34 — Backup, VACUUM, integrity check
- 8.10.36. SQL-35 — Streaming results with
_each_sql - 8.10.37. SQL-36 —
ATTACH DATABASE: cross-DB queries - 8.10.38. SQL-37 — Bulk operations: making writes fast
- 8.10.39. SQL-38 — Concurrency: threads, contention
- 8.10.40. SQL-39 —
schema_from: struct mirrors the DB - 8.10.41. SQL-40 — FTS5 full-text search
- 8.10.42. SQL-41 — Triggers: DB-level callbacks
- 8.10.43. SQL-42 — multi-version ETL with schema_from
- 8.10.44. SQL-43 — versioned schema migrations
8.11. 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.11.1. AUDIO-01 — Hello Sound
- 8.11.2. AUDIO-02 — Playing Audio Files
- 8.11.3. AUDIO-03 — Sound Control
- 8.11.4. AUDIO-04 — 3D Spatial Audio
- 8.11.5. AUDIO-05 — Reverb and Effects
- 8.11.6. AUDIO-06 — Streaming Audio
- 8.11.7. AUDIO-07 — WAV File I/O
- 8.11.8. AUDIO-08 — MIDI Files
- 8.11.9. AUDIO-09 — Playback Status
- 8.11.10. AUDIO-10 — Global Controls
8.12. 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.13. 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.13.1. STRUDEL-01 — Hello Pattern
- 8.13.2. STRUDEL-02 — Mini-Notation Fundamentals
- 8.13.3. STRUDEL-03 — Mini-Notation Advanced
- 8.13.4. STRUDEL-04 — Time Manipulation
- 8.13.5. STRUDEL-05 — Euclidean Rhythms
- 8.13.6. STRUDEL-06 — Stacking & Combining
- 8.13.7. STRUDEL-07 — Per-Voice FX & Combinators
- 8.13.8. STRUDEL-08 — Effects & Filters
- 8.13.9. STRUDEL-09 — Signals & Modulation
- 8.13.10. STRUDEL-10 — ADSR & Envelope Shaping
- 8.13.11. STRUDEL-11 — Scales & Music Theory
- 8.13.12. STRUDEL-12 — Synthesis
- 8.13.13. STRUDEL-13 — Samples
- 8.13.14. STRUDEL-14 — SF2 SoundFont Playback
- 8.13.15. STRUDEL-15 — MIDI Files
- 8.13.16. STRUDEL-16 — Live-Reloading Patterns
- 8.13.17. STRUDEL-17 — HRTF: 3D Positional Override for Pan
- 8.13.18. STRUDEL-18 — SFX Lab: a procedural sound-effect workbench
- 8.13.19. STRUDEL-19 — One-Shots: Fire-and-Forget Stings on Events
8.14. 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.15. 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