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.htmlIf you don't want to create anything using FFI, you may still benifit from existing FFI created bindings:
http://wiki.luajit.org/FFI-Bindings
Comments
e.g. for the free polygon clipper library 'clipper' we discussed months ago there exist bindings:
http://luapower.com/clipper
any news about which gideros version will have luajit (without labs)?
Fragmenter - animated loop machine and IKONOMIKON - the memory game
if yes, then e.g. for the clipper library there is some folders and files in the zip they provide, where should i put all these files in my eclipse project? do i need to precompile anything with ndk like for other plugins?
Fragmenter - animated loop machine and IKONOMIKON - the memory game
But the C lib must also be supported on that platform and you should have a binary for that platform to use it through FFI.
In case of Clipper, you can drop mingw 32 or 64 depending on your OS into Gideros plugins folder and use it on your desktop player.
For Android and IOS unfortunately it seems binaries are not provided and you would have to build them your self.
For ios, most probably it is enough to simply drag and drop all the sources (clipper.c, clipper.cpp, clipper.hpp) into Plugins directory of exported xcode project
For Android you will have to define Android.mk file, which could look like this:
http://mobilepearls.com/labs/ndk-builder-in-eclipse/
Hope that helps
Likes: vitalitymobile
so with ffi using e.g. clipper is still relatively simple, even though one has to compile but at least no work on manual binding is necessary.
i will experiment with this, when i get the time.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: ar2rsawseen
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps
Author of Learn Lua for iOS Game Development from Apress ( http://www.apress.com/9781430246626 )
Cool Vizify Profile at https://www.vizify.com/oz-apps