码迷,mamicode.com
首页 > 其他好文 > 详细

FFI

时间:2017-10-15 11:16:59      阅读:300      评论:0      收藏:0      [点我收藏+]

标签:lang   tps   via   ide   access   can   common   off   nta   

FFI概念

https://segmentfault.com/t/ffi/info

FFI即Foreign Function Interface,外部函数调用接口,是一个语言提供的使用其他语言现有库(以及其他组件)的接口。典型的例子包括C++的extern “C”、Java的JNI、.Net的P/Invoke、Python的Python/C API等。对于新的语言,提供FFI机制是很有现实意义的。提供这样的接口,意味着可以复用已有的无数现有的库。

 

https://en.wikipedia.org/wiki/Foreign_function_interface

A foreign function interface (FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written in another.

 

The term comes from the specification for Common Lisp, which explicitly refers to the language features for inter-language calls as such;[1] the term is also used officially by the Haskell[2] and Python programming languages.[3] Other languages use other terminology: the Ada programming language talks about "language bindings", while Java refers to its FFI as the JNI (Java Native Interface) or JNA (Java Native Access). Foreign function interface has become generic terminology for mechanisms which provide such services.

 

Lua FFI

http://luajit.org/ext_ffi.html

The FFI library allows calling external C functions and using C data structures from pure Lua code.

The FFI library largely obviates the need to write tedious manual Lua/C bindings in C. No need to learn a separate binding language — it parses plain C declarations! These can be cut-n-pasted from C header files or reference manuals. It‘s up to the task of binding large libraries without the need for dealing with fragile binding generators.

demo

local ffi = require("ffi")
ffi.cdef[[
int printf(const char *fmt, ...);
]]
ffi.C.printf("Hello %s!", "world")

参考:

https://moonbingbing.gitbooks.io/openresty-best-practices/content/lua/FFI.html

 

Python FFI

https://cffi.readthedocs.io/en/latest/

CFFI documentation

C Foreign Function Interface for Python. Interact with almost any C code from Python, based on C-like declarations that you can often copy-paste from header files or documentation.

 

FFI

标签:lang   tps   via   ide   access   can   common   off   nta   

原文地址:http://www.cnblogs.com/lightsong/p/7669100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!