Is C compatible with Love2D?
-
- Prole
- Posts: 1
- Joined: Tue Sep 25, 2018 7:34 pm
Is C compatible with Love2D?
I'm curious if we can use C in Love2D. Maybe it has said it somewhere but I missed it.
Re: Is C compatible with Love2D?
Not sure if this covers what you mean, but you can use many languages, including C, to write a dynamic library, and make bindings to it via LuaJIT's FFI library. Then you can use LÖVE's Lua to call any functions the library exports.
However, that means the library will only work for the processor it's compiled for. If you manage to include binary dynamic libraries for all systems you intend to support, you will need special code to make your LÖVE program load the right library for the running system.
However, that means the library will only work for the processor it's compiled for. If you manage to include binary dynamic libraries for all systems you intend to support, you will need special code to make your LÖVE program load the right library for the running system.
- Kindermaus
- Prole
- Posts: 33
- Joined: Sun Sep 23, 2018 5:08 am
Re: Is C compatible with Love2D?
Yes.
I wrote a behavior tree library and a "game database" library in C++ with C wrappers and I use them from Love on both Android and Windows (Linux, etc would be just as easy). You build a normal Lua-compatible DLL (either using FFI/LuaJit or traditional luaopen_xxx shared symbol where xxx is require 'xxx'). I use an ext/ directory off the main Love directory on desktop platforms and modify LUA_CPATH to search there first:
Of course, you need to distribute the right binaries for your platform. This makes your game less portable than vanilla Love2D.
I wrote a behavior tree library and a "game database" library in C++ with C wrappers and I use them from Love on both Android and Windows (Linux, etc would be just as easy). You build a normal Lua-compatible DLL (either using FFI/LuaJit or traditional luaopen_xxx shared symbol where xxx is require 'xxx'). I use an ext/ directory off the main Love directory on desktop platforms and modify LUA_CPATH to search there first:
Code: Select all
do
if love.system.getOS() == "Android" then
local sourceDirectory = love.filesystem.getSourceBaseDirectory()
local cpath = package.cpath
package.cpath = string.format(
"%s/lib/lib?.so;%s/lib?.so;%s",
sourceDirectory,
sourceDirectory,
cpath)
else
local sourceDirectory = love.filesystem.getSourceBaseDirectory()
local cpath = package.cpath
package.cpath = string.format(
"%s/ext/?.dll;%s/ext/?.so;%s",
sourceDirectory,
sourceDirectory,
cpath)
local path = package.path
package.path = string.format(
"%s/ext/?.lua;%s/ext/?/init.lua;%s",
sourceDirectory,
sourceDirectory,
cpath)
end
end
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / she
they / she
Re: Is C compatible with Love2D?
How to reload a plugin that actually works???...
I have tried several times to reload a existing pluging on lovedebug but it's not working very well... When there an error on reload it, It can never reload again by forcing a manual relaunch, Please tell me how to do it exactly?
I have tried several times to reload a existing pluging on lovedebug but it's not working very well... When there an error on reload it, It can never reload again by forcing a manual relaunch, Please tell me how to do it exactly?
Last edited by Chris951 on Tue Oct 02, 2018 6:00 am, edited 3 times in total.
- Kindermaus
- Prole
- Posts: 33
- Joined: Sun Sep 23, 2018 5:08 am
Re: Is C compatible with Love2D?
Reloading a shared library generally requires loading the DLL with a different path.
For example, Unreal Engine generates libraryXXX.dll where XXX is unique per build.
For example, Unreal Engine generates libraryXXX.dll where XXX is unique per build.
ItsyRealm, a quirky 2D/3D RPG where you fight, skill, and explore in a medieval world with horrors unimaginable.
they / she
they / she
Who is online
Users browsing this forum: No registered users and 5 guests