IronPython上的ctypes示例? [英] An example of ctypes on IronPython?

查看:150
本文介绍了IronPython上的ctypes示例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在IronPython上理解ctype及其与IronClad的关系. (应该在最新的IronPython版本中实现Ctypes.)有人可以给出在MonoPython/OSX上工作的IronPython中的ctypes的简单示例吗?尝试标准演示时,我得到:

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

我缺少明显的东西吗?

更一般地说,ctypes与IronClad项目有什么关系?

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

推荐答案

我不知道您第一个问题的答案(我不使用Mono,对不起),但是我可以回答您的一般性问题.

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

IronClad是一个适配器,它允许针对CPython API编写的现有CPython扩展模块在IronPython上无缝运行.另一方面,Ctypes是一个FFI(外部函数接口),该函数允许Python代码执行以下操作:以与平台无关的方式调用本机代码.

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.

在使用ctypes之前,从Python访问本机代码的唯一方法是编写与CPython紧密耦合的CPython扩展. ctypes消除了这种耦合,并使其可以在实现ctypes的任何Python实现中使用. IronClad的存在是为了允许所有旧版扩展继续在IronPython上运行.对于新事物,ctypes是必经之路.

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.

这篇关于IronPython上的ctypes示例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆