Write and run Lua code directly from Python files.
Project description
LuaWrap
Write and run Lua code directly inside your Python files — no separate Lua install needed.
Installation
pip install LuaWrap
How to Use
All your Lua code goes inside a string passed to lua(). Use triple quotes """ to write
multiple lines, just like a normal Lua script:
from LuaWrap import lua
lua("""
local var1 = 10
local var2 = 20
print("The sum of var1 and var2 is: " .. (var1 + var2))
""")
That's the main way to use LuaWrap! Write as many lines of Lua as you want inside the quotes.
Important: Do NOT write Lua code directly in the Python file — it must always be inside a string passed to
lua(). Pylance will show errors if you write Lua outside of strings.
More Ways to Use It
Get a value back in Python:
from LuaWrap import run_lua
result = run_lua("return 2 + 2")
print(result) # 4
Reusable Lua functions with @lua_function:
from LuaWrap import lua_function
@lua_function
def say_hello():
return """
local name = "World"
print("Hello, " .. name .. "!")
"""
say_hello() # call it like a normal Python function
Block style with LuaBlock:
from LuaWrap import LuaBlock
with LuaBlock() as lb:
lb.code = """
for i = 1, 5 do
print("Number: " .. i)
end
"""
# Lua runs automatically when the block ends
API
| Tool | What it does |
|---|---|
lua("...") |
Run Lua code from a string — the main way to use LuaWrap |
run_lua("...") |
Same as lua(), but also returns the result to Python |
@lua_function |
Decorator — wrap a Python function that returns Lua code as a string |
LuaBlock |
Context manager — set lb.code to your Lua string, runs on exit |
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file luawrap-0.1.3.tar.gz.
File metadata
- Download URL: luawrap-0.1.3.tar.gz
- Upload date:
- Size: 2.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.14.3 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
79e36ab121fa7e0706dfb15eba5c0d8de3e3706e7a4c03471420f3f1662529e0
|
|
| MD5 |
e75760e2c78eade7babead74d9486a9e
|
|
| BLAKE2b-256 |
df3359aa96884d64f18d7d5ef4ed730bb56e031967f21557454acb980b1b5cef
|
File details
Details for the file luawrap-0.1.3-py3-none-any.whl.
File metadata
- Download URL: luawrap-0.1.3-py3-none-any.whl
- Upload date:
- Size: 3.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.4.1 CPython/3.14.3 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a401b28861f3cee52b060b84de7557ad08617e79244cd489234bba7913542396
|
|
| MD5 |
4cd212044be5f67f290e131feba13728
|
|
| BLAKE2b-256 |
1fafdbd195e90eec5c65043bccd3b1162b6b9fba84844e181591d9c41301f89d
|