Page 1 of 1
Can I add c/c++ or possibly c# to my love2d game?
Posted: Wed Apr 26, 2023 11:15 pm
by psemo
If so how can I? I have never used more than one languages before, you don't need to come up with a step by step guide but is there a video I should watch? Is there a docunmentation I should read? What should I google? Anything would be great. (I would prefer c# wayyyy above c++ and c)
Re: Can I add c/c++ or possibly c# to my love2d game?
Posted: Thu Apr 27, 2023 12:21 am
by duaner
I'd be shocked if lua on luajit doesn't run as fast as compiled c#. The last time I benchmarked luajit against c code, it was about half as fast, on average, which is extraordinary for a scripting language. Even vanilla lua is extremely fast on my system. I don't usually bother with luajit.
Re: Can I add c/c++ or possibly c# to my love2d game?
Posted: Thu Apr 27, 2023 12:26 am
by Bigfoot71
For C# there is
love2DCS but it doesn't seem to be maintained since 2020, and for C there is FFI, it can be useful for critical tasks and with JIT of course otherwise it's extremely slow.
duaner wrote: ↑Thu Apr 27, 2023 12:21 am
I'd be shocked if lua on luajit doesn't run as fast as compiled c#. The last time I benchmarked luajit against c code, it was about half as fast, on average, which is extraordinary for a scripting language. Even vanilla lua is extremely fast on my system. I don't usually bother with luajit.
Clearly if it's to use a wrap anyway it won't be good for performance, so might as well use another framework like Raylib or Monogame but it will be less lovely
Re: Can I add c/c++ or possibly c# to my love2d game?
Posted: Thu Apr 27, 2023 7:39 pm
by dusoft
I would recommend a bit of googling before asking, but surely you can call C++ functions from Lua:
http://gamedevgeek.com/tutorials/callin ... -from-lua/
Re: Can I add c/c++ or possibly c# to my love2d game?
Posted: Thu Apr 27, 2023 8:53 pm
by pgimeno
I strongly recommend against doing it in the first place, because either you supply binaries for all platforms, or the multi-platformness of Löve goes down the drain.
Re: Can I add c/c++ or possibly c# to my love2d game?
Posted: Fri Apr 28, 2023 1:35 pm
by tourgen
duaner wrote: ↑Thu Apr 27, 2023 12:21 am
I'd be shocked if lua on luajit doesn't run as fast as compiled c#. The last time I benchmarked luajit against c code, it was about half as fast, on average, which is extraordinary for a scripting language. Even vanilla lua is extremely fast on my system. I don't usually bother with luajit.
the speed bump for C and C++ is usually the ability to use much more special-purpose data structures for your particular situation. Also absolute control over when/how to allocate and manage memory. Also, the compilers can make far more aggressive optimizations on pre-compiled code.
LuaJIT is surprisingly fast. Raw Lua though, not so much. I'd rather just use Python if plain Lua was all that was available.
Re: Can I add c/c++ or possibly c# to my love2d game?
Posted: Fri Apr 28, 2023 11:30 pm
by duaner
tourgen wrote: ↑Fri Apr 28, 2023 1:35 pm
I'd rather just use Python if plain Lua was all that was available.
Not me. I'd prefer lua over python every time if everything else was equal. Unfortunately, python's standard library is so much better (than dealing with dozens of fragmented lua libraries) that I end up using python anyway. I used to have some huge scripts written in lua, but I had to convert them to python when I lost support from one library or another. Then again, the things I do with python don't require speed.