Page 1 of 1

C++/C in Love2D?

Posted: Sat Aug 22, 2015 9:59 am
by louie999
Will it be possible to run C++/C(more preferably C++) with Love2D ? If so then how?

Re: C++/C in Love2D?

Posted: Sat Aug 22, 2015 1:43 pm
by Nixola
You can use C via LuaJIT's FFI lib, or use C++ if you make a library yourself and build it to a .so/dll/dylib file.

Re: C++/C in Love2D?

Posted: Sat Aug 22, 2015 3:07 pm
by louie999
Ah ok, C is good too. Though I have another question, how can I call a lua function from C ? like call love.graphics.setColor from C, how will I be able to do it ?

Edit:
I tried this:

Code: Select all

ffi = require "ffi"

ffi.cdef[[ #include <stdio.h>
    int main()
	{
		printf("Hi");
	}
]]
But it resulted in this error:

Code: Select all

unexpected symbol near 'include'
o.O

Re: C++/C in Love2D?

Posted: Sat Aug 22, 2015 7:42 pm
by Nixola
Apparently you don't include things in the FFI. By googling I found out that this is how you should be able to use printf:

Code: Select all

local ffi = require "ffi"

ffi.cdef[[
int printf(const char *fmt, ...);
]]

ffi.C.printf("Hi\n")
This link explains something (not much actually) about the FFI.

Re: C++/C in Love2D?

Posted: Sun Aug 23, 2015 9:54 am
by T-Bone
Why would you want this? At least for me, the big advantage of Löve is that you get to code in Lua. There are plenty of great C/C++ game frameworks out there.

Re: C++/C in Love2D?

Posted: Sun Aug 23, 2015 9:59 am
by Nixola
Lua is great, but sometimes a C library does exactly what you want and it'd be a pity not to use it, or you may need pretty intensive math which is much faster in C. It has its uses. You don't use only C with the FFI, but you can easily use it along Lua.

Re: C++/C in Love2D?

Posted: Fri Aug 28, 2015 1:52 am
by AntonioModer

Re: C++/C in Love2D?

Posted: Fri Aug 28, 2015 2:55 am
by arampl
louie999 wrote:Though I have another question, how can I call a lua function from C ? like call love.graphics.setColor from C, how will I be able to do it ?
T-Bone wrote:Why would you want this? At least for me, the big advantage of Löve is that you get to code in Lua. There are plenty of great C/C++ game frameworks out there.
+1. Functions like "love.graphics.setColor" is already written in C++ in LÖVE sources to be used from Lua. You want something like installing VirtualBox in Windows to install Linux with its own VirtualBox again.

If you talking about calling Lua functions from C/C++ in general then you should read about embedding Lua in PIL. It's not very complicated.