Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ jobs:
luaVersion: ${{ matrix.luaVersion }}
- name: Test
run: |
lua qrtest.lua
lua tests/run_all.lua
78 changes: 77 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,77 @@
docs
# Generated documentation
docs/

# Image files (test outputs and examples)
*.png
*.jpg
*.jpeg
*.ppm
*.gif
*.bmp

# Test artifacts
test_*.png
test_*.ppm
test_*.jpg
qr_*.png
qr_*.ppm
*_test.*

# Temporary files
*.tmp
*.temp
temp_*
*.tmp.*

# Data files (often test data)
*.csv
*.txt
*.log

# Python artifacts (if any remain)
__pycache__/
*.py[cod]
*$py.class
*.so
.Python
env/
venv/
.venv
pip-log.txt
pip-delete-this-directory.txt

# Editor artifacts
.DS_Store
.vscode/
.idea/
*.swp
*.swo
*~

# OS artifacts
Thumbs.db
ehthumbs.db
Desktop.ini

# Lua artifacts
*.o
*.a
*.so
*.luac
luac.out

# AI tools and configuration files
CLAUDE.md
CLAUDE.local.md
.claude/
.cursor/
.cursorrules
.github/copilot-instructions.md
.aider*
.codeium/
.gemini/
.anthropic/
claude-*
anthropic-*
openai-*
*.aider.log
Empty file removed .gitmodules
Empty file.
3 changes: 1 addition & 2 deletions .luacheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ include_files = {
".luacheckrc"
}
exclude_files = {
".luarocks",
"locco/*"
".luarocks"
}
globals = {
"testing",
Expand Down
53 changes: 52 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1 +1,52 @@
# Documentation generation removed - will be replaced with custom docs
# Lua Performance and Build Targets

.PHONY: test bytecode benchmark clean

# Standard test run
test:
lua tests/run_all.lua

# Compile Lua source to bytecode for faster loading
bytecode:
@echo "Compiling to bytecode..."
luac -o qrencode.luac qrencode.lua
luac -o qrimage.luac qrimage.lua
luac -o qrcode.luac qrcode.lua
@echo "Bytecode files created: *.luac"

# Test with LuaJIT (if available)
test-jit:
@command -v luajit >/dev/null 2>&1 || { echo "LuaJIT not found, install with: sudo apt install luajit"; exit 1; }
luajit tests/run_all.lua

# Performance benchmarks
benchmark:
@echo "=== Performance Benchmark ==="
@echo "Testing with standard Lua:"
@time lua tests/run_all.lua >/dev/null
@echo
@if command -v luajit >/dev/null 2>&1; then \
echo "Testing with LuaJIT:"; \
time luajit tests/run_all.lua >/dev/null; \
else \
echo "LuaJIT not available for comparison"; \
fi

# QR generation speed test
speed-test:
@echo "=== QR Generation Speed Test ==="
@echo "Generating 100 QR codes with standard Lua:"
@time lua -e 'qr=dofile("qrimage.lua"); for i=1,100 do qr.save_qr_image("TEST"..i, "/tmp/qr"..i..".ppm") end' 2>/dev/null
@echo
@if command -v luajit >/dev/null 2>&1; then \
echo "Generating 100 QR codes with LuaJIT:"; \
time luajit -e 'qr=dofile("qrimage.lua"); for i=1,100 do qr.save_qr_image("TEST"..i, "/tmp/qr"..i..".ppm") end' 2>/dev/null; \
else \
echo "LuaJIT not available for comparison"; \
fi
@rm -f /tmp/qr*.ppm

# Clean up compiled files
clean:
rm -f *.luac
rm -f /tmp/qr*.ppm
125 changes: 100 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,23 @@ lua qrimage.lua "Test" output.ppm 12 2

# Arguments: <text> [filename] [module_size] [border]
```
### Supported Output Formats

### Lua Library Usage
- **PPM** - Generated natively by Lua (no dependencies)
- **PNG** - Converted from PPM using system tools
- **JPEG** - Converted from PPM using system tools

The library automatically detects available conversion tools (ImageMagick, netpbm, ffmpeg) and uses the first one found.

## Error Correction Levels
All standard QR code error correction levels are supported:
- **L** (Low) - ~7% error correction
- **M** (Medium) - ~15% error correction
- **Q** (Quartile) - ~25% error correction
- **H** (High) - ~30% error correction


## Library Usage
```lua
-- Load the image generation module
local qrimage = dofile("qrimage.lua")
Expand All @@ -54,7 +69,7 @@ else
end
```

### Core Library Only
### Base library only
```lua
-- Use just the QR generation without image output
local qrencode = dofile("qrencode.lua")
Expand All @@ -77,39 +92,103 @@ end

## File Structure

### Core Library
| File | Purpose |
|------|---------|
| `qrencode.lua` | Core QR code generation library |
| `qrimage.lua` | Image output functionality |
| `qrcode.lua` | Text/ASCII display utilities |
| `qrtest.lua` | Test suite for core library |
| `test_qrimage.lua` | Tests for image generation |

### Modern Testing Framework
| File | Purpose |
|------|---------|
| `tests/framework.lua` | Modern test framework with rich assertions |
| `tests/test_core.lua` | Comprehensive core algorithm tests |
| `tests/test_image.lua` | Complete image generation tests |
| `tests/run_all.lua` | Test runner for all suites |

### Legacy Tests (Reference Only)
| File | Purpose |
|------|---------|
| `tests/legacy/qrtest.lua` | Original core library tests |
| `tests/legacy/test_qrimage.lua` | Original image generation tests |

## Testing

```bash
# Test core QR generation
lua qrtest.lua
# Run all tests with modern framework
lua tests/run_all.lua

# Test image generation
lua -e 'dofile("test_qrimage.lua")'
# Individual test suites
lua -e '_G.test_framework = dofile("tests/framework.lua"); dofile("tests/test_core.lua"); _G.test_framework.run()'
lua -e '_G.test_framework = dofile("tests/framework.lua"); dofile("tests/test_image.lua"); _G.test_framework.run()'
```

## Supported Output Formats
### Legacy Tests (Reference Only)
```bash
# Original core tests (moved to legacy folder)
lua tests/legacy/qrtest.lua

- **PPM** - Generated natively by Lua (no dependencies)
- **PNG** - Converted from PPM using system tools
- **JPEG** - Converted from PPM using system tools
# Original image tests (moved to legacy folder)
lua -e 'dofile("tests/legacy/test_qrimage.lua")'
```

The library automatically detects available conversion tools (ImageMagick, netpbm, ffmpeg) and uses the first one found.
### Test Features
- **295 comprehensive assertions** covering all functionality
- **23 test suites** with logical organization
- **Rich assertion library** with clear error messages
- **100% test coverage** for both core and image functionality
- **CI-ready** with proper exit codes

## Error Correction Levels
## Performance
This library supports multiple Lua implementations with significant performance differences:

### Performance Testing
```bash
# Performance benchmarks
make benchmark # Compare test suite performance
make speed-test # Compare QR generation speed
make test-jit # Run tests with LuaJIT

# Bytecode compilation
make bytecode # Compile to bytecode for faster loading
make clean # Remove compiled files
```

All standard QR code error correction levels are supported:
- **L** (Low) - ~7% error correction
- **M** (Medium) - ~15% error correction
- **Q** (Quartile) - ~25% error correction
- **H** (High) - ~30% error correction

| Implementation | Test Suite | QR Generation (100 codes) | Improvement |
|---------------|------------|---------------------------|-------------|
| **Standard Lua** | 0.35s | 1.08s | Baseline |
| **LuaJIT** | 0.14s | 0.16s | **6.6x faster** |
| **Bytecode** | ~0.35s | ~1.08s | Faster loading only |


## Development

### Contributing
This fork maintains compatibility with the original library while adding modern capabilities.

**For external contributors:**
```bash
# Fork the repository on GitHub, then:
git clone https://github.com/YOUR_USERNAME/luaqrcode.git
cd luaqrcode
git remote add upstream https://github.com/knowlen/luaqrcode.git

# Create a feature branch
git checkout -b feature-name

# Make changes and test
# ... your modifications ...
lua tests/run_all.lua # Ensure all tests pass

# Commit and push to your fork
git add .
git commit -m "Your commit message"
git push origin feature-name

# Create a Pull Request on GitHub
```

## Credits

Expand All @@ -123,7 +202,8 @@ This is a fork of the original [luaqrcode](https://github.com/speedata/luaqrcode
- Native image output functionality (PPM/PNG/JPEG)
- Command-line interface for image generation
- Pure Lua implementation with no Python dependencies
- Comprehensive test suite for image generation
- Modern testing framework with 295 comprehensive assertions
- Professional CI-ready test infrastructure

## License

Expand All @@ -132,9 +212,4 @@ This is a fork of the original [luaqrcode](https://github.com/speedata/luaqrcode
Copyright (c) 2012-2020, Patrick Gundlach (SPEEDATA GMBH) and contributors
See [License.md](License.md) for full license text.

## Development

This fork maintains compatibility with the original library while adding modern image output capabilities. The core QR generation algorithm remains unchanged from the original implementation.

**Maintenance Status:** Active development (this fork)
**Original Status:** Maintained for bug fixes only
Loading
Loading