[python][lua]在python里调用Lua
来源:互联网 发布:a标签触发js函数 编辑:程序博客网 时间:2024/05/22 05:03
https://stackoverflow.com/questions/30841738/run-lua-script-from-python
You can use a subprocess to run your Lua script and provide the function with it’s arguments.
import subprocessresult = subprocess.check_output(['lua', '-l', 'demo', '-e', 'test("a", "b")'])print(result)result = subprocess.check_output(['lua', '-l', 'demo', '-e', 'test2("a")'])print(result)
the -l requires the given library (your script)the -e is the code that should be executed on start (your function)
The value of result will be the value of STDOUT, so just write your return value to it and you can simply read it in your Python script. The demo Lua script I used for the example simply prints the arguments:
function test (a, b) print(a .. ', ' .. b)endfunction test2(a) print(a)end
In this example both files have to be in the same folder and the lua executable must be on your PATH.
===================================
我失败了,然后才注意到最后一句话.
最后我把python里的改成了
import subprocessresult = subprocess.check_output(['th', '-l', 'demo', '-e', 'test("a", "b")'])print(result)result = subprocess.check_output(['th', '-l', 'demo', '-e', 'test2("a")'])print(result)
因为我安装的是torch.
阅读全文
0 0
- [python][lua]在python里调用Lua
- Lupa - Python中调用Lua
- cocos2dx,在lua里调用相同的lua文件。
- Lupa - Python中调用Lua(收藏)
- linux 下python 调用lua环境配置
- Python 和 Lua
- python vs lua
- Lua Versus Python
- Python和lua
- lua,python,c++
- python,lua,bash
- From Python to Lua
- LUA与C++交互(在LUA脚本里调用C++函数传参)
- Lua 在Lua中调用C函数
- 在Wireshark里加载lua
- python中调用lua——(lupa)
- c++工程调用python语言与lua语言
- 在lua中调用DLL
- Java对象序列化
- Java算法之冒泡排序
- js保留两位小数的方法
- hdu 5979 Convex(正弦定理求三角形面积)
- 预处理和结构体2
- [python][lua]在python里调用Lua
- 用 Smali 手写一个可运行的 HelloWorld!!!
- 文章标题
- Java中Process和Runtime()使用,以及调用cmd命令阻塞在process.waitfor( )的问题解决
- 快速搭建 Node.js / io.js 开发环境以及加速 npm
- 人大金仓数据库的使用心得
- java程序员的大数据之路(10):MapReduce的排序
- 为什么有的人工作多年还是老样子
- 在本地使用MongoDB命令连接远程服务器的MongoDB