diff options
| -rw-r--r-- | src/intercopycontext.cpp | 6 | ||||
| -rw-r--r-- | unit_tests/scripts/misc/verbose_errors.lua | 9 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/intercopycontext.cpp b/src/intercopycontext.cpp index 0ccd619..4be1883 100644 --- a/src/intercopycontext.cpp +++ b/src/intercopycontext.cpp | |||
| @@ -494,8 +494,12 @@ void InterCopyContext::interCopyKeyValuePair() const | |||
| 494 | *std::format_to(_valPath, "{}[U:{}]", name, _key) = 0; | 494 | *std::format_to(_valPath, "{}[U:{}]", name, _key) = 0; |
| 495 | } else if (luaW_type(L1, _key_i) == LuaType::BOOLEAN) { | 495 | } else if (luaW_type(L1, _key_i) == LuaType::BOOLEAN) { |
| 496 | int const _key{ lua_toboolean(L1, _key_i) }; | 496 | int const _key{ lua_toboolean(L1, _key_i) }; |
| 497 | _valPath = static_cast<char*>(alloca(name.size() + 8)); // +8 for [], 'false' and terminating 0 | 497 | _valPath = static_cast<char*>(alloca(name.size() + 8)); // +8 for [false] and terminating 0 |
| 498 | *std::format_to(_valPath, "{}[{}]", name, _key ? "true" : "false") = 0; | 498 | *std::format_to(_valPath, "{}[{}]", name, _key ? "true" : "false") = 0; |
| 499 | } else if (luaW_type(L1, _key_i) == LuaType::USERDATA) { | ||
| 500 | // I don't want to invoke tostring on the userdata to get its name | ||
| 501 | _valPath = static_cast<char*>(alloca(name.size() + 11)); // +11 for [U:<FULL>] and terminating 0 | ||
| 502 | *std::format_to(_valPath, "{}[U:<FULL>]", name) = 0; | ||
| 499 | } | 503 | } |
| 500 | } | 504 | } |
| 501 | 505 | ||
diff --git a/unit_tests/scripts/misc/verbose_errors.lua b/unit_tests/scripts/misc/verbose_errors.lua index b38bf4c..8127980 100644 --- a/unit_tests/scripts/misc/verbose_errors.lua +++ b/unit_tests/scripts/misc/verbose_errors.lua | |||
| @@ -21,9 +21,13 @@ local do_test = function(key_) | |||
| 21 | local x, y = string.find(e, "arg#2.subtable[" .. key_ .. "].ud", 1, true) | 21 | local x, y = string.find(e, "arg#2.subtable[" .. key_ .. "].ud", 1, true) |
| 22 | assert(x and y, "got " .. e) | 22 | assert(x and y, "got " .. e) |
| 23 | elseif t_key == "userdata" then | 23 | elseif t_key == "userdata" then |
| 24 | local t_name | 24 | -- light userdata results in "userdata: <some uppercase hex value>" |
| 25 | local stringified_key = tostring(key_) | ||
| 26 | local hex = string.match(stringified_key, "userdata: (%x+)") | ||
| 27 | -- full userdata results in something else | ||
| 28 | local t_name = hex and ("0x" .. string.lower(hex)) or "<FULL>" | ||
| 25 | -- light userdata is formatted by std::format, where the pointer is written as a lowercase hex literal | 29 | -- light userdata is formatted by std::format, where the pointer is written as a lowercase hex literal |
| 26 | local expected = "arg#2.subtable[U:0x" .. string.lower(string.match(tostring(key_), "userdata: (%x+)")) .. "].ud" | 30 | local expected = "arg#2.subtable[U:" .. t_name .. "].ud" |
| 27 | -- expecting an error about arg#2.subtable[U:0x<some hex value>].ud | 31 | -- expecting an error about arg#2.subtable[U:0x<some hex value>].ud |
| 28 | local x, y = string.find(e, expected, 1, true) | 32 | local x, y = string.find(e, expected, 1, true) |
| 29 | assert(x and y, "expecting " .. expected .. " got " .. e) | 33 | assert(x and y, "expecting " .. expected .. " got " .. e) |
| @@ -36,3 +40,4 @@ do_test(false) | |||
| 36 | do_test(42) | 40 | do_test(42) |
| 37 | do_test(42.44) | 41 | do_test(42.44) |
| 38 | do_test(lanes.null) | 42 | do_test(lanes.null) |
| 43 | do_test(l) | ||
