Dup Goto 📝

Lupa

PT2/lang/python/lua 09-19 22:28:28
To Pop
23 lines, 70 words, 555 chars Friday 2025-09-19 22:28:28

For embedding LuaJIT in Python, use Lupa.

Examples

1

(From Chatgpt.)

from lupa import LuaRuntime

lua = LuaRuntime(unpack_returned_tuples=True)

# Run Lua code
print(lua.eval("1 + 2"))  # 3

# Define Lua function and call from Python
lua_func = lua.eval("function(x, y) return x * y end")
print(lua_func(6, 7))  # 42

# Pass Python function into Lua
def py_hello(name):
    return f"Hello, {name}!"
lua.globals().py_hello = py_hello
print(lua.eval('py_hello("Lua")'))  # Hello, Lua!