https://github.com/steve3184/minecraft_lua
Lua Compiler for Minecraft Datapacks
https://github.com/steve3184/minecraft_lua
compiler lua minecraft
Last synced: about 1 month ago
JSON representation
Lua Compiler for Minecraft Datapacks
- Host: GitHub
- URL: https://github.com/steve3184/minecraft_lua
- Owner: Steve3184
- License: gpl-3.0
- Created: 2024-12-28T04:05:01.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-12-28T07:12:22.000Z (over 1 year ago)
- Last Synced: 2025-08-17T10:39:59.787Z (11 months ago)
- Topics: compiler, lua, minecraft
- Language: Python
- Homepage:
- Size: 38.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mclua - Lua Compiler for Minecraft Datapacks
Up to now, the compiler does not have full Lua language support, and there is a variable scope problem, which cannot be used for large-scale projects.
If you can help with the development, please submit a Pull Request.
## features
- [x] Variable defines (basic types)
- [x] Function defines (need define types for arguments)
- [x] Function calls
- [x] print/command functions (use `command("")` to execute Minecraft commands)
- [x] String combines (two strings one time)
- [x] For in/While/Repeat
- [x] If/Else
- [ ] advanced math functions
- [ ] better performance
- [ ] variable local range
...
## installation
on Linux/Mac OS:
```sh
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
```
on Windows (PowerShell):
```powershell
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
python -m venv .venv
.venv\bin\activate.ps1
pip install -r requirements.txt
```
you need to delete `print(val)` to remove the debug output.
( at `.venv/lib/python3.*/site-packages/luaparser/ast.py` line 37)
## usage
Build with:
```sh
# Compile *.lua to a datapack
# This toll won't zip the datapack, it only output a directory
python datapack.py "input file" "output dir" "pack id"
# Compile *.lua to some mcfunction files
python compile.py "input file" "output dir" "pack id" # pack id is optional
```
Run in minecraft:
```mcfunction
/function mclua:util/init_stroage
/function mclua:util/init_score
/function output:main # replace "output" with your pack id
/function mclua:util/remove_stroage
```
## examples

```lua
a = "hello world!"
function hello( arg1__string )
aa = "func:" + arg1
print(aa)
return aa
end
hello(a)
c = 123 % 5
if c == 3 then
print("right!")
else
print("wrong!")
end
for i=0,3,1 do
j = str(i)
j = "Counter: " + j
print(j)
end
print("mclua demo end")
```
### License: [GPL-3.0](LICENSE)