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)
This commit is contained in:
Roberto Ierusalimschy
2019-03-13 13:16:53 -03:00
parent 2c32bff609
commit cf71a5ddc7
8 changed files with 87 additions and 51 deletions

View File

@@ -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