Skip to content

Commit cb5ad10

Browse files
committed
Take programs from current dir
1 parent 106c639 commit cb5ad10

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ async def program(api):
1818
await api.print('Hello world!')
1919
```
2020

21+
There must be a separate file for each program with `program` coroutine defined.
22+
2123
In minecraft, open up any computer and type:
2224

2325
```bash
@@ -45,6 +47,3 @@ async def program(api):
4547
# and this snippet takes approximately 2 seconds to complete.
4648
await asyncio.gather(api.os.sleep(2), api.os.sleep(2))
4749
```
48-
49-
TODO:
50-
- use current dir for programs

computercraft/server.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from aiohttp import web
55
from traceback import print_exc
66
from os.path import getmtime, join, dirname, abspath
7-
from os import listdir
7+
from os import listdir, getcwd
88
import importlib
99
import argparse
1010

@@ -33,6 +33,7 @@
3333

3434
THIS_DIR = dirname(abspath(__file__))
3535
LUA_FILE = join(THIS_DIR, 'back.lua')
36+
CURRENT_DIR = getcwd()
3637

3738

3839
exchange = {}
@@ -57,11 +58,11 @@ async def lua_json(request):
5758

5859

5960
def program_filenames():
60-
return [f[:-3] for f in listdir(join(THIS_DIR, 'programs')) if f.endswith('.py') and f != '__init__.py']
61+
return [f[:-3] for f in listdir(CURRENT_DIR) if f.endswith('.py') and f != '__init__.py']
6162

6263

6364
def m_filename(m):
64-
return join(THIS_DIR, 'programs', '{}.py'.format(m))
65+
return join(CURRENT_DIR, '{}.py'.format(m))
6566

6667

6768
async def reload_all_modules(module_map):
@@ -74,7 +75,7 @@ async def reload_all_modules(module_map):
7475

7576
# loading new modules
7677
for m in nxt - prev:
77-
module_map[m] = importlib.import_module('programs.{}'.format(m))
78+
module_map[m] = importlib.import_module(m)
7879
module_map[m]._mtime_mark = getmtime(m_filename(m))
7980
print('Loaded {}'.format(m))
8081

0 commit comments

Comments
 (0)