Skip to main content

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

WARNING:

This is not tested completely, bugs might appear.

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

luawrap-0.1.5.tar.gz (2.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

luawrap-0.1.5-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file luawrap-0.1.5.tar.gz.

File metadata

  • Download URL: luawrap-0.1.5.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

Hashes for luawrap-0.1.5.tar.gz
Algorithm Hash digest
SHA256 b732d27186fe1539e8c06c26c204525ea1323b174e8f5355e1353fc88343b7d8
MD5 accebba7780789721508446c3403673c
BLAKE2b-256 7b8a4da16119acd969666b05600487c35f37b0ca40351197a5b007efdafdadec

See more details on using hashes here.

File details

Details for the file luawrap-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: luawrap-0.1.5-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

Hashes for luawrap-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 9387f9e524f043496a6a8aa7d832d2b47bf5ed97ff013bb2220c2de6de2c8c61
MD5 55133c875198b7c67bfdeff096760479
BLAKE2b-256 2dc5b4a226e9562eddf4173cdde138324fc27c36541878b1f4160bbfe90fcc26

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page