如何在 Python 中嵌入 Lua? [英] How to embed Lua inside Python?

查看:23
本文介绍了如何在 Python 中嵌入 Lua?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这听起来很奇怪,所以我先解释一下周围的情况.

基本上,我有一个用 Python 编写的 3D 游戏开发工具包,它本身可以很好地运行.不过,我的大部分用户都会习惯使用 Lua 作为脚本语言,所以我开始研究 Lua-Python 绑定.

我选择了 Stefan Behnel 令人惊叹的 Lupa 库.但是,它基本上需要最终用户知道如何编译应用程序,这对于我的 GDK 来说是不可接受的.另外,我通常只能访问 Linux 系统,而且由于我的游戏开发工具包在 Windows 和 Mac OSX 上运行,因此 Windows 二进制文件总是滞后,我的 OSX 用户必须自己编译我的 GDK.

有人知道另一种选择吗?谢谢!

P.S:我已经尝试过 Lunatic Python,Lux 太过时了.

解决方案

你应该看看 lunatic-python 它是 python 和 lua 之间的双向桥梁.

网站外的一个例子展示了它是多么的自然和简单:

<预><代码>>>>导入lua>>>lg = lua.globals()>>>lg.string<0x81c6a10处的Lua表>>>>lg.string.lower<0x81c6b30处的Lua函数>>>>lg.string.lower("世界你好!")'你好世界!'

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.

解决方案

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!'

这篇关于如何在 Python 中嵌入 Lua?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆