konsumer / lua-openmpt

Libopenmpt ffi wrapper for loading & playing mod-music file in luajit or love2d.
4 stars 0 forks source link

libopenmpt not found unless in love2d project root (windows) #1

Open LynnDrumm opened 3 years ago

LynnDrumm commented 3 years ago

Hi! I've been trying to include this into a project, and after a bit of poking around got it working on windows.

unfortunately, it only seems to work if I put openmpt.lua and all the openmpt libraries into the root directory of the love2D project. if I try to put any of it in a subdirectory, I get this error:

cannot load module 'libopenmpt': The specified module could not be found.

resulting from this line:

local openmpt = ffi.load("libopenmpt.dll")

regardless of specifying the relative path.

anything I could be doing wrong? again, it works fine if I just dump all the files into the project root.

konsumer commented 3 years ago

I don't use windows, and don't really have a windows system to test on.

That said, maybe I can still help. I don't think this is related to my lib, it's a general lua/love thing.

First, in the code in this repo is

local openmpt = ffi.load("openmpt")

I think you should keep it that way (with no .dll)

Everything is relative to love project-dir, in love, not the current file, so you could just put the dll there, in the root, or change the path in your copy of openmpt.lua to ./MYLIBDIR/openmpt

Alternately, if you want to do this outside of the lib-file, you can set the c-path so lua knows where to find your DLL:

package.cpath = "./MYLIBDIR/?.dll;" .. package.cpath

On my linux system, it looks like this, but yours will look a bit different:

luajit -e "print(package.cpath)"

/home/konsumer/.luarocks/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/?.so;/home/konsumer/.luarocks/lib/lua/5.1/?.so;./?.so;/usr/lib/x86_64-linux-gnu/lua/5.1/?.so;/usr/lib/lua/5.1/?.so;/usr/local/lib/lua/5.1/loadall.so

You should modify the path before you require "openmpt". If you have some global dir on your system where these kinds of things are installed, you might want to permanently set this for lua, which you'll have to go find out how to do on your own in windows. Looks like you can modify it with the global environment variable LUA_CPATH, but you'll have to look into how to do that on your machine.

To add to the confusion, lua references paths slightly differently for lua vs c modules, using dots for slashes:

local OpenMPT = require "MYLIB.openmpt"

so to move it into a sub-dir called lib/:

package.cpath = "./lib/?.dll;" .. package.cpath
local OpenMPT = require "lib.openmpt"

should work.