aboutsummaryrefslogtreecommitdiff
path: root/testes/errors.lua
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-11-19 14:09:18 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-11-19 14:09:18 -0300
commit50c7c915ee2fa239043d5456237f5145d064089b (patch)
tree386e17e4baa154bb60dc54c1a00c751e3adedde9 /testes/errors.lua
parentb117bdb3448778d9e7f9a0302791e8ac3bb97ddd (diff)
downloadlua-50c7c915ee2fa239043d5456237f5145d064089b.tar.gz
lua-50c7c915ee2fa239043d5456237f5145d064089b.tar.bz2
lua-50c7c915ee2fa239043d5456237f5145d064089b.zip
Debug information about extra arguments from __call
'debug.getinfo' can return number of extra arguments added to a call by a chain of __call metavalues. That information is being used to improve error messages about errors in these extra arguments.
Diffstat (limited to 'testes/errors.lua')
-rw-r--r--testes/errors.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/testes/errors.lua b/testes/errors.lua
index 80d91a92..0925fe58 100644
--- a/testes/errors.lua
+++ b/testes/errors.lua
@@ -117,6 +117,31 @@ else
117 return 1 117 return 1
118 ]] 118 ]]
119 assert(string.find(res, "xuxu.-main chunk")) 119 assert(string.find(res, "xuxu.-main chunk"))
120
121 do -- tests for error messages about extra arguments from __call
122 local function createobj (n)
123 -- function that raises an error on its n-th argument
124 local code = string.format("argerror %d 'msg'", n)
125 local func = T.makeCfunc(code)
126 -- create a chain of 2 __call objects
127 local M = setmetatable({}, {__call = func})
128 M = setmetatable({}, {__call = M})
129 -- put it as a method for a new object
130 return {foo = M}
131 end
132
133 _G.a = createobj(1) -- error in first (extra) argument
134 checkmessage("a:foo()", "bad extra argument #1")
135
136 _G.a = createobj(2) -- error in second (extra) argument
137 checkmessage("a:foo()", "bad extra argument #2")
138
139 _G.a = createobj(3) -- error in self (after two extra arguments)
140 checkmessage("a:foo()", "bad self")
141
142 _G.a = createobj(4) -- error in first regular argument (after self)
143 checkmessage("a:foo()", "bad argument #1")
144 end
120end 145end
121 146
122 147