Issue #201 resolved

Have a search path for love.filesystem's require searcher

created an issue

I've submitted an STD to the Dropbox share that depends on this behaviour.

Basically, when you specify a custom package path it should work when the game is zipped.

If the package.path for example has "./lib/?.lua;" and you require("test"), LÖVE should check in

Comments (18)

  1. Linus reporter
    • changed status to open

    Then add a variable that works similarly to package.path for the LÖVE require loader called love.filesystem.path or something.

    Its default value should be "./?.lua;./?/init.lua", so it assumes the current behaviour correctly.

  2. kikito


    I know at least 1 reason.

    The TL;DR is: libraries with multiple files usually expect a package.path of some sort.

    package.path is not marked as "optional", like the debug library is (was). Multiple-file libraries in the Lua (non-LÖVE) world tend to rely on this, and assume that their library foo is available for require at require 'foo'. And if you put it on lib/foo, you just modify your package.path to include lib.

    Since LÖVE does not have that, when I create a library, I resolve to "hacks": I carefully get the "current dir" and require according to that it. Or I bundle everything in one huge file.

    These approaches work for libraries I explicitly tailored for LÖVE, but there are others Lua libraries out there that will just not work - or will work only if put in exactly one place - you will not be able to use a lib folder to organize your code.

  3. Landon Manning

    I'm not sure if this is completely on topic, but when you require a file, that file is given a path argument via ... which is commonly used for libraries using relative files.

    -- main.lua
    Lib = require "some.lib"
    -- some/lib/init.lua
    local path = ... -- "some.lib"
    local Module1 = require(path .. ".module1") -- "some.lib.module1"
    local Module2 = require(path .. ".module2") -- "some.lib.module2"
    local Module3 = require(path .. ".module3") -- "some.lib.module3"

    I wouldn't consider this a hack at all, it seems to be build right into Lua.

    Also, if you wanted to be hilarious, you could do the following:

    local path = ... .. "." -- "some.lib."


  4. kikito

    why was I implementing this in C++?

    Oh. I know nothing about that. By all means, if you go around implementing this, do it however it's easier for you :)

  5. Log in to comment