- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我有一个用 python 编写的简单函数,我想将其移植到 javascript。
我已经将 python 2.7 编译成一个 .so 库,所以这不是问题。
我遇到的问题是,在我用 cython 编译我的程序后,函数名都被打乱了,这意味着我不知道如何在运行 emcc 时保留这些函数。
有人有使用emscripten将python程序编译成js的经验吗?
如有任何信息,我们将不胜感激。
注意:我想保留 python 的确切功能,我不想要将 python 程序转换为 javascript 的东西。
最佳答案
另一个问题,有一个可接受的答案,提示同样的问题:Cython mangling function names and making it difficult to access from C++: Embed python function in C++
公认的答案指出 Cython 根本不适合这种事情,这表明您不能以这种方式做您想做的事:
You're not going to be able to get the interoperation you want that way. If you open and inspect hello.c you won't find "static int say_hello" anywhere in there. Cython is designed for letting Python use C libraries, not letting C libraries use python.
下一个未被接受的答案表明指定 public
不会破坏函数名称,尽管他也提到了链接问题。
# (in the generated C file hello.c)
__PYX_EXTERN_C DL_IMPORT(...) say_hello(...);
值得一试,但如果失败,请考虑评论中的其他选项。
关于javascript - 如何将用 python 编写的函数编译为 JavaScript (emscripten)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19788352/
我是一名优秀的程序员,十分优秀!