From cf71a5ddc742692fad813f89f1c9ef53e1ffde0f Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 13 Mar 2019 13:16:53 -0300 Subject: 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) --- testes/api.lua | 21 ++++++++++++++------- testes/strings.lua | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'testes') 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) return T.testC(string.format("%s %d; return 1", s, n), x) end +local null = T.pushuserdata(0) local hfunc = string.gmatch("", "") -- a "heavy C function" (with upvalues) assert(debug.getupvalue(hfunc, 1)) assert(to("tostring", {}) == nil) @@ -349,13 +350,19 @@ assert(to("tonumber", {}) == 0) assert(to("tonumber", "12") == 12) assert(to("tonumber", "s2") == 0) assert(to("tonumber", 1, 20) == 0) -assert(to("topointer", 10) == 0) -assert(to("topointer", true) == 0) -assert(to("topointer", T.pushuserdata(20)) == 20) -assert(to("topointer", io.read) ~= 0) -- light C function -assert(to("topointer", hfunc) ~= 0) -- "heavy" C function -assert(to("topointer", function () end) ~= 0) -- Lua function -assert(to("topointer", io.stdin) ~= 0) -- full userdata +assert(to("topointer", 10) == null) +assert(to("topointer", true) == null) +assert(to("topointer", nil) == null) +assert(to("topointer", "abc") ~= null) +assert(to("topointer", string.rep("x", 10)) == + to("topointer", string.rep("x", 10))) -- short strings +assert(to("topointer", string.rep("x", 300)) ~= + to("topointer", string.rep("x", 300))) -- long strings +assert(to("topointer", T.pushuserdata(20)) ~= null) +assert(to("topointer", io.read) ~= null) -- light C function +assert(to("topointer", hfunc) ~= null) -- "heavy" C function +assert(to("topointer", function () end) ~= null) -- Lua function +assert(to("topointer", io.stdin) ~= null) -- full userdata assert(to("func2num", 20) == 0) assert(to("func2num", T.pushuserdata(10)) == 0) assert(to("func2num", io.read) ~= 0) -- light C function diff --git a/testes/strings.lua b/testes/strings.lua index 88480924..da53a87e 100644 --- a/testes/strings.lua +++ b/testes/strings.lua @@ -199,6 +199,7 @@ end assert(string.format("\0%s\0", "\0\0\1") == "\0\0\0\1\0") checkerror("contains zeros", string.format, "%10s", "\0") +checkerror("cannot have modifiers", string.format, "%10q", "1") -- format x tostring assert(string.format("%s %s", nil, true) == "nil true") -- cgit v1.2.3-55-g6feb