elua: perform conversion beforehand

This commit is contained in:
Daniel Kolesa 2014-05-09 13:26:37 +01:00 committed by Daniel Kolesa
parent 654653bc4a
commit ebbce82403
1 changed files with 8 additions and 5 deletions

View File

@ -248,17 +248,20 @@ end
-- simulates lua's coercion
local checktype = function(c, idx, val)
if c == 115 or c == 112 then -- s, p
return
return val
end
local tv = type(val)
if c == 113 then -- q
if tv ~= "string" or tv ~= "number" then
fmterr(idx, "string expected, got " .. tv, 1)
end
return
return val
end
if tv == "number" then return val end
if tv == "string" then
local v = tonumber(val)
if v then return v end
end
if tv == "number" then return end
if tv == "string" and tonumber(tv) then return end
fmterr(idx, "number expected, got " .. tv, 1)
end
@ -299,7 +302,7 @@ getmetatable("").__mod = function(fmts, params)
fmterr(idx, "no value")
end
local v = params[idx]
checktype(c, idx, v)
v = checktype(c, idx, v)
buf:append_str(("%" .. tostr(nbuf)):format(v))
nbuf:clear()
end