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.h API

  • C++ Integration Tutorials — embed daslang in a C++ host using the native daScript.h API

  • Macro 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.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.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.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.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.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.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.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.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.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.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.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