yue.loadfile should not throw errors
johnd0e opened this issue · 1 comments
johnd0e commented
At the moment I'm trying to use yue
as drop-in replacement for moonscript
.
And I found that yue.loadfile
behaves differently.
> local yue = require("yue")
> yue.loadfile("not_existent_path")
(yuescript):115: bad argument #1 to 'to_lua' (string expected, got nil)
stack traceback:
[C]: in function 'to_lua'
(yuescript):115: in function 'loadfile'
stdin:1: in main chunk
[C]: at 0x004021a0
I see here two inconsistecies:
loadfile
inmoonscript
(as well as standard lua loadfile) does not throw errors: it return errors as message instead.- The message itself is not very helpful.
pigpigyyy commented
Just updated a version and forgot fixing this problem. You might use
local yue = require("yue")
local function yue_loadfile(fname, ...)
local res, err = yue.read_file(fname)
if not res then
return nil, err
end
return yue.loadstring(res, fname, ...)
end
Before making another release.