Page 1 of 1

How are C libraries for LÖVE handled?

Posted: Sat Oct 16, 2021 2:28 pm
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

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

Posted: Sat Oct 16, 2021 8:37 pm
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.

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

Posted: Sun Oct 17, 2021 5:56 pm
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.

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

Posted: Fri Oct 29, 2021 8:29 am
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.