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.

libFFI

http://sourceware.org/libffi/

What is libffi?

Compilers for high level languages generate code that follows certain conventions. These conventions are necessary, in part, for separate compilation to work. One such convention is the "calling convention". The "calling convention" is a set of assumptions made by the compiler about where function arguments will be found on entry to a function. A "calling convention" also specifies where the return value for a function is found.

Some programs may not know at the time of compilation what arguments are to be passed to a function. For instance, an interpreter may be told at run-time about the number and types of arguments used to call a given function. Libffi can be used in such programs to provide a bridge from the interpreter program to compiled code.

The libffi library provides a portable, high level programming interface to various calling conventions. This allows a programmer to call any function specified by a call interface description at run-time.

FFI stands for Foreign Function Interface. A foreign function interface is the popular name for the interface that allows code written in one language to call code written in another language. The libffi library really only provides the lowest, machine dependent layer of a fully featured foreign function interface. A layer must exist above libffi that handles type conversions for values passed between the two languages.

FFI的更多相关文章

  1. Atitit ABI FFI 的区别与联系 attilax总结

    Atitit ABI FFI 的区别与联系 attilax总结 FFI stands for Foreign Function Interface. A foreign function interf ...

  2. 安装 pyopenssl c/_cffi_backend.c:15:17: 致命错误:ffi.h:

    错误 c/_cffi_backend.c:15:17: 致命错误:ffi.h: 解决方案 yum install -y libffi-devel 或ubuntu中 apt-get install -y ...

  3. Ruby FFI 入门教程

    FFI是一个可以让用户使用Ruby调用C代码的gem.如果你需要执行一些系统底层调用,或者做一些高性能运算的话,FFI是一个很不错的选择. 1. 安装 执行gem install ffi即可.非常标准 ...

  4. hp-ux-ia64:jffi/ffi 编译总结

    在HP-UX-IA64下编译JFFI及FFI遇到很多问题,官网jffi文档中也并没有在hp-ux-ia64平台上有编译过. 次文档仅为记录之用.记录编译过程,但并不意味着本人遇到的问题已经解决. 注意 ...

  5. (原)lua使用ffi调用c程序的函数

    转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5812763.html 参考网址: http://luajit.freelists.narkive.co ...

  6. 在Node.js中使用ffi调用dll

    类似的文章还是比较多的,但或多或少有一些问题没有解决,在此我将其整合并分享给大家: 测试环境: Node.js 9.9.0 VisualStudio 2015 "ffi": &qu ...

  7. nodejs ffi(DLL)

    npm install ffi Error: The specified module could not be found. npm rebuild var ffi = require('ffi') ...

  8. FFI (语言交互接口(Foreign Function Interface))

    FFI(Foreign Function Interface)是用来与其它语言交互的接口, 在有些语言里面称为语言绑定(language bindings), Java 里面一般称为 JNI(Java ...

  9. lua中是 ffi 解析 【是如何处理数据包的/pkt是如何传进去的】 fsfsfs

    lua中的ffi是如何解析的呢? 拿bcc中对proto的解析说起: metatype是有大学问的: ffi.metatype(ffi.typeof('struct ip_t'), { __index ...

随机推荐

  1. [POI2007]ODW-Weights(贪心)

    在byteotian公司搬家的时候,他们发现他们的大量的精密砝码的搬运是一件恼人的工作.公司有一些固定容量的容器可以装这些砝码.他们想装尽量多的砝码以便搬运,并且丢弃剩下的砝码.每个容器可以装的砝码数 ...

  2. js 刷新

    方法一: location.reload 重新加载 location.reload(); 如果该方法没有规定参数,或者参数是 false,它就会用 HTTP 头 If-Modified-Since 来 ...

  3. 透彻掌握Promise的使用

    Promise的重要性我认为我没有必要多讲,概括起来说就是必须得掌握,而且还要掌握透彻.这篇文章的开头,主要跟大家分析一下,为什么会有Promise出现. 在实际的使用当中,有非常多的应用场景我们不能 ...

  4. python 当前时间获取方法

    1.先导入库:import datetime 2.获取当前日期和时间:now_time = datetime.datetime.now() 3.格式化成我们想要的日期:strftime() 比如:“2 ...

  5. linux:awk修改输出分隔符

    file1的内容如下: a b c d e f g h 现在想要修改成 a b c:d e f g:h 则需要用到如下命令: awk -F " " '{print $1,$2,$3 ...

  6. operator new和operator delete

    从STL源码剖析中看到了operator new的使用 template<class T> inline void _deallocate(T* buffer) { ::operator ...

  7. memset()函数及其作用(转)

    1. memset()函数原型是extern void *memset(void *buffer, int c, int count) buffer:为指针或是数组, c:是赋给buffer的值, c ...

  8. Qt ------ 在 ubuntu 内安装 Qt creator

    官网介绍:https://wiki.qt.io/Install_Qt_5_on_Ubuntu Contents [hide]  1Install Qt 5 on Ubuntu 1.1Introduct ...

  9. qt: 打不开png图像以及opencv加载中文路径问题;

    经过亲测, QT(版本: 5.9.4)提供的QImageReader或者函数load在加载本地png图像时,均会提示失败, 按照网上的方法,将Qt plugins下的imageformats 拷贝到e ...

  10. qml: QtCharts模块的使用(基本配置)------<一>

    QtCharts模块可以用于绘制图表: 导入模块: import QtCharts 2.2 例子: import QtQuick 2.0 import QtCharts 2.2 ChartView { ...