7. 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), dasPUGIXML (XML), dasStbImage, dasAudio, dasPEG (parser generator)
7.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.
- 7.1.1. Hello World
- 7.1.2. Variables and Types
- 7.1.3. Operators
- 7.1.4. Control Flow
- 7.1.5. Functions
- 7.1.6. Arrays
- 7.1.7. Strings
- 7.1.8. Structs
- 7.1.9. Enumerations and Bitfields
- 7.1.10. Tables
- 7.1.11. Tuples and Variants
- 7.1.12. Function Pointers
- 7.1.13. Blocks
- 7.1.14. Lambdas and Closures
- 7.1.15. Iterators and Generators
- 7.1.16. Modules and Program Structure
- 7.1.17. Move, Copy, and Clone
- 7.1.18. Classes and Inheritance
- 7.1.19. Generic Programming
- 7.1.20. Lifetime and Cleanup
- 7.1.21. Error Handling
- 7.1.22. Unsafe and Pointers
- 7.1.23. String Builder and Formatting
- 7.1.24. Pattern Matching
- 7.1.25. Annotations and Options
- 7.1.26. Contracts
- 7.1.27. Testing with dastest
- 7.1.28. LINQ — Language-Integrated Query
- 7.1.29. Functional Programming
- 7.1.30. JSON
- 7.1.31. Regular Expressions
- 7.1.32. Operator Overloading
- 7.1.33. Algorithm
- 7.1.34. Entity Component System (DECS)
- 7.1.35. Job Queue (jobque)
- 7.1.36. Pointers
- 7.1.37. Utility Patterns (defer + static_let)
- 7.1.38. Random Numbers
- 7.1.39. Dynamic Type Checking
- 7.1.40. Coroutines
- 7.1.41. Serialization (archive)
- 7.1.42. Testing Tools (faker + fuzzer)
- 7.1.43. Interfaces
- 7.1.44. Compiling and Running Programs at Runtime
- 7.1.45. Debug Agents
- 7.1.46. Cross-Context Services with apply_in_context
- 7.1.47. Data Walking with DapiDataWalker
- 7.1.48. Compile-Time Field Iteration with apply
- 7.1.49. Async / Await
- 7.1.50. Structure-of-Arrays (SOA)
- 7.1.51. Delegates
- 7.1.52. Option<T> and Result<T, E>
- 7.1.53. Command-Line Argument Parsing (clargs)
7.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).
7.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.
- 7.3.1. C Integration: Hello World
- 7.3.2. C Integration: Calling daslang Functions
- 7.3.3. C Integration: Binding C Types
- 7.3.4. C Integration: Callbacks and Closures
- 7.3.5. C Integration: Unaligned ABI & Advanced
- 7.3.6. C Integration: Sandbox
- 7.3.7. C Integration: Context Variables
- 7.3.8. C Integration: Serialization
- 7.3.9. C Integration: AOT
- 7.3.10. C Integration: Threading
- 7.3.11. C Integration: Type Introspection
- 7.3.12. C Integration: Mock ECS
- 7.3.13. C Integration: Shared Modules
7.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.
- 7.4.1. C++ Integration: Hello World
- 7.4.2. C++ Integration: Calling Functions
- 7.4.3. C++ Integration: Binding Functions
- 7.4.4. C++ Integration: Binding Types
- 7.4.5. C++ Integration: Binding Enumerations
- 7.4.6. C++ Integration: Low-Level Interop
- 7.4.7. C++ Integration: Callbacks
- 7.4.8. C++ Integration: Binding Methods
- 7.4.9. C++ Integration: Operators and Properties
- 7.4.10. C++ Integration: Custom Modules
- 7.4.11. C++ Integration: Context Variables
- 7.4.12. C++ Integration: Smart Pointers
- 7.4.13. C++ Integration: AOT Compilation
- 7.4.14. C++ Integration: Serialization
- 7.4.15. C++ Integration: Custom Annotations
- 7.4.16. C++ Integration: Sandbox
- 7.4.17. C++ Integration: Coroutines
- 7.4.18. C++ Integration: Dynamic Scripts
- 7.4.19. C++ Integration: Class Adapters
- 7.4.20. C++ Integration: Standalone Contexts
- 7.4.21. C++ Integration: Threading
- 7.4.22. C++ Integration: Namespace Integration
- 7.4.23. C++ Integration: Binding
shared_ptrviaHandle<T>
7.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
- 7.5.1. Macro Tutorial 1: Call Macros
- 7.5.2. Macro Tutorial 2: When Expression
- 7.5.3. Macro Tutorial 3: Function Macros
- 7.5.4. Macro Tutorial 4: Advanced Function Macros
- 7.5.5. Macro Tutorial 5: Tag Function Macros
- 7.5.6. Macro Tutorial 6: Structure Macros
- 7.5.7. Macro Tutorial 7: Block Macros
- 7.5.8. Macro Tutorial 8: Variant Macros
- 7.5.9. Macro Tutorial 9: For-Loop Macros
- 7.5.10. Macro Tutorial 10: Capture Macros
- 7.5.11. Macro Tutorial 11: Reader Macros
- 7.5.12. Macro Tutorial 12: Typeinfo Macros
- 7.5.13. Macro Tutorial 13: Enumeration Macros
- 7.5.14. Macro Tutorial 14: Pass Macro
- 7.5.15. Macro Tutorial 15: Type Macro
- 7.5.16. Macro Tutorial 16: Template Type Macro
- 7.5.17. Macro Tutorial 17: Quasi-quotation Reference
7.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
7.7. 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
7.8. 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
7.9. 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
- 7.9.1. SQL-01 — Hello dasSQLITE
- 7.9.2. SQL-02 — Declare a Table, Insert
- 7.9.3. SQL-03 — Auto-Increment Primary Key
- 7.9.4. SQL-04 — Reading Rows with
_sql - 7.9.5. SQL-05 — Parameter Binding
- 7.9.6. SQL-06 — Error Handling
- 7.9.7. SQL-07 — Anatomy of
_sql - 7.9.8. SQL-08 —
_wherePredicates: the Full Surface - 7.9.9. SQL-09 —
_selectProjections - 7.9.10. SQL-10 —
_order_byand_order_by_descending - 7.9.11. SQL-11 —
takeandskip: Paging - 7.9.12. SQL-12 —
distinct - 7.9.13. SQL-12b — Set operations
- 7.9.14. SQL-13 — Aggregates:
sum/avg/… - 7.9.15. SQL-14 —
_group_byand_having - 7.9.16. SQL-15 —
_join(inner equi-join) - 7.9.17. SQL-16 —
_left_joinwithOption<TB> - 7.9.18. SQL-17 — Subqueries
- 7.9.19. SQL-18 — NULL Handling:
Option<T>Everywhere - 7.9.20. SQL-19 — UPDATE
- 7.9.21. SQL-20 — DELETE
- 7.9.22. SQL-21 — UPSERT
- 7.9.23. SQL-22 — Transactions
- 7.9.24. SQL-23 — Foreign keys
- 7.9.25. SQL-24 — Indexes
- 7.9.26. SQL-25 — Defaults + computed columns
- 7.9.27. SQL-26 — Custom type adapters
- 7.9.28. SQL-27 — BLOB round-trip
- 7.9.29. SQL-28 — JSON and BLOB columns
- 7.9.30. SQL-29 — Column metadata
- 7.9.31. SQL-30 — Listing tables
- 7.9.32. SQL-31 — Views
- 7.9.33. SQL-32 — User-defined SQL scalar functions
- 7.9.34. SQL-33 — PRAGMA tuning
- 7.9.35. SQL-34 — Backup, VACUUM, integrity check
- 7.9.36. SQL-35 — Streaming results with
_each_sql - 7.9.37. SQL-36 —
ATTACH DATABASE: cross-DB queries - 7.9.38. SQL-37 — Bulk operations: making writes fast
- 7.9.39. SQL-38 — Concurrency: threads, contention
- 7.9.40. SQL-40 — FTS5 full-text search
- 7.9.41. SQL-41 — Triggers: DB-level callbacks
7.10. 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
7.11. 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.
- 7.11.1. STRUDEL-01 — Hello Pattern
- 7.11.2. STRUDEL-02 — Mini-Notation Fundamentals
- 7.11.3. STRUDEL-03 — Mini-Notation Advanced
- 7.11.4. STRUDEL-04 — Time Manipulation
- 7.11.5. STRUDEL-05 — Euclidean Rhythms
- 7.11.6. STRUDEL-06 — Stacking & Combining
- 7.11.7. STRUDEL-07 — Per-Voice FX & Combinators
- 7.11.8. STRUDEL-08 — Effects & Filters
- 7.11.9. STRUDEL-09 — ADSR & Envelope Shaping
- 7.11.10. STRUDEL-10 — Scales & Music Theory
- 7.11.11. STRUDEL-11 — Synthesis
- 7.11.12. STRUDEL-12 — Samples
- 7.11.13. STRUDEL-13 — SF2 SoundFont Playback
- 7.11.14. STRUDEL-14 — MIDI Files
- 7.11.15. STRUDEL-15 — Live-Reloading Patterns
- 7.11.16. STRUDEL-16 — HRTF: 3D Positional Override for Pan
7.12. 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