Skip to content

Commit

Permalink
Give includeexternal() the same error love that include() has had
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-sim committed Sep 28, 2024
1 parent d14bef8 commit 85f7301
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/base/api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,26 @@
---

function includeexternal(fname)
fname, compiled_chunk = p.findProjectScript(fname)
local wasIncludingExternal = api._isIncludingExternal
api._isIncludingExternal = true
compiled_chunk()
api._isIncludingExternal = wasIncludingExternal
local findOK, foundFnameOrErr, compiled_chunk = pcall(function () return p.findProjectScript(fname) end)
if findOK then
local wasIncludingExternal = api._isIncludingExternal
api._isIncludingExternal = true
local callOK, res = pcall(compiled_chunk)
api._isIncludingExternal = wasIncludingExternal

if callOK then
-- res is the return value of the script
return res
else
local err = res
local caller = filelineinfo(2)
premake.error(caller .. ": includeexternal(" .. fname .. ") execution error: " .. err)
end
else
local err = foundFnameOrErr
local caller = filelineinfo(2)
premake.error(caller .. ": includeexternal(" .. fname .. ") not found: " .. err)
end
end

p.alias(_G, "includeexternal", "includeExternal")
Expand Down

0 comments on commit 85f7301

Please sign in to comment.