An example of ctypes on IronPython?

大兔子大兔子 提交于 2019-12-11 09:18:58

问题


I'm trying to understand ctypes, and it's relationship to IronClad, on IronPython. (Ctypes is supposed to be implemented in the latest IronPython release.) Can somebody give a simple example of ctypes in IronPython that works on Mono/OSX? When trying the standard demos, I get:

import ctypes
SystemError: libdl.so

Am I missing something obvious?

More generally, how does ctypes relate to the IronClad project?


回答1:


I don't know the answer to your first question (I don't use Mono - sorry), but I can answer your general question.

IronClad is an adaptor that allows existing CPython extension modules, written against the CPython API, to work seamlessly on IronPython. Ctypes, on the other hand, is an FFI (Foreign Function Interface) that allows Python code to call into native code in a platform-independent way.

Before ctypes, the only way to access native code from Python was to write a CPython extension that was tightly coupled to CPython; ctypes removes that coupling and allows it to work on any Python implementation that implements ctypes. IronClad exists to allow all of the legacy extensions to continue to work on IronPython. For new stuff, though, ctypes is the way to go.



来源:https://stackoverflow.com/questions/2204599/an-example-of-ctypes-on-ironpython

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!