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!