How Come Folders Can't Have a Dot in their Name?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

How Come Folders Can't Have a Dot in their Name?

Post by davisdude »

It seems non-trivial to implement:

Code: Select all

-- 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?

Edit: Uploaded .love example
Attachments
Example.love
(380 Bytes) Downloaded 78 times
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
szensk
Party member
Posts: 155
Joined: Sat Jan 19, 2013 3:57 am

Re: How Come Folders Can't Have a Dot in their Name?

Post by szensk »

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.

Code: Select all

require = function(path) 
  return assert(love.filesystem.load(path:gsub('%.([^%.]*)$', '/%1.lua')))()
end
User avatar
undef
Party member
Posts: 438
Joined: Mon Jun 10, 2013 3:09 pm
Location: Berlin
Contact:

Re: How Come Folders Can't Have a Dot in their Name?

Post by undef »

This behaviour is normal in Lua:
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.
source
twitter | steam | indieDB

Check out quadrant on Steam!
davisdude
Party member
Posts: 1154
Joined: Sun Apr 28, 2013 3:29 am
Location: North Carolina

Re: How Come Folders Can't Have a Dot in their Name?

Post by davisdude »

Good to know, thanks. :)
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
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests