例如我有一个Python函数,我想转换为C++(或从C++调用,但我不想依赖python解释器) 简单的python函数不能理解shedskin生成的代码
//test.py
def my_sum(x,y):
print "Hello World!"
return x*x+y
我跑shedskin并有
//test.cpp
#include "builtin.hpp"
#include "test.hpp"
namespace __test__ {
str *__name__;
void __init() {
__name__ = new str("__main__");
}
} // module namespace
int main(int, char **) {
__shedskin__::__init();
__shedskin__::__start(__test__::__init);
}
//test.hpp
#ifndef __TEST_HPP
#define __TEST_HPP
using namespace __shedskin__;
namespace __test__ {
extern str *__name__;
} // module namespace
#endif
丑陋的代码,也没有我的功能my_sum和代码依赖于“builtin.hpp”。是否有可能只转换功能?
或
我想从我的C调用函数++代码类似 INT总和= py.my_sum(3,5); 我该怎么做?
或
也许我可以做Python代码DLL或者Lib,我可以在C++代码中使用?
我们目前知道的唯一可以可靠地将代码从一种语言翻译成另一种语言的人是人。 – geekosaur 2012-04-27 08:59:47
@geekosaur:曾听过编译器? – 2012-04-27 09:02:13
@FerdinandBeyer,请关掉迂腐的过滤器。对于这个问题,有些语言的翻译人员还有一些其他的语言(例如Fortran to C),这些语言并不太可怕......但是一般的Python到C++并不会很漂亮,正如这个问题所示。 – geekosaur 2012-04-27 09:05:35