From 3bd77fb8021ba380abcd61db14f42f136dc2953a Mon Sep 17 00:00:00 2001 From: Fabien Fleutot Date: Mon, 3 Nov 2008 00:17:15 +0100 Subject: [PATCH] fixed incorrect behavior for loadstring() and loadfile() when metalua.compiler is required --- src/compiler/mlc.mlua | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/compiler/mlc.mlua b/src/compiler/mlc.mlua index d317f0c..90cdc9a 100644 --- a/src/compiler/mlc.mlua +++ b/src/compiler/mlc.mlua @@ -156,14 +156,17 @@ function loadstring(str, name) 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) -- 2.11.4.GIT