Skip to content

Commit 106c639

Browse files
committed
Readme update
1 parent a8b6581 commit 106c639

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

README.md

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,50 @@
11
# Pythonized ComputerCraft API
22

3-
```
3+
First, you need to start a server:
4+
5+
```bash
6+
cd your_folder_with_programs
47
python -m computercraft.server
58
```
69

10+
Current directory is the place for your amazing programs.
11+
Server tracks files inside this directory and reloads if necessary.
12+
You don't (always) have to restart server if you change your programs.
13+
14+
Create simple program named `hello.py`:
15+
16+
```python
17+
async def program(api):
18+
await api.print('Hello world!')
19+
```
20+
21+
In minecraft, open up any computer and type:
22+
23+
```bash
24+
wget http://127.0.0.1:8080/ py
25+
py hello
26+
```
27+
28+
`py` is short Lua program that interacts with the server.
29+
Argument is the name of program without `.py`.
30+
In everything else it works exactly like native program on Lua.
31+
`api` object contains almost everything *as is* in ComputerCraft documentation:
32+
33+
```python
34+
async def program(api):
35+
await api.disk.eject('right')
36+
await api.print(await api.os.getComputerLabel())
37+
# ...
38+
```
39+
40+
Using python coroutines allows launching commands in parallel, effectively replacing `parallel` API:
41+
42+
```python
43+
async def program(api):
44+
# Since os.sleep is mostly waiting for events, it doesn't block execution of parallel threads
45+
# and this snippet takes approximately 2 seconds to complete.
46+
await asyncio.gather(api.os.sleep(2), api.os.sleep(2))
47+
```
48+
749
TODO:
850
- use current dir for programs

0 commit comments

Comments
 (0)