How are C libraries for LÖVE handled?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
josip
Prole
Posts: 21
Joined: Tue Oct 03, 2017 1:55 pm

How are C libraries for LÖVE handled?

Post by josip »

I would like to use sqlite in an Android app. I would like it to work across Linux desktop and Android platforms at least.

For this I'll need to compile in the C source of that lib, as well include the Lua wrapper in the game.love bundle. Some of these wrappers provide traditional C binding, others use JIT FFI. Is one preferred for cross-platform use?

Is there a documented way of how to approach this in LÖVE? On how to build and distribute the C library. Maybe some example repo?

As an example of what I'm after, there is a similar framework called LOVR that has plugins supported through the build system. Plugins can be separate repositories with just the necessary code, and not forks of the whole framework.

Code: Select all

https://lovr.org/docs/Plugins
User avatar
pgimeno
Party member
Posts: 3674
Joined: Sun Oct 18, 2015 2:58 pm

Re: How are C libraries for LÖVE handled?

Post by pgimeno »

Dynamic libraries linked at run time are typically handled via FFI, see http://luajit.org/ext_ffi_api.html (especially ffi.load). Making it cross-platform is not too difficult, but it requires a bit of work (apart from the binaries of course).

There are LuaJIT bindings for SQLite already available, you can take a look at those.
josip
Prole
Posts: 21
Joined: Tue Oct 03, 2017 1:55 pm

Re: How are C libraries for LÖVE handled?

Post by josip »

Is there a open source project that dealt with similar thing before? I don't really know enough about Android to figure out where to put the .so files, how to point to them from LuaJIT, and what app permissions are needed for executing JNI libraries.
User avatar
AuahDark
Party member
Posts: 107
Joined: Mon Oct 23, 2017 2:34 pm
Location: Indonesia
Contact:

Re: How are C libraries for LÖVE handled?

Post by AuahDark »

Currently, for Android specifically you need to modify LOVE code (and the Android.mk build files), statically link your C libraries to it, and expose it to "package.preload". Extracting the native libraries to game directory and requiring that doesn't work in Android 10 and later due to no execute enforcement in LOVE save directory.
Profile. Do you encounter crashes in LÖVE Android and wanna send me logcats? Please hit me up in LÖVE Discord and send the full logcat file!
Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests