-- Replace '.' if using `require 'Path.to.lib'`
function require( inputPath ) -- or whatever it is
local currentPath = ''
local currentIndex = 0
while #currentPath ~= #inputPath do
local _, index, temp = inputPath:find( '(.-)%.', currentIndex )
if love.filesystem.exists( currentPath .. temp ) then -- Allow for . in folder names
currentPath = currentPath .. temp .. '/'
currentIndex = index + 1
end
end
return currentPath
end
So how come the .'s are overwritten by "/"?
Is this a Lua problem, or a LÖVE problem?
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
In the example.love it's a Lua problem (require blindly replaces . with the system separator). The easiest solution, in Lua, is to use loadfile. I suspect it is not Love's fault because assert(love.filesystem.exists('Folder.with.dots/File.lua')) works perfectly fine, for instance.
Your example require function makes Love crash, on my PC. Personally, I'd just avoid `.`
Regardless of suggestions, I wrote a require function that works for the Example.love shown. I do not state its correctness. It doesn't handle errors. You'd probably want to use this as a loader rather than overriding require.
The second searcher looks for a loader as a Lua library, using the path stored at package.path. A path is a sequence of templates separated by semicolons. For each template, the searcher will change each interrogation mark in the template by filename, which is the module name with each dot replaced by a "directory separator" (such as "/" in Unix); then it will try to open the resulting file name. So, for instance, if the Lua path is the string
"./?.lua;./?.lc;/usr/local/?/init.lua"
the search for a Lua file for module foo will try to open the files ./foo.lua, ./foo.lc, and /usr/local/foo/init.lua, in that order.
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim