You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/howto/main_function.md
+8-6Lines changed: 8 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,14 +1,16 @@
1
1
title: The Main Function
2
2
---
3
3
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.
5
5
6
6
```py
7
7
defmain() -> None:
8
8
print("Hello world")
9
9
```
10
10
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.
12
14
13
15
## Return Codes
14
16
@@ -26,9 +28,9 @@ $ echo $?
26
28
```
27
29
28
30
29
-
## Passed Arguments (Interpretter Only)
31
+
## Accessing Command Line Arguments
30
32
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 ininterpretted
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 ininterpreted
32
34
33
35
```py
34
36
#args.spy
@@ -40,11 +42,11 @@ $ uv run spy args.spy 999
40
42
999
41
43
```
42
44
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`:
0 commit comments