Python中的Lua解析器

2024-04-20 11:41:18 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在研究在一个web项目中使用Lua。我似乎找不到任何直接用纯python解析并用python运行Lua代码的方法。在

有人知道怎么做吗?在


Tags: 项目方法代码weblua
3条回答

有一个项目(pylux)在Python中嵌入Lua。虽然它看起来相当不活跃,但它可能是一个很好的项目来看看。在

从您的评论来看,您似乎对执行不可信代码的安全方法感兴趣。在

正如您在评论中建议的那样,重新定义python内置函数是一种保护代码安全的可怕方法。在

你想要的是沙盒,有针对python的解决方案,但我不推荐它们。使用Jython或IronPython会更好,因为JVM和.netclr在设计时考虑了沙箱。在

我个人认为,在大多数情况下,如果您需要执行不可信的代码,那么您对您的用户的信任太多或不够。在

@卓尔

来自Lua的网站:

Lua is a fast language engine with small footprint that you can embed easily into your application. Lua has a simple and well documented API that allows strong integration with code written in other languages. It is easy to extend Lua with libraries written in other languages. It is also easy to extend programs written in other languages with Lua. Lua has been used to extend programs written not only in C and C++, but also in Java, C#, Smalltalk, Fortran, Ada, Erlang, and even in other scripting languages, such as Perl and Ruby.

@乔·辛普森

看看疯狂的Python,它可能有你想要的。我知道这是个老问题,但其他人可能也在寻找这个答案。这是一个值得好好回答的好问题。在

相关问题 更多 >