File size: 4,145 Bytes
d086025
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# `dragon` CLI reference

The `dragon` executable is the entry point for running, compiling and editing
Dragon programs. Its behaviour is chosen by the first argument (a script path,
a subcommand, or a flag).

```
dragon <command | file.dgn> [options] [args...]
```

---

## Commands

| Invocation | Effect |
| --- | --- |
| `dragon <file.dgn> [args...]` | Run a Dragon script. Extra arguments are passed to the script as `argv`. |
| `dragon --repl` | Start the interactive REPL. |
| `dragon run` | Run the project described by `./package.json`. |
| `dragon -c <file.dgn> -o <out>` | Compile/bundle a script into an executable or library. |
| `dragon --ide` | Launch the TurboDragon terminal IDE. |
| `dragon -v`, `dragon --version` | Print version information and exit. |

---

## Running a script

```bash
dragon hello.dgn
dragon hello.dgn Alice 42 --verbose
```

* Input: a UTF-8 `.dgn` source file.
* Output: whatever the program prints with `show` / `showln` on **stdout**
  (errors and diagnostics are reported on stderr, with the offending line
  highlighted).
* Everything after the file name is delivered to the program as the `argv`
  list, so scripts can read their own command-line arguments.

---

## Interactive REPL

```bash
dragon --repl
```

A persistent session: variables, functions and classes defined on one line stay
available on the next. Type `exit` to quit.

---

## Running a project: `dragon run`

```bash
dragon run
```

Looks for a `package.json` in the current directory and runs the file named by
its `"main"` field (the `"entry"` field is accepted as an alias).

```json
{
  "name": "my-dragon-app",
  "main": "src/main.dgn"
}
```

Input format: a JSON object with a `name` and a `main`/`entry` path relative to
the directory containing `package.json`.

---

## Compiling a script: `-c` / `-o`

```bash
# Bundle a script (and everything it imports) into one distributable executable
dragon -c input.dgn -o output

# GUI/background mode: do not attach a console window on Windows
dragon -c input.dgn -o output --window

# Build a shared library instead of an executable
dragon -c input.dgn -o output.dll --lib      # .so / .dylib on Linux / macOS

# (Experimental) transpile to C and build a native binary with gcc/clang/MSVC
dragon -c input.dgn -o output --native

# (Experimental) native shared library
dragon -c input.dgn -o output --native --lib

# Keep the intermediate generated C source when using --native
dragon -c input.dgn -o output --native --keep-c
```

| Option | Meaning |
| --- | --- |
| `-c <file.dgn>` | Compile mode; the value is the input script. |
| `-o <path>` | Output file name (omit the extension for an executable; add `.dll` / `.so` / `.dylib` with `--lib`). |
| `--lib` | Produce a shared library that can be embedded in another application. |
| `--native` | Experimental: build the program with your system C compiler instead of bundling it. Requires `gcc`, `clang`, or `cl` on `PATH`. |
| `--keep-c` | With `--native`, leave the generated C source on disk for inspection. |
| `--window` | Windows only: start without a console window (GUI/background application). |

Notes:

* Bundled executables are **self-contained**: the script plus everything it
  imports is packaged inside the single output file, which can be distributed
  to machines that do not have Dragon installed.
* `--native` produces an ordinary platform binary built by your C compiler,
  which starts faster than a bundled script because no translation happens when
  the program is launched.

---

## TurboDragon IDE

```bash
dragon --ide
```

A lightweight, keyboard-driven terminal editor/runner: edit a script and run it
without leaving the terminal.

---

## Output formats summary

| Mode | Artifact produced |
| --- | --- |
| run | none (program output on stdout) |
| `--repl` | none (session state is in-memory) |
| `-c ... -o out` | `out` (native executable / bundled binary) |
| `-c ... -o out --lib` | `out.dll` / `libout.so` / `out.dylib` |
| `-c ... -o out --native` | platform executable built by the system C compiler |
| `-c ... -o out --native --keep-c` | executable + retained generated C source |