我知道可以在 C 或 lua(请参阅 luabash)上编写 bash 扩展模块(可加载内置函数),但是在 Python/Cython 上可以吗?是否有任何项目朝着这个方向迈进?
最佳答案
您可能会这样做的方法是从一个包含适当导出函数的 C 库开始,然后在导出函数中加载并运行 python 解释器,运行您的 python 代码,然后拆除 python 解释器。
你可以在这里看到如何将 python 解释器加载到 C 程序/库中:
- http://docs.python.org/extending/embedding.html
- http://docs.python.org/extending/extending.html#calling-python-functions-from-c
- http://www.linuxjournal.com/article/8497
如果您经常这样做,那么当您可以使用多个不同的 Python 脚本时,编写一个通用处理程序可能会更简单。
关于python - python 上的 bash 扩展模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11475147/