FFI
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的更多相关文章
- Atitit ABI FFI 的区别与联系 attilax总结
Atitit ABI FFI 的区别与联系 attilax总结 FFI stands for Foreign Function Interface. A foreign function interf ...
- 安装 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 ...
- Ruby FFI 入门教程
FFI是一个可以让用户使用Ruby调用C代码的gem.如果你需要执行一些系统底层调用,或者做一些高性能运算的话,FFI是一个很不错的选择. 1. 安装 执行gem install ffi即可.非常标准 ...
- hp-ux-ia64:jffi/ffi 编译总结
在HP-UX-IA64下编译JFFI及FFI遇到很多问题,官网jffi文档中也并没有在hp-ux-ia64平台上有编译过. 次文档仅为记录之用.记录编译过程,但并不意味着本人遇到的问题已经解决. 注意 ...
- (原)lua使用ffi调用c程序的函数
转载请注明出处: http://www.cnblogs.com/darkknightzh/p/5812763.html 参考网址: http://luajit.freelists.narkive.co ...
- 在Node.js中使用ffi调用dll
类似的文章还是比较多的,但或多或少有一些问题没有解决,在此我将其整合并分享给大家: 测试环境: Node.js 9.9.0 VisualStudio 2015 "ffi": &qu ...
- nodejs ffi(DLL)
npm install ffi Error: The specified module could not be found. npm rebuild var ffi = require('ffi') ...
- FFI (语言交互接口(Foreign Function Interface))
FFI(Foreign Function Interface)是用来与其它语言交互的接口, 在有些语言里面称为语言绑定(language bindings), Java 里面一般称为 JNI(Java ...
- lua中是 ffi 解析 【是如何处理数据包的/pkt是如何传进去的】 fsfsfs
lua中的ffi是如何解析的呢? 拿bcc中对proto的解析说起: metatype是有大学问的: ffi.metatype(ffi.typeof('struct ip_t'), { __index ...
随机推荐
- One-hot encoding 独热编码
http://blog.sina.com.cn/s/blog_5252f6ca0102uy47.html
- linux(fedora) 第一课
1.Linux查看ip地址:ifconfig(interface config) 2.find / -name ifconfig (查找 从/开始找 找名字 匹配ifconfing) 复制命令:Ctr ...
- 网络分层和Http协议原理
网络分层: 应用层 传输层 网络层 数据链路层 物理层 物理层: 比特流在节点之间的传输,是计算机连接起来的物理手段. 数据链路层: 控制网络层和物理层之间的通信,功能是在不可靠的物理线路上进行数据可 ...
- python基础之文件表格读取
实现功能:提取表格某一列的值. 所用库:xlrd 打开表格的函数 def open_excel_file(filename,sheet_num=0): xlsfile = filename book ...
- 基于django的自定义简单session功能
基于django的自定义简单session功能 简单思路: 1.建立自定义session数据库 2.登入时将用户名和密码存入session库 3.将自定义的随机session_id写入cookie中 ...
- TODO 动态执行appium代码,便于修改和调试
https://testerhome.com/topics/9040 还没尝试过. 不过不是很懂怎么实现的,java不是编译后再运行的语言吗?怎么一边编译一边运行呢???
- mysql 5.7 启动脚本
最近这段时间,在看mysql,安装了,也应用过,对于生产环境中,一般都选择使用source code安装,在安装的时候可以自定义相关路径和内容,对于生产环境来说更有效.相对于mysql 5.5的安装, ...
- Qt ------ window下工程项目打包成一个exe程序
最近,在学习QT5的过程中,想尝试着把自己写的工程程序给打包发布出来,在任何一台windows系统都能运行,这样就不会限于电脑需不需要安装QT安装包了. 首先,先介绍自己使用的环境.我使用的QT版本是 ...
- 异常处理和Throwable中的几个方法
package cn.lijun.demo; /* * try { //需要被检测的语句. } catch(异常类 变量) { //参数. //异常的处理语句. } finally { //一定会被执 ...
- 关键字(6):trigger触发器
trigger是个特殊的存储过程,它的执行不是由程序调用,也不是手工启动,而是由事件来触发,比如当对一个表进行操作(insert,delete,update)时就会激活它执行.触发器经常用于加强数据的 ...