ludic/docs/language/structure/kw-import.md
Orkuncakilkaya f92d7f89c6 feat(tooling): JetBrains IDE support, LSP navigation, barrel imports, package scripts and hooks
- JetBrains plugin 1.4.0: semantic colours (builtin / vendor / own), template strings,
  brace handling, run configurations and a test console, package.ludic and
  package.lock.ludic editing (completion, docs, app preview, colour previews, asset
  navigation), External Libraries for the runtime and packages, doc pages for built-ins
- ludic-lsp: go to definition for imports, document links, hover with inferred types,
  type definition, signature help with parameters, docs from docs/language
- `import "dir"` resolves a barrel `dir/index.ludic`
- package.ludic `entry`, `script` and `hook before|after <command>`; `ludic <script>`,
  `ludic script`, `ludic scripts`
- `ludic test --verbose` and `--test NAME`; the test runner filters by name

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-16 16:13:31 +03:00

1.5 KiB

id name category kind tokens sig tip order
kw-import import structure keyword import import "file.ludic" Splice another Ludic file's declarations into this program. 10

An import pulls the declarations of another Ludic file into this program, letting you split a game across many files instead of one giant block. The imported file is a fragment — bare declarations with no program wrapper — and its contents are spliced in as if written here. Paths resolve relative to the importing file, imports may nest, and each resolved path is include-guarded, so importing the same file twice (even through different chains) pulls it in exactly once. Diagnostics still point at the real source file, so errors in an imported fragment report that file's name and line.

A path without .ludic names a directory through its barrel, index.ludic: import "camp" reads camp/index.ludic, which lists the directory's modules with imports relative to itself. import "dir/*.ludic" instead takes every file in the directory, in name order.

# doc-check: skip — illustrative; the imported paths are example files, not
# resolvable when this snippet is checked in isolation.
program ChronoRift {
  import "chronorift/world.ludic"     # properties and models
  import "chronorift/combat.ludic"    # the battle handlers

  handler Boot phase Start {
    spawn Hero { Position { column: 4, row: 4 } }
  }
}