diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-13 13:16:53 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2019-03-13 13:16:53 -0300 |
| commit | cf71a5ddc742692fad813f89f1c9ef53e1ffde0f (patch) | |
| tree | df02305ff3cf05908f21829384e3a7f8699d2331 /testes/api.lua | |
| parent | 2c32bff60987d38a60a58d4f0123f3783da60a63 (diff) | |
| download | lua-cf71a5ddc742692fad813f89f1c9ef53e1ffde0f.tar.gz lua-cf71a5ddc742692fad813f89f1c9ef53e1ffde0f.tar.bz2 lua-cf71a5ddc742692fad813f89f1c9ef53e1ffde0f.zip | |
Details
Several small improvements (code style, warnings, comments, more tests),
in particular:
- 'lua_topointer' extended to handle strings
- raises an error in 'string.format("%10q")' ('%q' with modifiers)
- in the manual for 'string.format', the term "option" replaced by
"conversion specifier" (the term used by the C standard)
Diffstat (limited to 'testes/api.lua')
| -rw-r--r-- | testes/api.lua | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/testes/api.lua b/testes/api.lua index 9904dadf..d034ea80 100644 --- a/testes/api.lua +++ b/testes/api.lua | |||
| @@ -332,6 +332,7 @@ function to (s, x, n) | |||
| 332 | return T.testC(string.format("%s %d; return 1", s, n), x) | 332 | return T.testC(string.format("%s %d; return 1", s, n), x) |
| 333 | end | 333 | end |
| 334 | 334 | ||
| 335 | local null = T.pushuserdata(0) | ||
| 335 | local hfunc = string.gmatch("", "") -- a "heavy C function" (with upvalues) | 336 | local hfunc = string.gmatch("", "") -- a "heavy C function" (with upvalues) |
| 336 | assert(debug.getupvalue(hfunc, 1)) | 337 | assert(debug.getupvalue(hfunc, 1)) |
| 337 | assert(to("tostring", {}) == nil) | 338 | assert(to("tostring", {}) == nil) |
| @@ -349,13 +350,19 @@ assert(to("tonumber", {}) == 0) | |||
| 349 | assert(to("tonumber", "12") == 12) | 350 | assert(to("tonumber", "12") == 12) |
| 350 | assert(to("tonumber", "s2") == 0) | 351 | assert(to("tonumber", "s2") == 0) |
| 351 | assert(to("tonumber", 1, 20) == 0) | 352 | assert(to("tonumber", 1, 20) == 0) |
| 352 | assert(to("topointer", 10) == 0) | 353 | assert(to("topointer", 10) == null) |
| 353 | assert(to("topointer", true) == 0) | 354 | assert(to("topointer", true) == null) |
| 354 | assert(to("topointer", T.pushuserdata(20)) == 20) | 355 | assert(to("topointer", nil) == null) |
| 355 | assert(to("topointer", io.read) ~= 0) -- light C function | 356 | assert(to("topointer", "abc") ~= null) |
| 356 | assert(to("topointer", hfunc) ~= 0) -- "heavy" C function | 357 | assert(to("topointer", string.rep("x", 10)) == |
| 357 | assert(to("topointer", function () end) ~= 0) -- Lua function | 358 | to("topointer", string.rep("x", 10))) -- short strings |
| 358 | assert(to("topointer", io.stdin) ~= 0) -- full userdata | 359 | assert(to("topointer", string.rep("x", 300)) ~= |
| 360 | to("topointer", string.rep("x", 300))) -- long strings | ||
| 361 | assert(to("topointer", T.pushuserdata(20)) ~= null) | ||
| 362 | assert(to("topointer", io.read) ~= null) -- light C function | ||
| 363 | assert(to("topointer", hfunc) ~= null) -- "heavy" C function | ||
| 364 | assert(to("topointer", function () end) ~= null) -- Lua function | ||
| 365 | assert(to("topointer", io.stdin) ~= null) -- full userdata | ||
| 359 | assert(to("func2num", 20) == 0) | 366 | assert(to("func2num", 20) == 0) |
| 360 | assert(to("func2num", T.pushuserdata(10)) == 0) | 367 | assert(to("func2num", T.pushuserdata(10)) == 0) |
| 361 | assert(to("func2num", io.read) ~= 0) -- light C function | 368 | assert(to("func2num", io.read) ~= 0) -- light C function |
