Lua Requires Chilkat v11.7.0+
Lua
Validate a QR Code Request
See more QR Code Examples
Demonstrates the validate operation, which examines a request without producing anything. The scope says how far to look: definition checks the options, capacity also checks that the data fits a QR symbol, and layout also checks the rendered size against the limits. The response has a validationStatus of valid or invalid, a list of checks, and findings[] describing what is wrong. A request that cannot be understood at all, such as one with a misspelled option, still makes the call fail in the usual way.Chilkat Lua Downloads
local chilkat = require("chilkat")
-- This example requires the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local fmt = chilkat.Formats.new()
local jsonOut = chilkat.JsonObject.new()
local json = chilkat.JsonObject.new()
json:update_string("target", "symbol")
json:update_string("validation.scope", "capacity")
json:update_string("payload.text", "https://www.chilkatsoft.com/barcode_overview.asp")
local success = fmt:qr_code("validate", json, jsonOut)
if not success then
print(fmt.last_error_text)
return
end
print("status: " .. jsonOut:string_of("validationStatus"))
local n = jsonOut:size_of_array("checks")
for i = 0, n - 1 do
jsonOut.i = i
print(" " .. jsonOut:string_of("checks[i].name") .. ": " .. jsonOut:string_of("checks[i].status"))
end
-- The same text does not fit version 2 at error-correction level H.
json:update_int("encoding.qr.maxVersion", 2)
json:update_string("encoding.qr.errorCorrection", "H")
success = fmt:qr_code("validate", json, jsonOut)
if not success then
print(fmt.last_error_text)
return
end
print("status: " .. jsonOut:string_of("validationStatus"))
n = jsonOut:size_of_array("checks")
for i = 0, n - 1 do
jsonOut.i = i
print(" " .. jsonOut:string_of("checks[i].name") .. ": " .. jsonOut:string_of("checks[i].status"))
end
n = jsonOut:size_of_array("findings")
for i = 0, n - 1 do
jsonOut.i = i
print("finding: " .. jsonOut:string_of("findings[i].code") .. " at " .. jsonOut:string_of("findings[i].path"))
print(" " .. jsonOut:string_of("findings[i].message"))
end
-- Sample output:
-- status: valid
-- definition: passed
-- capacity: passed
-- layout: notApplicable
-- status: invalid
-- definition: passed
-- capacity: failed
-- layout: notApplicable
-- finding: capacityExceeded at /payload
-- the payload does not fit any admitted QR version at the selected error-correction level