Skip to content

Commit 53f3293

Browse files
committed
Context information is now stored on Lua's call stack. (No more pcalls or non-string error objects!)
All errors now at least log the traceback. Auto-build now uses pcall.
1 parent 6a5282d commit 53f3293

File tree

8 files changed

+1074
-1091
lines changed

8 files changed

+1074
-1091
lines changed

build/meta.lua

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
loadParams
2222
makeDirectory, makeDirectoryRecursive, removeDirectory, removeDirectoryRecursive
2323
NOSPACE
24+
PUSH_CONTEXT, POP_CONTEXT
2425
readFile, writeFile, writeTextFile
2526
templateToLua
2627
templateToString, templateToStringUtf16
2728
toWindowsPath
2829
traverseDirectory
2930
utf16ToUtf8, utf8ToUtf16
30-
XPCALL
3131
zipDirectory, zipFiles
3232
3333
--============================================================]]
@@ -72,7 +72,7 @@ function _G.loadParams()
7272
if not (line == "" or line:find"^#") then
7373
local k, v = line:match"^([%w_]+)%s*=%s*(.*)$"
7474
if not k then
75-
error(F("local/param.ini:%d: Bad line format: %s", ln, line))
75+
errorf("local/param.ini:%d: Bad line format: %s", ln, line)
7676
end
7777

7878
if k == "pathGpp32" then params.pathGpp32 = v
@@ -135,7 +135,7 @@ function _G.executeRequired(cmd, args)
135135

136136
local exitCode = os.execute(cmd)
137137
if exitCode ~= 0 then
138-
error(F("Got code %d from command: %s", exitCode, cmd))
138+
errorf("Got code %d from command: %s", exitCode, cmd)
139139
end
140140
end
141141

@@ -146,7 +146,7 @@ end
146146
function _G.templateToString(s, values, formatter)
147147
return (s:gsub("${(%w+)}", function(k)
148148
local v = values[k]
149-
if not v then error(F("No value '%s'.", k)) end
149+
if not v then errorf("No value '%s'.", k) end
150150
if formatter then v = formatter(v) end
151151
return v
152152
end))
@@ -158,7 +158,7 @@ function _G.templateToStringUtf16(params, s, values, formatter)
158158
return (s:gsub("$%z{%z([%w%z]+)}%z", function(k)
159159
k = utf16ToUtf8(params, k)
160160
local v = values[k]
161-
if not v then error(F("No value '%s'.", k)) end
161+
if not v then errorf("No value '%s'.", k) end
162162
if formatter then v = formatter(v) end
163163
return utf8ToUtf16(params, v)
164164
end))
@@ -297,7 +297,7 @@ function _G.makeDirectory(dir)
297297

298298
local ok, err = lfs.mkdir(dir)
299299
if not ok then
300-
error(F("Could not make directory '%s'. (%s)", dir, err))
300+
errorf("Could not make directory '%s'. (%s)", dir, err)
301301
end
302302
end
303303
function _G.makeDirectoryRecursive(dir)
@@ -311,7 +311,7 @@ function _G.removeDirectory(dir)
311311

312312
local ok, err = lfs.rmdir(dir)
313313
if not ok then
314-
error(F("Could not remove directory '%s'. (%s)", dir, err))
314+
errorf("Could not remove directory '%s'. (%s)", dir, err)
315315
end
316316
end
317317
function _G.removeDirectoryRecursive(dir)
@@ -375,14 +375,6 @@ end
375375

376376

377377

378-
-- ok, err = !XPCALL `lua`
379-
function XPCALL(lua)
380-
__LUA"xpcall(function() "
381-
__LUA(lua)
382-
__LUA" end, xpcallErrorHandler)"
383-
end
384-
385-
386378
do
387379
local function outputArgumentChecks(errLevel, argsStr)
388380
local optionalPos = argsStr:find("?", 1, true) or #argsStr
@@ -438,3 +430,20 @@ end
438430

439431

440432

433+
local ctxName
434+
435+
function _G.PUSH_CONTEXT(_ctxName)
436+
ctxName = _ctxName
437+
__LUA"do "
438+
__LUA"local function "__LUA(ctxName)__LUA"Context(ctx)"
439+
end
440+
441+
function _G.POP_CONTEXT()
442+
__LUA"end "
443+
__LUA"local ctx = pushContext("__VAL(ctxName)__LUA", "__LUA(ctxName)__LUA"Context) "
444+
__LUA(ctxName)__LUA"Context(ctx) "
445+
__LUA"end"
446+
end
447+
448+
449+

lib/toml.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,12 @@ TOML.parse = function(toml, options)
8989
end
9090
line = line + 1
9191
end
92-
error("TOML: " .. message .. " on line " .. line .. ".", 4)
92+
-- @Edit:
93+
if options.pathForErrors then
94+
error(options.pathForErrors .. ":" .. line .. ": [TOML] " .. message .. ".", 0)
95+
else
96+
error("[TOML] " .. message .. " on line " .. line .. ".", 4)
97+
end
9398
end
9499
end
95100

0 commit comments

Comments
 (0)