local n = str:match '^#![^\n]*\n()'
if n then str=str:sub(n, -1) end
-- FIXME: handle erroneous returns (return nil + error msg)
- return mlc.function_of_luastring(str, name)
+ local success, f = pcall (mlc.function_of_luastring, str, name)
+ if success then return f else return nil, f end
end
function loadfile(filename)
- local f = io.open(filename, 'rb')
- local src = f:read '*a'
- f:close()
- return loadstring(src, '@'..filename)
+ local f, err_msg = io.open(filename, 'rb')
+ if not f then return nil, err_msg end
+ local success, src = pcall( f.read, f, '*a')
+ pcall(f.close, f)
+ if success then return loadstring (src, '@'..filename)
+ else return nil, src end
end
function load(f, name)