From 85ed36de5112afc73bf653b635285cbac176d25e Mon Sep 17 00:00:00 2001 From: UnlegitDqrk Date: Mon, 2 Mar 2026 11:58:39 +0100 Subject: [PATCH] Fixed issue: #101 --- core/src/main/java/org/luaj/vm2/Globals.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/luaj/vm2/Globals.java b/core/src/main/java/org/luaj/vm2/Globals.java index 76d9c6c4..2fd8f4f7 100644 --- a/core/src/main/java/org/luaj/vm2/Globals.java +++ b/core/src/main/java/org/luaj/vm2/Globals.java @@ -179,10 +179,22 @@ public class Globals extends LuaTable { * @throws LuaError if the file could not be loaded. */ public LuaValue loadfile(String filename) { + InputStream is = null; try { - return load(finder.findResource(filename), "@"+filename, "bt", this); + is = finder.findResource(filename); + if (is == null) { + return error("cannot open " + filename + ": No such file or directory"); + } + return load(is, "@"+filename, "bt", this); } catch (Exception e) { return error("load "+filename+": "+e); + } finally { + if (is != null) { + try { + is.close(); + } catch (Exception ignored) { + } + } } }