This commit is contained in:
Rafael Tavares Juliani committed 2025-09-04 15:47:05 -03:00
commit 9ceca45ccf
341 files changed
+73874

No files matched your search

+13
View File
@@ -0,0 +1,13 @@
name: Luacheck
on: [push, pull_request]
jobs:
luacheck:
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Luacheck
uses: lunarmodules/luacheck@v1
+26
View File
@@ -0,0 +1,26 @@
name: Test
on: [ push, pull_request ]
jobs:
test:
strategy:
fail-fast: false
matrix:
luaVersion: ['luajit', '5.1', '5.2', '5.3', '5.4.4']
runs-on: ubuntu-22.04
name: test lua ${{ matrix.luaVersion }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup ‘lua’
uses: leafo/gh-actions-lua@v9
with:
luaVersion: ${{ matrix.luaVersion }}
buildCache: true
- name: Test
run: |
lua qrtest.lua
+1
View File
@@ -0,0 +1 @@
docs
+3
View File
@@ -0,0 +1,3 @@
[submodule "ghpages"]
path = ghpages
url = [email protected]:speedata/luaqrcode.git
+15
View File
@@ -0,0 +1,15 @@
std = "max"
include_files = {
"**/*.lua",
"*.rockspec",
".luacheckrc"
}
exclude_files = {
".luarocks",
"locco/*"
}
globals = {
"testing",
"debugging"
}
max_line_length = false
+24
View File
@@ -0,0 +1,24 @@
Copyright (c) 2012-2020, Patrick Gundlach (SPEEDATA GMBH) and contributors, see https://github.com/speedata/luaqrcode. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of SPEEDATA nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL SPEEDATA BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+2
View File
@@ -0,0 +1,2 @@
doc:
lua locco/locco.lua qrencode.lua
+10
View File
@@ -0,0 +1,10 @@
See the homepage at http://speedata.github.io/luaqrcode/ for more information.
Special thanks to all contributors. Everything helps: bug reports, patches etc.
License: 3-clause BSD license<br>
Usability status: mature, used in production<br>
Maintenance status: maintained (bug fixes)<br>
Part of the [speedata Publisher](https://www.speedata.de/).
+26
View File
@@ -0,0 +1,26 @@
(Note from Patrick Gundlach: this is a slightly modified version of locco,
I like to use three dashes for locco documentation, two dashes for normal
Lua comments.)
______
___ / ________________________
__ / _ __ \ ___/ ___/ __ \
_ /___/ /_/ / /__ / /__ / /_/ /
/_____/\____/\___/ \___/ \____/
Locco is a Lua port of Docco: the original quick-and-dirty, hundred-line-
long, literate-programming-style documentation generator. For more information,
see the generated docs:
<http://rgieseke.github.com/locco/>
Other languages:
CoffeeScript - <http://jashkenas.github.com/docco/>
Python - <http://fitzgen.github.com/pycco/>
Ruby - <http://rtomayko.github.com/rocco/>
Sh - <http://rtomayko.github.com/shocco/>
+202
View File
@@ -0,0 +1,202 @@
/*--------------------- Layout and Typography ----------------------------*/
img {
max-width: 100%;
}
body {
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
font-size: 15px;
line-height: 22px;
color: #252519;
margin: 0; padding: 0;
}
a {
color: #261a3b;
}
a:visited {
color: #261a3b;
}
p {
margin: 0 0 15px 0;
}
h1, h2, h3, h4, h5, h6 {
margin: 0px 0 15px 0;
line-height: 110%;
}
h1 {
margin-top: 40px;
}
#container {
position: relative;
}
#background {
position: fixed;
top: 0; left: 525px; right: 0; bottom: 0;
background: #f5f5ff;
border-left: 1px solid #e5e5ee;
z-index: -1;
}
#jump_to, #jump_page {
background: white;
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
-webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
font: 10px Arial;
text-transform: uppercase;
cursor: pointer;
text-align: right;
}
#jump_to, #jump_wrapper {
position: fixed;
right: 0; top: 0;
padding: 5px 10px;
}
#jump_wrapper {
padding: 0;
display: none;
}
#jump_to:hover #jump_wrapper {
display: block;
}
#jump_page {
padding: 5px 0 3px;
margin: 0 0 25px 25px;
}
#jump_page .source {
display: block;
padding: 5px 10px;
text-decoration: none;
border-top: 1px solid #eee;
}
#jump_page .source:hover {
background: #f5f5ff;
}
#jump_page .source:first-child {
}
table td {
border: 0;
outline: 0;
}
td.docs > table {
padding-left: 3px;
padding-right: 3px;
}
table.body {
vertical-align: top;
text-align: left;
}
td.docs, th.docs {
max-width: 450px;
min-width: 450px;
min-height: 5px;
padding: 10px 25px 1px 50px;
overflow-x: hidden;
vertical-align: top;
text-align: left;
}
.docs pre {
margin: 15px 0 15px;
padding-left: 15px;
}
.docs p tt, .docs p code {
background: #f8f8ff;
border: 1px solid #dedede;
font-size: 12px;
padding: 0 0.2em;
}
.pilwrap {
position: relative;
}
.pilcrow {
font: 12px Arial;
text-decoration: none;
color: #454545;
position: absolute;
top: 3px; left: -20px;
padding: 1px 2px;
opacity: 0;
-webkit-transition: opacity 0.2s linear;
}
td.docs:hover .pilcrow {
opacity: 1;
}
td.code, th.code {
padding: 14px 15px 16px 25px;
width: 100%;
vertical-align: top;
background: #f5f5ff;
border-left: 1px solid #e5e5ee;
}
pre, tt, code {
font-size: 12px; line-height: 18px;
font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
margin: 0; padding: 0;
}
/*---------------------- Syntax Highlighting -----------------------------*/
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
body .hll { background-color: #ffffcc }
body .c { color: #408080; font-style: italic } /* Comment */
body .err { border: 1px solid #FF0000 } /* Error */
body .k { color: #954121 } /* Keyword */
body .o { color: #666666 } /* Operator */
body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
body .cp { color: #BC7A00 } /* Comment.Preproc */
body .c1 { color: #408080; font-style: italic } /* Comment.Single */
body .cs { color: #408080; font-style: italic } /* Comment.Special */
body .gd { color: #A00000 } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #FF0000 } /* Generic.Error */
body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
body .gi { color: #00A000 } /* Generic.Inserted */
body .go { color: #808080 } /* Generic.Output */
body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
body .gt { color: #0040D0 } /* Generic.Traceback */
body .kc { color: #954121 } /* Keyword.Constant */
body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
body .kp { color: #954121 } /* Keyword.Pseudo */
body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
body .kt { color: #B00040 } /* Keyword.Type */
body .m { color: #666666 } /* Literal.Number */
body .s { color: #219161 } /* Literal.String */
body .na { color: #7D9029 } /* Name.Attribute */
body .nb { color: #954121 } /* Name.Builtin */
body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
body .no { color: #880000 } /* Name.Constant */
body .nd { color: #AA22FF } /* Name.Decorator */
body .ni { color: #999999; font-weight: bold } /* Name.Entity */
body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
body .nf { color: #0000FF } /* Name.Function */
body .nl { color: #A0A000 } /* Name.Label */
body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
body .nt { color: #954121; font-weight: bold } /* Name.Tag */
body .nv { color: #19469D } /* Name.Variable */
body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mf { color: #666666 } /* Literal.Number.Float */
body .mh { color: #666666 } /* Literal.Number.Hex */
body .mi { color: #666666 } /* Literal.Number.Integer */
body .mo { color: #666666 } /* Literal.Number.Oct */
body .sb { color: #219161 } /* Literal.String.Backtick */
body .sc { color: #219161 } /* Literal.String.Char */
body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
body .s2 { color: #219161 } /* Literal.String.Double */
body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
body .sh { color: #219161 } /* Literal.String.Heredoc */
body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
body .sx { color: #954121 } /* Literal.String.Other */
body .sr { color: #BB6688 } /* Literal.String.Regex */
body .s1 { color: #219161 } /* Literal.String.Single */
body .ss { color: #19469D } /* Literal.String.Symbol */
body .bp { color: #954121 } /* Name.Builtin.Pseudo */
body .vc { color: #19469D } /* Name.Variable.Class */
body .vg { color: #19469D } /* Name.Variable.Global */
body .vi { color: #19469D } /* Name.Variable.Instance */
body .il { color: #666666 } /* Literal.Number.Integer.Long */
+266
View File
@@ -0,0 +1,266 @@
#!/usr/bin/env lua
-- __Locco__ is a Lua port of [Docco](http://jashkenas.github.com/docco/),
-- the quick-and-dirty, hundred-line-long, literate-programming-style
-- documentation generator. It produces HTML that displays your comments
-- alongside your code. Comments are passed through
-- [Markdown](http://daringfireball.net/projects/markdown/), and code is
-- syntax highlighted.
-- This page is the result of running Locco against its own source file:
-- locco.lua locco.lua
--
-- For its syntax highlighting Locco relies on the help of
-- [David Manura](http://lua-users.org/wiki/DavidManura)'s
-- [Lua Balanced](https://github.com/davidm/lua-balanced) to split
-- up the code. As a markdown engine it ships with
-- [Niklas Frykholm](http://www.frykholm.se/)'s
-- [markdown.lua](http://www.frykholm.se/files/markdown.lua) in the [Lua 5.2
-- compatible version](https://github.com/speedata/luamarkdown) from
-- [Patrick Gundlach](https://github.com/pgundlach). Otherwise there
-- are no external dependencies.
--
-- The generated HTML documentation for the given source files is saved
-- into a `docs` directory. If you have Locco on your path you can run it from
-- the command-line:
-- locco.lua project/*.lua
--
-- Locco is monolingual, but there are many projects written in
-- and with support for other languages, see the
-- [Docco](http://jashkenas.github.com/docco/) page for a list.<br>
-- The [source for Locco](https://github.com/rgieseke/locco) is available on
-- GitHub, and released under the MIT
-- license.
-- ### Setup & Helpers
-- Add script path to package path to find submodules.
local script_path = arg[0]:match('(.+)/.+')
package.path = table.concat({
script_path..'/?.lua',
package.path
}, ';')
-- Load markdown.lua.
local md = require 'markdown'
-- Load Lua Balanced.
local lb = require 'luabalanced'
-- Load HTML templates.
local template = require 'template'
-- Ensure the `docs` directory exists and return the _path_ of the source file.<br>
-- Parameter:<br>
-- _source_: The source file for which documentation is generated.<br>
local function ensure_directory(source)
local path = source:match('(.+)/.+$')
if not path then path = '.' end
os.execute('mkdir -p '..path..'/ghpages/docs')
return path
end
-- Insert HTML entities in a string.<br>
-- Parameter:<br>
-- _s_: String to escape.<br>
local function escape(s)
s = s:gsub('&', '&amp;')
s = s:gsub('<', '&lt;')
s = s:gsub('>', '&gt;')
s = s:gsub('%%', '&#37;')
return s
end
--local function replace_percent(s)
-- s = s:gsub('%%', '%%%%')
-- return s
--end
-- Define the Lua keywords, built-in functions and operators that should
-- be highlighted.
local keywords = { 'break', 'do', 'else', 'elseif', 'end', 'false', 'for',
'function', 'if', 'in', 'local', 'nil', 'repeat', 'return',
'then', 'true', 'until', 'while' }
local functions = { 'assert', 'collectgarbage', 'dofile', 'error', 'getfenv',
'getmetatable', 'ipairs', 'load', 'loadfile', 'loadstring',
'module', 'next', 'pairs', 'pcall', 'print', 'rawequal',
'rawget', 'rawset', 'require', 'setfenv', 'setmetatable',
'tonumber', 'tostring', 'type', 'unpack', 'xpcall' }
local operators = { 'and', 'not', 'or' }
-- Wrap an item from a list of Lua keywords in a span template or return the
-- unchanged item.<br>
-- Parameters:<br>
-- _item_: An item of a code snippet.<br>
-- _item\_list_: List of keywords or functions.<br>
-- _span\_class_: Style sheet class.<br>
local function wrap_in_span(item, item_list, span_class)
for i=1, #item_list do
if item_list[i] == item then
item = '<span class="'..span_class..'">'..item..'</span>'
break
end
end
return item
end
-- Quick and dirty source code highlighting. A chunk of code is split into
-- comments (at the end of a line), strings and code using the
-- [Lua Balanced](https://github.com/davidm/lua-balanced/blob/master/luabalanced.lua)
-- module. The code is then split again and matched against lists
-- of Lua keywords, functions or operators. All Lua items are wrapped into
-- a span having one of the classes defined in the Locco style sheet.<br>
-- Parameter:<br>
-- _code_: Chunk of code to highlight.<br>
local function highlight_lua(code)
local out = lb.gsub(code,
function(u, s)
local sout
if u == 'c' then -- Comments.
sout = '<span class="c">'..escape(s)..'</span>'
elseif u == 's' then -- Strings.
sout = '<span class="s">'..escape(s)..'</span>'
elseif u == 'e' then -- Code.
s = escape(s)
-- First highlight function names.
s = s:gsub('function ([%w_:%.]+)', 'function <span class="nf">%1</span>')
-- There might be a non-keyword at the beginning of the snippet.
sout = s:match('^(%A+)') or ''
-- Iterate through Lua items and try to wrap operators,
-- keywords and built-in functions in span elements.
-- If nothing was highlighted go to the next category.
for item, sep in s:gmatch('([%a_]+)(%A+)') do
local span, n = wrap_in_span(item, operators, 'o')
if span == item then
span, n = wrap_in_span(item, keywords, 'k')
end
if span == item then
span, n = wrap_in_span(item, functions, 'nt')
end
sout = sout..span..sep
end
end
return sout
end)
out = '<div class="highlight"><pre>'..out..'</pre></div>'
return out
end
-- ### Main Documentation Generation Functions
-- Given a string of source code, parse out each comment and the code that
-- follows it, and create an individual section for it. Sections take the form:
--
-- {
-- docs_text = ...,
-- docs_html = ...,
-- code_text = ...,
-- code_html = ...,
-- }
--
-- Parameter:<br>
-- _source_: The source file to process.<br>
local function parse(source)
local sections = {}
local has_code = false
local docs_text, code_text = '', ''
for line in io.lines(source) do
if line:match('^%s*%-%-%-') then
if has_code then
code_text = code_text:gsub('\n\n$', '\n') -- remove empty trailing line
sections[#sections + 1] = { ['docs_text'] = docs_text,
['code_text'] = code_text }
has_code = false
docs_text, code_text = '', ''
end
docs_text = docs_text..line:gsub('%s*(%-%-%-%s?)', '', 1)..'\n'
else
if not line:match('^#!') then -- ignore #!/usr/bin/lua
has_code = true
code_text = code_text..line..'\n'
end
end
end
sections[#sections + 1] = { ['docs_text'] = docs_text,
['code_text'] = code_text }
return sections
end
-- Loop through a table of split sections and convert the documentation
-- from Markdown to HTML and pass the code through Locco's syntax
-- highlighting. Add _docs\_html_ and _code\_html_ elements to the sections
-- table.<br>
-- Parameter:<br>
-- _sections_: A table with split sections.<br>
local function highlight(sections)
for i=1, #sections do
sections[i]['docs_html'] = md.markdown(sections[i]['docs_text'])
sections[i]['code_html'] = highlight_lua(sections[i]['code_text'])
end
return sections
end
-- After the highlighting is done, the template is filled with the documentation
-- and code snippets and an HTML file is written.<br>
-- Parameters:<br>
-- _source_: The source file.<br>
-- _path_: Path of the source file.<br>
-- _filename_: The filename of the source file.<br>
-- _sections_: A table with the original sections and rendered as HTML.<br>
-- _jump\_to_: A HTML chunk with links to other documentation files.
local function generate_html(source, path, filename, sections, jump_to)
local f, err = io.open(path..'/ghpages/docs/'..filename:gsub('lua$', 'html'), 'wb')
if err then print(err) end
local h = template.header:gsub('%%title%%', source)
h = h:gsub('%%jump%%', jump_to)
f:write(h)
for i=1, #sections do
local t = template.table_entry:gsub('%%index%%', i..'')
t = t:gsub('%%docs_html%%', sections[i]['docs_html'])
t = t:gsub('%%code_html%%', sections[i]['code_html'])
f:write(t)
end
f:write(template.footer)
f:close()
end
-- Generate the documentation for a source file by reading it in,
-- splitting it up into comment/code sections, highlighting and merging
-- them into an HTML template.<br>
-- Parameters:<br>
-- _source_: The source file to process.<br>
-- _path_: Path of the source file.<br>
-- _filename_: The filename of the source file.<br>
-- _jump\_to_: A HTML chunk with links to other documentation files.
local function generate_documentation(source, path, filename, jump_to)
local sections = parse(source)
local sections = highlight(sections)
generate_html(source, path, filename, sections, jump_to)
end
-- Run the script.
-- Generate HTML links to other files in the documentation.
local jump_to = ''
if #arg > 1 then
jump_to = template.jump_start
for i=1, #arg do
local link = arg[i]:gsub('lua$', 'html')
link = link:match('.+/(.+)$') or link
local t = template.jump:gsub('%%jump_html%%', link)
t = t:gsub('%%jump_lua%%', arg[i])
jump_to = jump_to..t
end
jump_to = jump_to..template.jump_end
end
-- Make sure the output directory exists, generate the HTML files for each
-- source file, print what's happening and write the style sheet.
local path = ensure_directory(arg[1])
for i=1, #arg do
local filename = arg[i]:match('.+/(.+)$') or arg[i]
generate_documentation(arg[i], path, filename, jump_to)
print(arg[i]..' --> '..path..'/ghpages/docs/'..filename:gsub('lua$', 'html'))
end
local f, err = io.open(path..'/'..'ghpages/docs/locco.css', 'wb')
if err then print(err) end
f:write(template.css)
f:close()
@@ -0,0 +1,367 @@
--[==[
LUA MODULE
luabalanced v$(_VERSION) - Functions for matching delimited snippets of Lua code in a string
SYNOPSIS
local LB = require "luabalanced"
-- Extract Lua expression starting at position 4.
print(LB.match_expression("if x^2 + x > 5 then print(x) end", 4))
--> x^2 + x > 5 16
-- Extract Lua string starting at (default) position 1.
print(LB.match_string([["test\"123" .. "more"]]))
--> "test\"123" 12
-- Break Lua code into code types.
LB.gsub([[
local x = 1 -- test
print("x=", x)
]], function(u, s)
print(u .. '[' .. s .. ']')
end)
--[[output:
e[ local x = 1 ]
c[-- test
]
e[ print(]
s["x="]
e[, x)
]
]]
DESCRIPTION
This module can, for example, match a Lua string, Lua comment, or Lua
expression. It is useful in particular for source filters or parsing
Lua snippets embedded in another language. It is inspired by Damian Conway's
Text::Balanced [1] in Perl. The unique feature of this implementation
is that that it does not rigorously lex and parse the Lua grammar.
It doesn't need to. It assumes during the parse that the Lua code is
syntactically correct (which can be verified later using loadstring).
By assuming this, extraction of delimited sequences is significantly
simplified yet can still be robust, and it also supports supersets
of the Lua grammar. The code, which is written entirely in Lua,
is just under 200 lines of Lua code (compare to Yueliang used in
MetaLua, where the lexer alone is a few hundred lines).
API
LB.match_string(s, pos) --> string, posnew
Match Lua string in string <s> starting at position `pos`.
Returns `string`, `posnew`, where `string` is the matched
string (or nil on no match) and `posnew` is the character
following the match (or `pos` on no match).
Supports all Lua string syntax: "...", '...', [[...]], [=[...]=], etc.
LB.match_bracketed(s, pos) --> string, posnew
Match bracketed Lua expression, e.g. "(...)", "{...}", "[...]", "[[...]]",
[=[...]=], etc.
Function interface is similar to `match_string`.
LB.match_comment(s, pos) --> string, posnew
Match Lua comment, e.g. "--...\n", "--[[...]]", "--[=[...]=]", etc.
Function interface is similar to `match_string`.
LB.match_expression(s, pos) --> string, posnew
Match Lua expression, e.g. "a + b * c[e]".
Function interface is similar to match_string.
LB.match_namelist(s, pos) --> array, posnew
Match name list (zero or more names). E.g. "a,b,c"
Function interface is similar to match_string,
but returns array as match.
M.match_explist(s, pos) --> array, posnew
Match expression list (zero or more expressions). E.g. "a+b,b*c".
Function interface is similar to match_string,
but returns array as match.
M.gsub(s, f)
Replace snippets of code in Lua code string `s`
using replacement function `f(u,sin) --> sout`.
`u` is the type of snippet ('c' = comment, 's' = string,
'e' = any other code).
Snippet is replaced with `sout` (unless `sout` is `nil` or `false`, in
which case the original snippet is kept)
This is somewhat analogous to `string.gsub`.
DEPENDENCIES
None (other than Lua 5.1 or 5.2).
HOME PAGE
http://lua-users.org/wiki/LuaBalanced
https://github.com/davidm/lua-balanced
DOWNLOAD/INSTALL
If using LuaRocks:
luarocks install lua-balanced
Otherwise, download <https://github.com/davidm/lua-balanced/zipball/master>
and unzip. Alternately, if using git:
git clone git://github.com/davidm/lua-balanced.git
cd lua-balanced
Optionally unpack:
./util.mk
or unpack and install in LuaRocks:
./util.mk install
REFERENCES
[1] http://lua-users.org/wiki/LuaBalanced
[2] http://search.cpan.org/dist/Text-Balanced/lib/Text/Balanced.pm
LICENSE
(c) 2008-2011 David Manura. Licensed under the same terms as Lua (MIT).
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
(end license)
--]==]---------------------------------------------------------------------
local M = {_TYPE='module', _NAME='luabalanaced', _VERSION='0.1.1.20120323'}
local assert = assert
-- map opening brace <-> closing brace.
local ends = { ['('] = ')', ['{'] = '}', ['['] = ']' }
local begins = {}; for k,v in pairs(ends) do begins[v] = k end
local function match_string(s, pos)
pos = pos or 1
local posa = pos
local c = s:sub(pos,pos)
if c == '"' or c == "'" then
pos = pos + 1
while 1 do
pos = assert(s:find("[" .. c .. "\\]", pos), 'syntax error')
if s:sub(pos,pos) == c then
local part = s:sub(posa, pos)
return part, pos + 1
else
pos = pos + 2
end
end
else
local sc = s:match("^%[(=*)%[", pos)
if sc then
local _; _, pos = s:find("%]" .. sc .. "%]", pos)
assert(pos)
local part = s:sub(posa, pos)
return part, pos + 1
else
return nil, pos
end
end
end
M.match_string = match_string
local function match_bracketed(s, pos)
pos = pos or 1
local posa = pos
local ca = s:sub(pos,pos)
if not ends[ca] then
return nil, pos
end
local stack = {}
while 1 do
pos = s:find('[%(%{%[%)%}%]\"\']', pos)
assert(pos, 'syntax error: unbalanced')
local c = s:sub(pos,pos)
if c == '"' or c == "'" then
local part; part, pos = match_string(s, pos)
assert(part)
elseif ends[c] then -- open
local mid, posb
if c == '[' then mid, posb = s:match('^%[(=*)%[()', pos) end
if mid then
pos = s:match('%]' .. mid .. '%]()', posb)
assert(pos, 'syntax error: long string not terminated')
if #stack == 0 then
local part = s:sub(posa, pos-1)
return part, pos
end
else
stack[#stack+1] = c
pos = pos + 1
end
else -- close
assert(stack[#stack] == assert(begins[c]), 'syntax error: unbalanced')
stack[#stack] = nil
if #stack == 0 then
local part = s:sub(posa, pos)
return part, pos+1
end
pos = pos + 1
end
end
end
M.match_bracketed = match_bracketed
local function match_comment(s, pos)
pos = pos or 1
if s:sub(pos, pos+1) ~= '--' then
return nil, pos
end
pos = pos + 2
local partt, post = match_string(s, pos)
if partt then
return '--' .. partt, post
end
local part; part, pos = s:match('^([^\n]*\n?)()', pos)
return '--' .. part, pos
end
local wordop = {['and']=true, ['or']=true, ['not']=true}
local is_compare = {['>']=true, ['<']=true, ['~']=true}
local function match_expression(s, pos)
pos = pos or 1
local posa = pos
local lastident
local poscs, posce
while pos do
local c = s:sub(pos,pos)
if c == '"' or c == "'" or c == '[' and s:find('^[=%[]', pos+1) then
local part; part, pos = match_string(s, pos)
assert(part, 'syntax error')
elseif c == '-' and s:sub(pos+1,pos+1) == '-' then
-- note: handle adjacent comments in loop to properly support
-- backtracing (poscs/posce).
poscs = pos
while s:sub(pos,pos+1) == '--' do
local part; part, pos = match_comment(s, pos)
assert(part)
pos = s:match('^%s*()', pos)
posce = pos
end
elseif c == '(' or c == '{' or c == '[' then
local part; part, pos = match_bracketed(s, pos)
elseif c == '=' and s:sub(pos+1,pos+1) == '=' then
pos = pos + 2 -- skip over two-char op containing '='
elseif c == '=' and is_compare[s:sub(pos-1,pos-1)] then
pos = pos + 1 -- skip over two-char op containing '='
elseif c:match'^[%)%}%];,=]' then
local part = s:sub(posa, pos-1)
return part, pos
elseif c:match'^[%w_]' then
local newident,newpos = s:match('^([%w_]+)()', pos)
if pos ~= posa and not wordop[newident] then -- non-first ident
local pose = ((posce == pos) and poscs or pos) - 1
while s:match('^%s', pose) do pose = pose - 1 end
local ce = s:sub(pose,pose)
if ce:match'[%)%}\'\"%]]' or
ce:match'[%w_]' and not wordop[lastident]
then
local part = s:sub(posa, pos-1)
return part, pos
end
end
lastident, pos = newident, newpos
else
pos = pos + 1
end
pos = s:find('[%(%{%[%)%}%]\"\';,=%w_%-]', pos)
end
local part = s:sub(posa, #s)
return part, #s+1
end
M.match_expression = match_expression
local function match_namelist(s, pos)
pos = pos or 1
local list = {}
while 1 do
local c = #list == 0 and '^' or '^%s*,%s*'
local item, post = s:match(c .. '([%a_][%w_]*)%s*()', pos)
if item then pos = post else break end
list[#list+1] = item
end
return list, pos
end
M.match_namelist = match_namelist
local function match_explist(s, pos)
pos = pos or 1
local list = {}
while 1 do
if #list ~= 0 then
local post = s:match('^%s*,%s*()', pos)
if post then pos = post else break end
end
local item; item, pos = match_expression(s, pos)
assert(item, 'syntax error')
list[#list+1] = item
end
return list, pos
end
M.match_explist = match_explist
local function gsub(s, f)
local pos = 1
local posa = 1
local ts = {}
while 1 do
pos = s:find('[%-\'\"%[]', pos)
if not pos then break end
if s:match('^%-%-', pos) then
local exp = s:sub(posa, pos-1)
if #exp > 0 then ts[#ts+1] = (f('e', exp) or exp) end
local comment; comment, pos = match_comment(s, pos)
ts[#ts+1] = (f('c', assert(comment)) or comment)
posa = pos
else
local posb = s:find('^[\'\"%[]', pos)
local str
if posb then str, pos = match_string(s, posb) end
if str then
local exp = s:sub(posa, posb-1)
if #exp > 0 then ts[#ts+1] = (f('e', exp) or exp) end
ts[#ts+1] = (f('s', str) or str)
posa = pos
else
pos = pos + 1
end
end
end
local exp = s:sub(posa)
if #exp > 0 then ts[#ts+1] = (f('e', exp) or exp) end
return table.concat(ts)
end
M.gsub = gsub
return M
File diff suppressed because it is too large. Load diff
+255
View File
@@ -0,0 +1,255 @@
local M = {}
M.header = [[<!DOCTYPE html>
<html>
<head>
<title>%title%</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<link rel="stylesheet" media="all" href="locco.css" />
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML"></script>
</head>
<body>
<div id="container">
<div id="background"></div>
%jump%
<table cellpadding="0" cellspacing="0">
<thead>
<tr>
<th class="docs">
<h1>
%title%
</h1>
</th>
<th class="code">
</th>
</tr>
</thead>
<tbody>
]]
M.jump_start = [[
<div id="jump_to">
Jump To &hellip;
<div id="jump_wrapper">
<div id="jump_page">
]]
M.jump = [[
<a class="source" href="%jump_html%">%jump_lua%</a>
]]
M.jump_end = [[
</div>
</div>
</div>
]]
M.table_entry = [[
<tr id="section-%index%">
<td class="docs">
<div class="pilwrap">
<a class="pilcrow" href="#section-%index%">&#182;</a>
</div>
%docs_html%
</td>
<td class="code">
%code_html%
</td>
</tr>]]
M.footer = [[</tbody>
</table>
</div>
</body>
</html>]]
M.css = [[/*--------------------- Layout and Typography ----------------------------*/
body {
font-family: 'Palatino Linotype', 'Book Antiqua', Palatino, FreeSerif, serif;
font-size: 15px;
line-height: 22px;
color: #252519;
margin: 0; padding: 0;
}
a {
color: #261a3b;
}
a:visited {
color: #261a3b;
}
p {
margin: 0 0 15px 0;
}
h1, h2, h3, h4, h5, h6 {
margin: 0px 0 15px 0;
}
h1 {
margin-top: 40px;
}
#container {
position: relative;
}
#background {
position: fixed;
top: 0; left: 525px; right: 0; bottom: 0;
background: #f5f5ff;
border-left: 1px solid #e5e5ee;
z-index: -1;
}
#jump_to, #jump_page {
background: white;
-webkit-box-shadow: 0 0 25px #777; -moz-box-shadow: 0 0 25px #777;
-webkit-border-bottom-left-radius: 5px; -moz-border-radius-bottomleft: 5px;
font: 10px Arial;
text-transform: uppercase;
cursor: pointer;
text-align: right;
}
#jump_to, #jump_wrapper {
position: fixed;
right: 0; top: 0;
padding: 5px 10px;
}
#jump_wrapper {
padding: 0;
display: none;
}
#jump_to:hover #jump_wrapper {
display: block;
}
#jump_page {
padding: 5px 0 3px;
margin: 0 0 25px 25px;
}
#jump_page .source {
display: block;
padding: 5px 10px;
text-decoration: none;
border-top: 1px solid #eee;
}
#jump_page .source:hover {
background: #f5f5ff;
}
#jump_page .source:first-child {
}
table td {
border: 0;
outline: 0;
}
td.docs, th.docs {
max-width: 450px;
min-width: 450px;
min-height: 5px;
padding: 10px 25px 1px 50px;
overflow-x: hidden;
vertical-align: top;
text-align: left;
}
.docs pre {
margin: 15px 0 15px;
padding-left: 15px;
}
.docs p tt, .docs p code {
background: #f8f8ff;
border: 1px solid #dedede;
font-size: 12px;
padding: 0 0.2em;
}
.pilwrap {
position: relative;
}
.pilcrow {
font: 12px Arial;
text-decoration: none;
color: #454545;
position: absolute;
top: 3px; left: -20px;
padding: 1px 2px;
opacity: 0;
-webkit-transition: opacity 0.2s linear;
}
td.docs:hover .pilcrow {
opacity: 1;
}
td.code, th.code {
padding: 14px 15px 16px 25px;
width: 100%;
vertical-align: top;
background: #f5f5ff;
border-left: 1px solid #e5e5ee;
}
pre, tt, code {
font-size: 12px; line-height: 18px;
font-family: Menlo, Monaco, Consolas, "Lucida Console", monospace;
margin: 0; padding: 0;
}
/*---------------------- Syntax Highlighting -----------------------------*/
td.linenos { background-color: #f0f0f0; padding-right: 10px; }
span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }
body .hll { background-color: #ffffcc }
body .c { color: #408080; font-style: italic } /* Comment */
body .err { border: 1px solid #FF0000 } /* Error */
body .k { color: #954121 } /* Keyword */
body .o { color: #666666 } /* Operator */
body .cm { color: #408080; font-style: italic } /* Comment.Multiline */
body .cp { color: #BC7A00 } /* Comment.Preproc */
body .c1 { color: #408080; font-style: italic } /* Comment.Single */
body .cs { color: #408080; font-style: italic } /* Comment.Special */
body .gd { color: #A00000 } /* Generic.Deleted */
body .ge { font-style: italic } /* Generic.Emph */
body .gr { color: #FF0000 } /* Generic.Error */
body .gh { color: #000080; font-weight: bold } /* Generic.Heading */
body .gi { color: #00A000 } /* Generic.Inserted */
body .go { color: #808080 } /* Generic.Output */
body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */
body .gs { font-weight: bold } /* Generic.Strong */
body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
body .gt { color: #0040D0 } /* Generic.Traceback */
body .kc { color: #954121 } /* Keyword.Constant */
body .kd { color: #954121; font-weight: bold } /* Keyword.Declaration */
body .kn { color: #954121; font-weight: bold } /* Keyword.Namespace */
body .kp { color: #954121 } /* Keyword.Pseudo */
body .kr { color: #954121; font-weight: bold } /* Keyword.Reserved */
body .kt { color: #B00040 } /* Keyword.Type */
body .m { color: #666666 } /* Literal.Number */
body .s { color: #219161 } /* Literal.String */
body .na { color: #7D9029 } /* Name.Attribute */
body .nb { color: #954121 } /* Name.Builtin */
body .nc { color: #0000FF; font-weight: bold } /* Name.Class */
body .no { color: #880000 } /* Name.Constant */
body .nd { color: #AA22FF } /* Name.Decorator */
body .ni { color: #999999; font-weight: bold } /* Name.Entity */
body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */
body .nf { color: #0000FF } /* Name.Function */
body .nl { color: #A0A000 } /* Name.Label */
body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */
body .nt { color: #954121; font-weight: bold } /* Name.Tag */
body .nv { color: #19469D } /* Name.Variable */
body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */
body .w { color: #bbbbbb } /* Text.Whitespace */
body .mf { color: #666666 } /* Literal.Number.Float */
body .mh { color: #666666 } /* Literal.Number.Hex */
body .mi { color: #666666 } /* Literal.Number.Integer */
body .mo { color: #666666 } /* Literal.Number.Oct */
body .sb { color: #219161 } /* Literal.String.Backtick */
body .sc { color: #219161 } /* Literal.String.Char */
body .sd { color: #219161; font-style: italic } /* Literal.String.Doc */
body .s2 { color: #219161 } /* Literal.String.Double */
body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */
body .sh { color: #219161 } /* Literal.String.Heredoc */
body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */
body .sx { color: #954121 } /* Literal.String.Other */
body .sr { color: #BB6688 } /* Literal.String.Regex */
body .s1 { color: #219161 } /* Literal.String.Single */
body .ss { color: #19469D } /* Literal.String.Symbol */
body .bp { color: #954121 } /* Name.Builtin.Pseudo */
body .vc { color: #19469D } /* Name.Variable.Class */
body .vg { color: #19469D } /* Name.Variable.Global */
body .vi { color: #19469D } /* Name.Variable.Instance */
body .il { color: #666666 } /* Literal.Number.Integer.Long */
]]
return M
+109
View File
@@ -0,0 +1,109 @@
#!/usr/bin/env lua
local qrencode = dofile("qrencode.lua")
-- padding: number of padding rows/columns around QR code
local function matrix_to_string( tab, padding,padding_char,white_pixel,black_pixel )
local padding_string
local str_tab = {} -- hold each row of the qr code in a cell
-- Add (padding) blank columns at the left of the matrix
-- (left of each row string), inserting an extra (padding)
-- rows at the top and bottom
padding_string = string.rep(padding_char,padding)
for i=1,#tab + 2*padding do
str_tab[i] = padding_string
end
for x=1,#tab do
for y=1,#tab do
if tab[x][y] > 0 then
-- using y + padding because we added (padding) blank columns at the left for each string in str_tab array
str_tab[y + padding] = str_tab[y + padding] .. black_pixel
elseif tab[x][y] < 0 then
str_tab[y + padding] = str_tab[y + padding] .. white_pixel
else
str_tab[y + padding] = str_tab[y + padding] .. " X"
end
end
end
padding_string = string.rep(padding_char,#tab)
for i=1,padding do
-- fills in padding rows at top of matrix
str_tab[i] = str_tab[i] .. padding_string
-- fills in padding rows at bottom of matrix
str_tab[#tab + padding + i] = str_tab[#tab + padding + i] .. padding_string
end
-- Add (padding) blank columns to right of matrix (to the end of each row string)
padding_string = string.rep(padding_char,padding)
for i=1,#tab + 2*padding do
str_tab[i] = str_tab[i] .. padding_string
end
return str_tab
end
local use_ansi = false
local padding = 1
local padding_char
local black_pixel = "X"
local white_pixel = " "
local codeword
while true do
if arg[1] == nil then
break
elseif arg[1] == "-h" or arg[1] == "--help" then
codeword = nil
break
elseif arg[1] == "-a" then
use_ansi = true
elseif arg[1] == "-p" then
padding = arg[2]
table.remove(arg,2)
elseif arg[1] == "-c" then
padding_char = arg[2]
table.remove(arg,2)
elseif arg[1] == "-b" then
black_pixel = arg[2]
table.remove(arg,2)
elseif arg[1] == "-w" then
white_pixel = arg[2]
table.remove(arg,2)
else
codeword = arg[1]
end
table.remove(arg,1)
end
if use_ansi then
black_pixel = "\27[40m \27[0m"
white_pixel = "\27[1;47m \27[0m"
end
padding_char = padding_char or white_pixel
if codeword then
local ok, tab_or_message = qrencode.qrcode(codeword)
if not ok then
print(tab_or_message)
else
local rows
rows = matrix_to_string(tab_or_message,padding,padding_char,white_pixel,black_pixel)
for i=1,#rows do -- prints each "row" of the QR code on a line, one at a time
print(rows[i])
end
end
else
print("Usage:")
print(arg[0] .. " [-a] [-p <num>] [-c <char>] [-b <char>] [-w <char>] <contents>")
print("-a : use ansi colors (don't do this on a dos box)")
print("-p <num> : use padding of width <num> (default: 1)")
print("-b <char>: use <char> for black pixel (default: 'X')")
print("-w <char>: use <char> for white pixel (default: ' ')")
print("-c <char>: use <char> for padding (default: the white pixel)")
end
File diff suppressed because it is too large. Load diff
+123
View File
@@ -0,0 +1,123 @@
#!/usr/bin/env lua
local function err( ... )
print(string.format(...))
end
local failed = false
local function assert_equal( a,b,func )
if a ~= b then
err("Assertion failed: %s: %q is not equal to %q",func,tostring(a),tostring(b))
failed = true
end
end
testing=true
local qrcode = dofile("qrencode.lua")
local tab
local str = "HELLO WORLD"
assert_equal(qrcode.get_mode("0101"), 1,"get_encoding_byte 1")
assert_equal(qrcode.get_mode(str), 2,"get_encoding_byte 2")
assert_equal(qrcode.get_mode("0-9A-Z $%*./:+-"),2,"get_encoding_byte 3")
assert_equal(qrcode.get_mode("foär"), 4,"get_encoding_byte 4")
assert_equal(qrcode.get_length(str,1,2),"000001011","get_length")
assert_equal(qrcode.binary(5,10),"0000000101","binary()")
assert_equal(qrcode.binary(779,11),"01100001011","binary()")
assert_equal(qrcode.add_pad_data(1,3,"0010101"),"00101010000000001110110000010001111011000001000111101100000100011110110000010001111011000001000111101100","pad_data")
tab = qrcode.get_generator_polynominal_adjusted(13,25)
assert_equal(tab[1],0,"get_generator_polynominal_adjusted 0")
assert_equal(tab[24],74,"get_generator_polynominal_adjusted 24")
assert_equal(tab[25],0,"get_generator_polynominal_adjusted 25")
tab = qrcode.get_generator_polynominal_adjusted(13,24)
assert_equal(tab[1],0,"get_generator_polynominal_adjusted 0")
assert_equal(tab[23],74,"get_generator_polynominal_adjusted 23")
assert_equal(tab[24],0,"get_generator_polynominal_adjusted 24")
tab = qrcode.convert_bitstring_to_bytes("00100000010110110000101101111000110100010111001011011100010011010100001101000000111011000001000111101100")
assert_equal(tab[1],32,"convert_bitstring_to_bytes")
assert_equal(qrcode.bit_xor(141,43), 166,"bit_xor")
assert_equal(qrcode.bit_xor(179,0), 179,"bit_xor")
-- local hello_world_msg_with_ec = "0010000001011011000010110111100011010001011100101101110001001101010000110100000011101100000100011110110010101000010010000001011001010010110110010011011010011100000000000010111000001111101101000111101000010000"
assert_equal(qrcode.get_pixel_with_mask(0,21,21,1),-1,"get_pixel_with_mask 1")
assert_equal(qrcode.get_pixel_with_mask(0,1,1,1),-1,"get_pixel_with_mask 2")
local a,b,c,d,e = qrcode.get_version_eclevel_mode_bistringlength(str)
assert_equal(a,1,"get_version_eclevel_mode_bistringlength 1")
assert_equal(b,3,"get_version_eclevel_mode_bistringlength 2")
assert_equal(c,"0010","get_version_eclevel_mode_bistringlength 3")
assert_equal(d,2,"get_version_eclevel_mode_bistringlength 4")
assert_equal(e,"000001011","get_version_eclevel_mode_bistringlength 5")
assert_equal(qrcode.encode_string_numeric("01234567"),"000000110001010110011000011","encode string numeric")
assert_equal(qrcode.encode_string_ascii(str),"0110000101101111000110100010111001011011100010011010100001101","encode string ascii")
assert_equal(qrcode.remainder[40],0,"get_remainder")
assert_equal(qrcode.remainder[2],7,"get_remainder")
-------------------
-- Error correction
-------------------
local data = {32, 234, 187, 136, 103, 116, 252, 228, 127, 141, 73, 236, 12, 206, 138, 7, 230, 101, 30, 91, 152, 80, 0, 236, 17, 236, 17, 236}
local ec_expected = {73, 31, 138, 44, 37, 176, 170, 36, 254, 246, 191, 187, 13, 137, 84, 63}
local ec = qrcode.calculate_error_correction(data,16)
for i=1,#ec_expected do
assert_equal(ec_expected[i],ec[i],string.format("calculate_error_correction %d",i))
end
data = {32, 234, 187, 136, 103, 116, 252, 228, 127, 141, 73, 236, 12, 206, 138, 7, 230, 101, 30, 91, 152, 80, 0, 236, 17, 236, 17, 236, 17, 236, 17, 236, 17, 236}
ec_expected = {66, 146, 126, 122, 79, 146, 2, 105, 180, 35}
ec = qrcode.calculate_error_correction(data,10)
for i=1,#ec_expected do
assert_equal(ec_expected[i],ec[i],string.format("calculate_error_correction %d",i))
end
data = {32, 83, 7, 120, 209, 114, 215, 60, 224}
ec_expected = {123, 120, 222, 125, 116, 92, 144, 245, 58, 73, 104, 30, 108, 0, 30, 166, 152}
ec = qrcode.calculate_error_correction(data,17)
for i=1,#ec_expected do
assert_equal(ec_expected[i],ec[i],string.format("calculate_error_correction %d",i))
end
data = {32,83,7,120,209,114,215,60,224,236,17}
ec_expected = {3, 67, 244, 57, 183, 14, 171, 101, 213, 52, 148, 3, 144, 148, 6, 155, 3, 252, 228, 100, 11, 56}
ec = qrcode.calculate_error_correction(data,22)
for i=1,#ec_expected do
assert_equal(ec_expected[i],ec[i],string.format("calculate_error_correction %d",i))
end
data = {236,17,236,17,236, 17,236, 17,236, 17,236}
ec_expected = {171, 165, 230, 109, 241, 45, 198, 125, 213, 84, 88, 187, 89, 61, 220, 255, 150, 75, 113, 77, 147, 164}
ec = qrcode.calculate_error_correction(data,22)
for i=1,#ec_expected do
assert_equal(ec_expected[i],ec[i],string.format("calculate_error_correction %d",i))
end
data = {17,236, 17,236, 17,236,17,236, 17,236, 17,236}
ec_expected = {23, 115, 68, 245, 125, 66, 203, 235, 85, 88, 174, 178, 229, 181, 118, 148, 44, 175, 213, 243, 27, 215}
ec = qrcode.calculate_error_correction(data,22)
for i=1,#ec_expected do
assert_equal(ec_expected[i],ec[i],string.format("calculate_error_correction %d",i))
end
data = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
ec_expected = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
ec = qrcode.calculate_error_correction(data,10)
for i=1,#ec_expected do
assert_equal(ec_expected[i],ec[i],string.format("calculate_error_correction %d",i))
end
-- "HALLO WELT" in alphanumeric, code 5-H
data = { 32,83,7,120,209,114,215,60,224,236,17,236,17,236,17,236, 17,236, 17,236, 17,236, 17, 236, 17,236, 17,236, 17,236, 17,236, 17,236, 17, 236, 17,236, 17,236, 17,236, 17,236, 17,236}
local message_expected = {32, 236, 17, 17, 83, 17, 236, 236, 7, 236, 17, 17, 120, 17, 236, 236, 209, 236, 17, 17, 114, 17, 236, 236, 215, 236, 17, 17, 60, 17, 236, 236, 224, 236, 17, 17, 236, 17, 236, 236, 17, 236, 17, 17, 236, 236, 3, 171, 23, 23, 67, 165, 115, 115, 244, 230, 68, 68, 57, 109, 245, 245, 183, 241, 125, 125, 14, 45, 66, 66, 171, 198, 203, 203, 101, 125, 235, 235, 213, 213, 85, 85, 52, 84, 88, 88, 148, 88, 174, 174, 3, 187, 178, 178, 144, 89, 229, 229, 148, 61, 181, 181, 6, 220, 118, 118, 155, 255, 148, 148, 3, 150, 44, 44, 252, 75, 175, 175, 228, 113, 213, 213, 100, 77, 243, 243, 11, 147, 27, 27, 56, 164, 215, 215}
local tmp = qrcode.arrange_codewords_and_calculate_ec(5,4,data)
local message = qrcode.convert_bitstring_to_bytes(tmp)
for i=1,#message do
assert_equal(message_expected[i],message[i],string.format("arrange_codewords_and_calculate_ec %d",i))
end
print("Tests end here")
if failed then
print("Some tests failed, see above")
else
print("Everything looks fine")
end
os.exit(failed and 1 or 0)