aboutsummaryrefslogtreecommitdiff
path: root/testes/locals.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-12-29 13:15:54 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2020-12-29 13:15:54 -0300
commit4bd10b6fe81c0a56eb9e01e24fba10e655966870 (patch)
treeff21703d9f06a0dd4ca4f3317dd0cb7b048c9b8d /testes/locals.lua
parent59e565d9555c07e82808d8c1db8f4f4d159b5e5c (diff)
downloadlua-4bd10b6fe81c0a56eb9e01e24fba10e655966870.tar.gz
lua-4bd10b6fe81c0a56eb9e01e24fba10e655966870.tar.bz2
lua-4bd10b6fe81c0a56eb9e01e24fba10e655966870.zip
Better error messages for calling non-callable objects
When available, use the calling code to find a suitable name for what was being called; this is particularly useful for errors of non-callable metamethods. This commit also improved the debug information for order metamethods.
Diffstat (limited to 'testes/locals.lua')
-rw-r--r--testes/locals.lua17
1 files changed, 16 insertions, 1 deletions
diff --git a/testes/locals.lua b/testes/locals.lua
index 1b43609b..add023ca 100644
--- a/testes/locals.lua
+++ b/testes/locals.lua
@@ -459,7 +459,22 @@ do -- errors due to non-closable values
459 getmetatable(xyz).__close = nil -- remove metamethod 459 getmetatable(xyz).__close = nil -- remove metamethod
460 end 460 end
461 local stat, msg = pcall(foo) 461 local stat, msg = pcall(foo)
462 assert(not stat and string.find(msg, "attempt to call a nil value")) 462 assert(not stat and string.find(msg, "metamethod 'close'"))
463
464 local function foo ()
465 local a1 <close> = func2close(function (_, msg)
466 assert(string.find(msg, "number value"))
467 error(12)
468 end)
469 local a2 <close> = setmetatable({}, {__close = print})
470 local a3 <close> = func2close(function (_, msg)
471 assert(msg == nil)
472 error(123)
473 end)
474 getmetatable(a2).__close = 4 -- invalidate metamethod
475 end
476 local stat, msg = pcall(foo)
477 assert(not stat and msg == 12)
463end 478end
464 479
465 480