Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed Lua inside Python?

This sounds like a weird question, so I'll explain circumstances surrounding first.

Basically, I have a 3D game development kit, written in Python, that works excellently by itself. However, most of my users will be used to using Lua as a scripting language, so I started to look at Lua-Python bindings.

I settled with Stefan Behnel's amazing Lupa library. However, it basically requires end-users to know how to compile applications, which is unacceptable for my GDK. Also, I normally can only access a Linux system, and since my game development kit runs on Windows and Mac OSX, the Windows binaries always lag behind, and my OSX users must compile my GDK themselves.

Does anyone know another alternative? Thank you!

P.S: I've already tried Lunatic Python, and Lux is too outdated.

like image 947
DangerOnTheRanger Avatar asked Jun 04 '11 02:06

DangerOnTheRanger


People also ask

Can you use Lua in Python?

Lua is therefore not commonly used as primary language for large applications, but it makes for a fast, high-level and resource-friendly backup language inside of Python when raw speed is required and the edit-compile-run cycle of binary extension modules is too heavy and too static for agile development or hot- ...

Is Lua harder than Python?

Lua is easier than the Python language but Python is popular and demanding language than the Lua language for beginners. Python is a scripting language but it is heavy and slower than the Lua language but Lua is a light-weight, portable, and rapid execution language.

How do I run a Lua script from the command line?

To run a Lua scriptOpen the Lua Script Library through Prepare > Run Lua Script. Use the appearing dialog to load, save, and execute Lua scripts as well as to create new ones. Select the script to be run. Click Execute Script.


1 Answers

you should look into lunatic-python it is a 2 way bridge between python and lua.

an example off the site shows how natural and easy it is:

>>> import lua
>>> lg = lua.globals()
>>> lg.string
<Lua table at 0x81c6a10>
>>> lg.string.lower
<Lua function at 0x81c6b30>
>>> lg.string.lower("Hello world!")
'hello world!'
like image 61
Hortinstein Avatar answered Oct 04 '22 08:10

Hortinstein