Skip to content

Commit 2cec8d3

Browse files
committed
refactoring
1 parent b975dbe commit 2cec8d3

File tree

1 file changed

+6
-12
lines changed
  • nattlua/definitions/lua/ffi/preprocessor

1 file changed

+6
-12
lines changed

nattlua/definitions/lua/ffi/preprocessor/parser.lua

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -831,6 +831,8 @@ do -- conditional compilation (#if, #ifdef, #ifndef, #else, #elif, #endif)
831831
end
832832

833833
do -- #include directive
834+
local fs = require("nattlua.other.fs")
835+
834836
local function resolve_include_path(self, filename, is_system_include)
835837
local opts = self.preprocess_options
836838

@@ -871,24 +873,16 @@ do -- #include directive
871873
-- Try to find the file
872874
for _, base_path in ipairs(search_paths) do
873875
local full_path = base_path .. "/" .. filename
874-
local file = io.open(full_path, "r")
876+
local content, err = fs.read(full_path)
875877

876-
if file then
877-
local content = file:read("*all")
878-
file:close()
879-
return content, full_path
880-
end
878+
if content then return content, full_path end
881879
end
882880

883881
-- Try absolute path
884882
if filename:sub(1, 1) == "/" then
885-
local file = io.open(filename, "r")
883+
local content, err = fs.read(filename)
886884

887-
if file then
888-
local content = file:read("*all")
889-
file:close()
890-
return content, filename
891-
end
885+
if content then return content, filename end
892886
end
893887

894888
return nil, "Include file not found: " .. filename

0 commit comments

Comments
 (0)