Skip to main content

Write and run Lua code directly from Python files! No lua install needed!

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: luawrap-0.1.6.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.6.tar.gz
Algorithm Hash digest
SHA256 58ab6cb373a3ea1ac3cf5c5a0027be04099f132a267b05e6c957918d572ac944
MD5 3538f4deb958208639e898da7b73ec23
BLAKE2b-256 077a98032d8e8ac95467a9bf39dc18b6ae469a896aa53348c36e6b81bc074094

See more details on using hashes here.

File details

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

File metadata

  • Download URL: luawrap-0.1.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 441b02dd2dee37fe755a45d6a14955560b0602d945a4309ed2a6271f0c6f7657
MD5 5ba0f344380ee4b31cda5aef0029ab31
BLAKE2b-256 2927007efe5dc9f50bd6b765de7ede47742e2738009d12171373d05fa757a54b

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