Can I add c/c++ or possibly c# to my love2d game?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
psemo
Prole
Posts: 6
Joined: Sun Mar 05, 2023 11:42 am

Can I add c/c++ or possibly c# to my love2d game?

Post 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)
duaner
Prole
Posts: 41
Joined: Thu May 07, 2020 6:43 pm
Contact:

Re: Can I add c/c++ or possibly c# to my love2d game?

Post 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.
User avatar
Bigfoot71
Party member
Posts: 287
Joined: Fri Mar 11, 2022 11:07 am

Re: Can I add c/c++ or possibly c# to my love2d game?

Post 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 :ultraglee:
My avatar code for the curious :D V1, V2, V3.
User avatar
dusoft
Party member
Posts: 531
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Can I add c/c++ or possibly c# to my love2d game?

Post 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/
User avatar
pgimeno
Party member
Posts: 3588
Joined: Sun Oct 18, 2015 2:58 pm

Re: Can I add c/c++ or possibly c# to my love2d game?

Post 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.
tourgen
Citizen
Posts: 53
Joined: Sat Mar 18, 2023 12:45 am

Re: Can I add c/c++ or possibly c# to my love2d game?

Post 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.
duaner
Prole
Posts: 41
Joined: Thu May 07, 2020 6:43 pm
Contact:

Re: Can I add c/c++ or possibly c# to my love2d game?

Post 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.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 9 guests