love icon indicating copy to clipboard operation
love copied to clipboard

filesystem.getSourceBaseDirectory behavior is not compliant with the documentation

Open slime73 opened this issue 9 years ago • 3 comments

Original report by array93 (Bitbucket: array93, GitHub: array93).


A similar problem was reported under #892. Long story short: getSourceBaseDirectory does not always return full source base directory.

I have performed several tests. Here are the results with a brief introduction.

First of all, my testing environment.

D:\env
  - exe
    - main.exe
    - file.txt
  - love
    - main.love
  - lua
    - main.lua

Secondly, the code:

#!lua
function love.load()
  print '' -- just making the console output a little bit easier to copy
  print('isFused', love.filesystem.isFused())
  
  local baseDirectory = love.filesystem.getSourceBaseDirectory()
  print('baseDirectory', baseDirectory)

  print '\nfiles found:'
  love.filesystem.mount(baseDirectory, '') -- mounting at empty string, I believe the same thing happened when mounted on '/'
  love.filesystem.getDirectoryItems('/', print)
end

Now the results that look alright to me:

D:\env\src> love --console .
  isFused false
  baseDirectory   D:/env

  files found:
  main.lua

D:\env\src> love --console --fused .
  isFused true
  baseDirectory   D:/env

  files found:
  exe
  love
  main.lua
  src

D:\env\love> love --console main.love
  isFused false
  baseDirectory   D:/env/love

  files found:
  main.lua

D:\env> D:\env\exe\main.exe --console
  isFused true
  baseDirectory   D:\env\exe

  files found:
  file.txt
  main.exe
  main.lua

And the ones that look dodgy, one by one, with my comments:

D:\env\love> love --console --fused main.love
  isFused true
  baseDirectory   D:/env/love

  files found:
  main.love

Shouldn't files found also contain main.lua? getDirectoryItems is used to show all files at root directory.

D:\env\exe> main.exe --console
  isFused true
  baseDirectory

  files found:
  main.lua

baseDirectory is empty string.

D:\env\exe> main --console

Love starts with "no game" window.

D:\env> exe\main.exe --console
  isFused true
  baseDirectory   exe

  files found:
  file.txt
  main.exe
  main.lua

Base directory 'exe'

Citing the wiki (https://love2d.org/wiki/love.filesystem.getSourceBaseDirectory) Returns the full path to the directory containing the .love file.

Keep up the great work :)

slime73 avatar Oct 25 '15 11:10 slime73

Original comment by Bart van Strien (Bitbucket: bartbes, GitHub: bartbes).


I've not been able to reproduce any weirdness on linux. I always see main.lua, and baseDirectory is never empty, and always an absolute path. Maybe this only affects windows?

slime73 avatar Mar 20 '16 15:03 slime73

Original comment by Premek (Bitbucket: premek, GitHub: premek).


One more case that I'm experiencing on linux:

#!bash
premek@nuc:~/prog/forest$ ls src/main.lua 
src/main.lua
premek@nuc:~/prog/forest$ love src/
SourceBaseDirectory /home/premek/prog/forest
WorkingDirectory    /home/premek/prog/forest

The name of the 'src' folder is lost and inacessible from lua. Is this correct? The documentation mentions only .love file but what about when you point to the directory and not the .love file?

slime73 avatar Sep 07 '16 22:09 slime73

Original comment by Bart van Strien (Bitbucket: bartbes, GitHub: bartbes).


That is correct, it's the path that contains the source. To love there's really no difference between a .love file and a directory. You can get the actual source with the (currently undocumented) love.filesystem.getSource() function.

slime73 avatar Sep 16 '16 18:09 slime73