Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
FFI for LuaJIT — Gideros Forum

FFI for LuaJIT

ar2rsawseenar2rsawseen Maintainer
edited April 2014 in General questions
Everyone knows that LuaJIT for Gideros provides speed improvements.
but maybe not everyone knows that with LuaJIT comes FFI.

So what is FFI?
FFI (http://luajit.org/ext_ffi_tutorial.html) or Foreign Function Interface is an awesome feature, that allows you to call static C functions without any lua binding.
(external C library still must be linked, for example included in Plugins directory)


So how does FFI work?
FFI is by default included in LuaJIT, so if you are an upgraded member and have installed luajit binaries, you will have FFI included automatically.

All you have to do in your Gideros project is to require ffi lib
local ffi = require("ffi")
Then provide definition of function you want to call (usually can be found and copy pasted from C library header files)
ffi.cdef[[
int printf(const char *fmt, ...);
]]
And then you can call this function through C namespace:
ffi.C.printf("Hello %s!", "world")
And thats it.

More thorough tutorial: http://luajit.org/ext_ffi_tutorial.html

If you don't want to create anything using FFI, you may still benifit from existing FFI created bindings:
http://wiki.luajit.org/FFI-Bindings
+1 -1 (+3 / -0 )Share on Facebook

Comments

Sign In or Register to comment.