Issues

Using Love2d as a C++ Library

I've recently been toying around with love2d, and it has been an outstanding way to learn lua. However, I've recently started to take up C++, and I figure that love2d may be a great way to do that.

Looking through the source code, It appears to be a complete C++ library, with only the wrap_xxx.cpp files being the lua stuff. So perhaps compiling love2d for use with C++ can just be a set of #ifdefs around the #include "wrap_xxx.h" lines.

I'm also curious about this. More specifically, I'm interested in audio and graphics with physfs integrated. One thing I'm curious is, DevIL and OpenAL whatever, are they modified to work with physfs, or simply wrapped?

OpenAL doesn't load files by itself in the first place, its buffers just take raw PCM data. There is the ALUT library, but it's old and LÖVE doesn't use it.

For audio, it goes something like this: filename -> read by love.filesystem (with the physfs backend) into FileData -> decoded by love.sound into a Decoder and/or SoundData -> played by love.audio as a Source.

For images, it's similar: filename -> read by love.filesystem into FileData -> decoded by love.image into an ImageData -> put into VRAM by love.graphics as an Image.

In both cases, the file reading step (via love.filesystem) is done separately from the decoding step - the latter is only done for data which is already entirely in RAM; DevIL and the various love.sound backends all have functions to do it.

Mostly stuff in love.physics. A really quick search shows these function using the lua_State struct. There may be more functions, perhaps doing other things with Lua.

You can try to just use it as a C++ library, but you may run into issues where you need to look at the wrapper or the embedded Lua scripts to understand how to set it up. An example is the initialization order of the modules.

It's possible to use most love modules from C++ as-is, although some functions still operate on a Lua state directly.

In general though, LÖVE's code is written specifically for use in Lua rather than as a general C++ API. There are many idioms in the codebase that are written with the expectation that the APIs will be used in Lua – modules are reference-counted singleton objects, objects in general have special reference-counting methods, methods have parameters and return values that reflect Lua's multiple return value functionality, etc.

If you're looking to write C++ code that uses similar functionality to what LÖVE provides, I'd recommend an actual C or C++ library like SDL or SFML.

Just for who may be still interested. I forked love and experimented using it as a pure C++ library.
With a few surprises. I managed to put a simple test program as a proof of concept.
See here love-as-lib.