From fb26ab9c9e27cabb4c98b5f391eadf1dcf776cc0 Mon Sep 17 00:00:00 2001 From: Olivia Appleton Date: Thu, 19 Sep 2024 21:06:14 -0500 Subject: [PATCH] Attempt file io in lua (2) --- lua/src/lib/utils.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lua/src/lib/utils.lua b/lua/src/lib/utils.lua index 49c54db7..13896510 100644 --- a/lua/src/lib/utils.lua +++ b/lua/src/lib/utils.lua @@ -1,5 +1,6 @@ local function get_data_file(name, mode) - local file = io.open("../_data/" .. name, mode) + local filename = "../_data/" .. name + local file = io.open(filename, mode) if not file then print("Could not open file: " .. filename) @@ -25,9 +26,9 @@ local function get_answer(id) if type_ == 'str' then return value - else if type_ == 'int' then + elseif type_ == 'int' then return tonumber(value) - else if type_ == 'uint' then + elseif type_ == 'uint' then if length < 64 then return tonumber(value) end @@ -39,6 +40,7 @@ local function get_answer(id) end end end + return nil, "Answer not found" end return {