Search code examples
lualove2dluarocks

How to use external library with love2d


I'm trying to use the luafun library with love2d. Running lua main.lua, however love . complains about the missing fun library.

I have installed luafun with luarocks.


Solution

  • There's two options.

    If you want to distribute whatever you're building, you almost certainly don't want users to install Lua, luarocks, etc. etc. - so the best way is to simply put any libraries into the folder that your game/program/… lives in. (If a library contains compiled things, you'll need to build per platform/OS and then you'll actually want a build process that spits out the various variants, but if it's all-Lua, there's no platform-specific stuff, so just copy it in.)

    The other option (mostly for when you only need it to work on your machine) is to adjust package.path and then love will find things just fine. If you use LUA_INIT / LUA_PATH on your machine, Love ignores them but you can manually fetch & process them using os.getenv, dofile / load(code)() & friends. (As the very simplest special case of this, if luarocks is installed in the standard Lua search path, saying require "luarocks.loader" might be enough to get all luarocks-installed packages to work.)