|
1 | | -# PyLua - Embedded Python Interpreter for Luau |
| 1 | +# PyLua - Embedded Python for Luau |
2 | 2 |
|
3 | | -> Notice: For v0.2 docs, see [docs/0.2/README.md](docs/0.2/README.md). |
| 3 | +> For v0.2 docs, see [docs/0.2/README.md](docs/0.2/README.md). |
4 | 4 |
|
5 | | -PyLua lets you run Python inside Luau (e.g., Roblox). The v0.3 rewrite is a proper interpreter built in Luau with a CPython-inspired design. |
| 5 | +Run Python inside Luau (e.g., Roblox). PyLua 0.3 is a compact, CPython‑inspired interpreter you can embed in Luau projects. |
6 | 6 |
|
7 | | -## What is it? |
| 7 | +## Highlights |
8 | 8 |
|
9 | | -- A Python 3.12-and-below interpreter implemented in Luau |
10 | | -- Runs on [Lute] and other Luau-compatible runtimes |
11 | | -- Embeddable API for executing/evaluating Python and sharing values via `globals()` |
| 9 | +- Python 3.12 (and below) semantics where practical |
| 10 | +- Works with [Lute] and Luau runtimes (Roblox Studio, etc.) |
| 11 | +- Simple API: execute/eval and share values via `globals()` |
| 12 | +- CPython‑style pipeline (lexer → parser → AST → bytecode → VM) |
12 | 13 |
|
13 | | -## Use cases |
| 14 | +## Quick start |
14 | 15 |
|
15 | | -- Author gameplay logic in Python while running on Luau |
16 | | -- Build modding hooks: expose Luau callbacks to Python scripts |
17 | | -- Teach/prototype Python inside Roblox-like environments |
18 | | -- Explore interpreter architecture (tokens → AST → bytecode → VM) |
| 16 | +Run an example from the repo root (requires Lute in PATH): |
19 | 17 |
|
20 | | -## How it’s built |
21 | | - |
22 | | -Interpreter pipeline: |
| 18 | +```powershell |
| 19 | +lute examples/hello_world.luau |
| 20 | +``` |
23 | 21 |
|
24 | | -- Lexer → Parser → AST → Compiler → Bytecode → VM |
| 22 | +Embed and run a bit of Python: |
25 | 23 |
|
26 | | -Key modules (see `src/PyLua/`): |
| 24 | +```lua |
| 25 | +local PyLua = require("./src/PyLua") |
| 26 | +local py = PyLua.new() |
27 | 27 |
|
28 | | -- `lexer.luau`, `parser/` – Python-compliant tokenization and parsing |
29 | | -- `compiler.luau` – compile AST to bytecode |
30 | | -- `vm/` – stack-based virtual machine |
31 | | -- `objects/` – Python object model |
32 | | -- `builtins/` – core built-in functions and types |
| 28 | +py:execute([[x = 2 + 3]]) |
| 29 | +print(py:getGlobal("x")) -- 5 |
33 | 30 |
|
34 | | -## Status |
| 31 | +local result = py:eval("sum([1, 2, 3])") |
| 32 | +print(result) -- 6 |
| 33 | +``` |
35 | 34 |
|
36 | | -- Version: `0.3.0-dev3` |
37 | | -- Target: Python 3.12 syntax and below (3.13+ out of scope) |
38 | | -- Roadmap: `internalDocs/REWRITE_PLAN.md` |
| 35 | +## Docs and examples |
39 | 36 |
|
40 | | -## Get started |
| 37 | +- Docs index: `docs/README.md` |
| 38 | +- Architecture overview: `docs/ARCHITECTURE.md` |
| 39 | +- Examples: `examples/` |
41 | 40 |
|
42 | | -See docs and examples for usage and API details: |
| 41 | +## Status |
43 | 42 |
|
44 | | -- Docs home: `docs/README.md` |
45 | | -- Examples: `docs/examples/` |
| 43 | +- Version: `0.3.0` |
| 44 | +- Target: Python 3.12 and below (3.13+ out of scope) |
| 45 | +- Roadmap: `internalDocs/ROADMAP.md` |
46 | 46 |
|
47 | | -You can also quickly try an example with Lute from the repo root: |
| 47 | +## Contributing |
48 | 48 |
|
49 | | -```bash |
50 | | -lute examples/hello_world.luau |
51 | | -``` |
| 49 | +Issues and PRs welcome. See `CONTRIBUTING.md` for guidelines. |
52 | 50 |
|
53 | 51 | ## License |
54 | 52 |
|
55 | | -MIT - see [`LICENSE`](./LICENSE). |
| 53 | +MIT — see [`LICENSE`](./LICENSE). |
56 | 54 |
|
57 | 55 | [Lute]: https://github.com/luau-lang/lute |
0 commit comments