C++/C in Love2D?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
C++/C in Love2D?
Will it be possible to run C++/C(more preferably C++) with Love2D ? If so then how?
Code: Select all
fun = true
school = true
function isItFun()
if school then
fun = false
end
if not fun then
me:explode()
end
end
Re: C++/C in Love2D?
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.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: C++/C in Love2D?
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:
But it resulted in this error:
o.O
Edit:
I tried this:
Code: Select all
ffi = require "ffi"
ffi.cdef[[ #include <stdio.h>
int main()
{
printf("Hi");
}
]]
Code: Select all
unexpected symbol near 'include'
Code: Select all
fun = true
school = true
function isItFun()
if school then
fun = false
end
if not fun then
me:explode()
end
end
Re: C++/C in Love2D?
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:
This link explains something (not much actually) about the FFI.
Code: Select all
local ffi = require "ffi"
ffi.cdef[[
int printf(const char *fmt, ...);
]]
ffi.C.printf("Hi\n")
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: C++/C in Love2D?
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.
My game called Hat Cat and the Obvious Crimes Against the Fundamental Laws of Physics is out now!
Re: C++/C in Love2D?
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.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
- AntonioModer
- Party member
- Posts: 202
- Joined: Fri Jun 15, 2012 5:31 pm
- Location: Belarus
- Contact:
Re: C++/C in Love2D?
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 ?
+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.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.
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.
Who is online
Users browsing this forum: No registered users and 3 guests