Skip to content

Commit f1e5bcb

Browse files
committed
Address pr comments
1 parent 59391f7 commit f1e5bcb

1 file changed

Lines changed: 8 additions & 6 deletions

File tree

docs/src/howto/main_function.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
title: The Main Function
22
---
33

4-
All SPy programs must have a `main` function. The main function is the entry point of the program, and it is where the execution of the program begins.
4+
All SPy programs that are run in the interpreter or compiled must have a `main` function. The main function is the entry point of the program, and it is where the execution of the program begins.
55

66
```py
77
def main() -> None:
88
print("Hello world")
99
```
1010

11-
Not every `.spy` module needs a main function, but the module invoked by, e.g. `spy execute foo.spy` must contain a main function.
11+
Not every `.spy` module needs a main function, but the module invoked by, e.g. `spy foo.spy` `spy build foo.spy` must contain a main function.
12+
13+
Modules which are compiled as a library (e.g. `spy build --target lib foo.spy` or `--target py-cffi`) do not need a main function.
1214

1315
## Return Codes
1416

@@ -26,9 +28,9 @@ $ echo $?
2628
```
2729

2830

29-
## Passed Arguments (Interpretter Only)
31+
## Accessing Command Line Arguments
3032

31-
If the `main` function accepts a list of strings as an argument, the SPy program will accept arguments from the command line, both when running in interpretted
33+
If the `main` function accepts a list of strings as an argument, the SPy program will accept arguments from the command line, both when running in interpreted
3234

3335
```py
3436
#args.spy
@@ -40,11 +42,11 @@ $ uv run spy args.spy 999
4042
999
4143
```
4244

43-
As with CPython, args[0] is the name of the string passed to the uv runtime:
45+
As with CPython, args[0] is the name of the string passed to the uv runtime. This is the equivalent of CPython's `sys.argv`:
4446

4547
```py
4648
#argname.spy
47-
def main(args: list[str]) -> None:
49+
def main(argv: list[str]) -> None:
4850
print(args[0])
4951
```
5052
```

0 commit comments

Comments
 (0)