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.4.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.4-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: luawrap-0.1.4.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.4.tar.gz
Algorithm Hash digest
SHA256 1ab1bc28b7cfa03e74629cc114d65f94da79b756686c97c13ada80cbde379f78
MD5 9ee8ab97007723cd84b3800e4b5092b9
BLAKE2b-256 83658914faf527cd72efa264691554279c76344f3147c80f571f253878f2fa2d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: luawrap-0.1.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 dc4fadcb910fd21480853c3acb225d708f7f20de81d7dbabaf06d64ff00269fe
MD5 3b9163f83353f7b9051a3c55a68fe6b4
BLAKE2b-256 1d10d8184903c0daaacb8a83043829b3e5b4a946c6a119ce3bc23b4d82bc7666

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