Page 1 of 1
love.filesystem.load() doesn't catch syntax errors?
Posted: Sat Nov 17, 2018 7:31 pm
by NetherGranite
loadfile() catches syntax errors, but love.filesystem.load() does not, meaning that calls to it have to be wrapped in pcall or xpcall if you are not sure whether the file you are loading is error-free. Is this intentional? I assumed love.filesystem.load() would use loadfile() internally, just with the added functionality of searching for the file in more places; am I wrong?
Re: love.filesystem.load() doesn't catch syntax errors?
Posted: Sat Nov 17, 2018 7:48 pm
by zorg
According to the code, love.filesystem.load should indeed catch most errors:
https://bitbucket.org/rude/love/src/992 ... #lines-604
(Also, it uses PhysFS under the hood, like the rest of love.filesystem)
Maybe give us a testcase where it fails for you?
Re: love.filesystem.load() doesn't catch syntax errors?
Posted: Sat Nov 17, 2018 8:12 pm
by NetherGranite
zorg wrote: ↑Sat Nov 17, 2018 7:48 pm
Maybe give us a testcase where it fails for you?
main.lua:
file.lua:
Running this project throws this error:
Code: Select all
Error
main.lua:1: Syntax error: file.lua:2: '=' expected near '<eof>'
Traceback
[C]: in function 'load'
main.lua:1: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
Re: love.filesystem.load() doesn't catch syntax errors?
Posted: Sun Dec 30, 2018 10:39 am
by NetherGranite
Is bumping this thread appropriate?
Re: love.filesystem.load() doesn't catch syntax errors?
Posted: Sun Dec 30, 2018 10:56 am
by grump
NetherGranite wrote: ↑Sat Nov 17, 2018 8:12 pm
main.lua:
file.lua:
Running this project throws this error:
Code: Select all
Error
main.lua:1: Syntax error: file.lua:2: '=' expected near '<eof>'
Traceback
[C]: in function 'load'
main.lua:1: in main chunk
[C]: in function 'require'
[C]: in function 'xpcall'
[C]: in function 'xpcall'
There is probably an error, but you're not doing anything with that information. Try
Code: Select all
assert(love.filesystem.load("file.lua"))
If load returns nil, it also returns an error message.