diff options
author | Li Jin <dragon-fly@qq.com> | 2023-03-27 17:02:56 +0800 |
---|---|---|
committer | Li Jin <dragon-fly@qq.com> | 2023-03-27 17:02:56 +0800 |
commit | 0a55542c9a2eb958afe4fc6797b5400902c1e058 (patch) | |
tree | 9b941ea017203779da246ed691e9e2f79c1652d7 | |
parent | e57cc71c1a5860d7fd34c590c2f1d282b842075e (diff) | |
download | yuescript-0a55542c9a2eb958afe4fc6797b5400902c1e058.tar.gz yuescript-0a55542c9a2eb958afe4fc6797b5400902c1e058.tar.bz2 yuescript-0a55542c9a2eb958afe4fc6797b5400902c1e058.zip |
fix issue #131.
-rw-r--r-- | src/yuescript/stacktraceplus.h | 56 |
1 files changed, 28 insertions, 28 deletions
diff --git a/src/yuescript/stacktraceplus.h b/src/yuescript/stacktraceplus.h index 4b6f370..6025daa 100644 --- a/src/yuescript/stacktraceplus.h +++ b/src/yuescript/stacktraceplus.h | |||
@@ -266,23 +266,23 @@ function Dumper:DumpLocals (level) | |||
266 | if not name then | 266 | if not name then |
267 | return | 267 | return |
268 | end | 268 | end |
269 | self:add("\tLocal variables:\r\n") | 269 | self:add("\tLocal variables:\n") |
270 | while name do | 270 | while name do |
271 | if type(value) == "number" then | 271 | if type(value) == "number" then |
272 | self:add_f("%s%s = number: %g\r\n", prefix, name, value) | 272 | self:add_f("%s%s = number: %g\n", prefix, name, value) |
273 | elseif type(value) == "boolean" then | 273 | elseif type(value) == "boolean" then |
274 | self:add_f("%s%s = boolean: %s\r\n", prefix, name, tostring(value)) | 274 | self:add_f("%s%s = boolean: %s\n", prefix, name, tostring(value)) |
275 | elseif type(value) == "string" then | 275 | elseif type(value) == "string" then |
276 | self:add_f("%s%s = string: %q\r\n", prefix, name, value) | 276 | self:add_f("%s%s = string: %q\n", prefix, name, value) |
277 | elseif type(value) == "userdata" then | 277 | elseif type(value) == "userdata" then |
278 | self:add_f("%s%s = %s\r\n", prefix, name, safe_tostring(value)) | 278 | self:add_f("%s%s = %s\n", prefix, name, safe_tostring(value)) |
279 | elseif type(value) == "nil" then | 279 | elseif type(value) == "nil" then |
280 | self:add_f("%s%s = nil\r\n", prefix, name) | 280 | self:add_f("%s%s = nil\n", prefix, name) |
281 | elseif type(value) == "table" then | 281 | elseif type(value) == "table" then |
282 | if m_known_tables[value] then | 282 | if m_known_tables[value] then |
283 | self:add_f("%s%s = %s\r\n", prefix, name, m_known_tables[value]) | 283 | self:add_f("%s%s = %s\n", prefix, name, m_known_tables[value]) |
284 | elseif m_user_known_tables[value] then | 284 | elseif m_user_known_tables[value] then |
285 | self:add_f("%s%s = %s\r\n", prefix, name, m_user_known_tables[value]) | 285 | self:add_f("%s%s = %s\n", prefix, name, m_user_known_tables[value]) |
286 | else | 286 | else |
287 | local txt = "{" | 287 | local txt = "{" |
288 | for k,v in pairs(value) do | 288 | for k,v in pairs(value) do |
@@ -293,13 +293,13 @@ function Dumper:DumpLocals (level) | |||
293 | end | 293 | end |
294 | if next(value, k) then txt = txt..", " end | 294 | if next(value, k) then txt = txt..", " end |
295 | end | 295 | end |
296 | self:add_f("%s%s = %s %s\r\n", prefix, name, safe_tostring(value), txt.."}") | 296 | self:add_f("%s%s = %s %s\n", prefix, name, safe_tostring(value), txt.."}") |
297 | end | 297 | end |
298 | elseif type(value) == "function" then | 298 | elseif type(value) == "function" then |
299 | local info = self.getinfo(value, "nS") | 299 | local info = self.getinfo(value, "nS") |
300 | local fun_name = info.name or m_known_functions[value] or m_user_known_functions[value] | 300 | local fun_name = info.name or m_known_functions[value] or m_user_known_functions[value] |
301 | if info.what == "C" then | 301 | if info.what == "C" then |
302 | self:add_f("%s%s = C %s\r\n", prefix, name, (fun_name and ("function: " .. fun_name) or tostring(value))) | 302 | self:add_f("%s%s = C %s\n", prefix, name, (fun_name and ("function: " .. fun_name) or tostring(value))) |
303 | else | 303 | else |
304 | local source = info.short_src | 304 | local source = info.short_src |
305 | if source:sub(2,7) == "string" then | 305 | if source:sub(2,7) == "string" then |
@@ -307,10 +307,10 @@ function Dumper:DumpLocals (level) | |||
307 | end | 307 | end |
308 | --for k,v in pairs(info) do print(k,v) end | 308 | --for k,v in pairs(info) do print(k,v) end |
309 | fun_name = fun_name or GuessFunctionName(info) | 309 | fun_name = fun_name or GuessFunctionName(info) |
310 | self:add_f("%s%s = Lua function '%s' (defined at line %d of chunk %s)\r\n", prefix, name, fun_name, info.linedefined, source) | 310 | self:add_f("%s%s = Lua function '%s' (defined at line %d of chunk %s)\n", prefix, name, fun_name, info.linedefined, source) |
311 | end | 311 | end |
312 | elseif type(value) == "thread" then | 312 | elseif type(value) == "thread" then |
313 | self:add_f("%sthread %q = %s\r\n", prefix, name, tostring(value)) | 313 | self:add_f("%sthread %q = %s\n", prefix, name, tostring(value)) |
314 | end | 314 | end |
315 | i = i + 1 | 315 | i = i + 1 |
316 | name, value = self.getlocal(level, i) | 316 | name, value = self.getlocal(level, i) |
@@ -383,20 +383,20 @@ function _M.stacktrace(thread, message, level) | |||
383 | local dumper = Dumper.new(thread) | 383 | local dumper = Dumper.new(thread) |
384 | 384 | ||
385 | if type(message) == "table" then | 385 | if type(message) == "table" then |
386 | dumper:add("an error object {\r\n") | 386 | dumper:add("an error object {\n") |
387 | local first = true | 387 | local first = true |
388 | for k,v in pairs(message) do | 388 | for k,v in pairs(message) do |
389 | if first then | 389 | if first then |
390 | dumper:add(" ") | 390 | dumper:add(" ") |
391 | first = false | 391 | first = false |
392 | else | 392 | else |
393 | dumper:add(",\r\n ") | 393 | dumper:add(",\n ") |
394 | end | 394 | end |
395 | dumper:add(safe_tostring(k)) | 395 | dumper:add(safe_tostring(k)) |
396 | dumper:add(": ") | 396 | dumper:add(": ") |
397 | dumper:add(safe_tostring(v)) | 397 | dumper:add(safe_tostring(v)) |
398 | end | 398 | end |
399 | dumper:add("\r\n}") | 399 | dumper:add("\n}") |
400 | elseif type(message) == "string" then | 400 | elseif type(message) == "string" then |
401 | local fname, line, msg = message:match('([^\n]+):(%d+): (.*)$') | 401 | local fname, line, msg = message:match('([^\n]+):(%d+): (.*)$') |
402 | if fname then | 402 | if fname then |
@@ -425,7 +425,7 @@ function _M.stacktrace(thread, message, level) | |||
425 | dumper:add(message) | 425 | dumper:add(message) |
426 | end | 426 | end |
427 | 427 | ||
428 | dumper:add("\r\n") | 428 | dumper:add("\n") |
429 | dumper:add[[ | 429 | dumper:add[[ |
430 | Stack Traceback | 430 | Stack Traceback |
431 | =============== | 431 | =============== |
@@ -444,20 +444,20 @@ Stack Traceback | |||
444 | info.source, info.currentline = getYueLineNumber(info.source, info.currentline) | 444 | info.source, info.currentline = getYueLineNumber(info.source, info.currentline) |
445 | if info.what == "main" then | 445 | if info.what == "main" then |
446 | if _M.simplified then | 446 | if _M.simplified then |
447 | dumper:add_f("(%d) '%s':%d\r\n", level_to_show, info.source, info.currentline) | 447 | dumper:add_f("(%d) '%s':%d\n", level_to_show, info.source, info.currentline) |
448 | else | 448 | else |
449 | dumper:add_f("(%d) main chunk of file '%s' at line %d\r\n", level_to_show, info.source, info.currentline) | 449 | dumper:add_f("(%d) main chunk of file '%s' at line %d\n", level_to_show, info.source, info.currentline) |
450 | end | 450 | end |
451 | elseif info.what == "C" then | 451 | elseif info.what == "C" then |
452 | --print(info.namewhat, info.name) | 452 | --print(info.namewhat, info.name) |
453 | --for k,v in pairs(info) do print(k,v, type(v)) end | 453 | --for k,v in pairs(info) do print(k,v, type(v)) end |
454 | local function_name = m_user_known_functions[info.func] or m_known_functions[info.func] or info.name or tostring(info.func) | 454 | local function_name = m_user_known_functions[info.func] or m_known_functions[info.func] or info.name or tostring(info.func) |
455 | dumper:add_f("(%d) %s C function '%s'\r\n", level_to_show, info.namewhat, function_name) | 455 | dumper:add_f("(%d) %s C function '%s'\n", level_to_show, info.namewhat, function_name) |
456 | --dumper:add_f("%s%s = C %s\r\n", prefix, name, (m_known_functions[value] and ("function: " .. m_known_functions[value]) or tostring(value))) | 456 | --dumper:add_f("%s%s = C %s\n", prefix, name, (m_known_functions[value] and ("function: " .. m_known_functions[value]) or tostring(value))) |
457 | elseif info.what == "tail" then | 457 | elseif info.what == "tail" then |
458 | --print("tail") | 458 | --print("tail") |
459 | --for k,v in pairs(info) do print(k,v, type(v)) end--print(info.namewhat, info.name) | 459 | --for k,v in pairs(info) do print(k,v, type(v)) end--print(info.namewhat, info.name) |
460 | dumper:add_f("(%d) tail call\r\n", level_to_show) | 460 | dumper:add_f("(%d) tail call\n", level_to_show) |
461 | dumper:DumpLocals(level) | 461 | dumper:DumpLocals(level) |
462 | elseif info.what == "Lua" then | 462 | elseif info.what == "Lua" then |
463 | local source = info.source | 463 | local source = info.source |
@@ -475,26 +475,26 @@ Stack Traceback | |||
475 | local function_type = (info.namewhat == "") and "function" or info.namewhat | 475 | local function_type = (info.namewhat == "") and "function" or info.namewhat |
476 | if info.source and info.source:sub(1, 1) == "@" then | 476 | if info.source and info.source:sub(1, 1) == "@" then |
477 | if _M.simplified then | 477 | if _M.simplified then |
478 | dumper:add_f("(%d) '%s':%d%s\r\n", level_to_show, info.source:sub(2), info.currentline, was_guessed and " (guess)" or "") | 478 | dumper:add_f("(%d) '%s':%d%s\n", level_to_show, info.source:sub(2), info.currentline, was_guessed and " (guess)" or "") |
479 | else | 479 | else |
480 | dumper:add_f("(%d) Lua %s '%s' at file '%s':%d%s\r\n", level_to_show, function_type, function_name, info.source:sub(2), info.currentline, was_guessed and " (best guess)" or "") | 480 | dumper:add_f("(%d) Lua %s '%s' at file '%s':%d%s\n", level_to_show, function_type, function_name, info.source:sub(2), info.currentline, was_guessed and " (best guess)" or "") |
481 | end | 481 | end |
482 | elseif info.source and info.source:sub(1,1) == '#' then | 482 | elseif info.source and info.source:sub(1,1) == '#' then |
483 | if _M.simplified then | 483 | if _M.simplified then |
484 | dumper:add_f("(%d) '%s':%d%s\r\n", level_to_show, info.source:sub(2), info.currentline, was_guessed and " (guess)" or "") | 484 | dumper:add_f("(%d) '%s':%d%s\n", level_to_show, info.source:sub(2), info.currentline, was_guessed and " (guess)" or "") |
485 | else | 485 | else |
486 | dumper:add_f("(%d) Lua %s '%s' at template '%s':%d%s\r\n", level_to_show, function_type, function_name, info.source:sub(2), info.currentline, was_guessed and " (best guess)" or "") | 486 | dumper:add_f("(%d) Lua %s '%s' at template '%s':%d%s\n", level_to_show, function_type, function_name, info.source:sub(2), info.currentline, was_guessed and " (best guess)" or "") |
487 | end | 487 | end |
488 | else | 488 | else |
489 | if _M.simplified then | 489 | if _M.simplified then |
490 | dumper:add_f("(%d) '%s':%d\r\n", level_to_show, source, info.currentline) | 490 | dumper:add_f("(%d) '%s':%d\n", level_to_show, source, info.currentline) |
491 | else | 491 | else |
492 | dumper:add_f("(%d) Lua %s '%s' at chunk '%s':%d\r\n", level_to_show, function_type, function_name, source, info.currentline) | 492 | dumper:add_f("(%d) Lua %s '%s' at chunk '%s':%d\n", level_to_show, function_type, function_name, source, info.currentline) |
493 | end | 493 | end |
494 | end | 494 | end |
495 | dumper:DumpLocals(level) | 495 | dumper:DumpLocals(level) |
496 | else | 496 | else |
497 | dumper:add_f("(%d) unknown frame %s\r\n", level_to_show, info.what) | 497 | dumper:add_f("(%d) unknown frame %s\n", level_to_show, info.what) |
498 | end | 498 | end |
499 | 499 | ||
500 | level = level + 1 | 500 | level = level + 1 |