add lua bindings with luarocks packaging support#29
Merged
MuriloChianfa merged 2 commits intomainfrom Jan 31, 2026
Merged
Conversation
Resolved conflicts in: - .github/workflows/ci.yml: Added Lua, Perl, PHP, and Python bindings tests - CMakeLists.txt: Combined Lua, Perl, PHP, and Python wrapper options - docker/README.md: Documented all language binding containers - scripts/docker-build.sh: Added support for all binding images This merge brings in the Perl (#28), Python (#27), and PHP (#26) bindings alongside the existing Lua bindings work.
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
MuriloChianfa
added a commit
that referenced
this pull request
Jan 31, 2026
Resolved conflicts in: - .github/workflows/ci.yml: Added C#, Lua, Perl, PHP, and Python bindings tests - CMakeLists.txt: Combined C#, Lua, Perl, PHP, and Python wrapper options - docker/README.md: Documented all language binding containers - scripts/docker-build.sh: Added support for all binding images This merge brings in the Lua (#29), Perl (#28), Python (#27), and PHP (#26) bindings alongside the existing C# bindings work.
MuriloChianfa
added a commit
that referenced
this pull request
Jan 31, 2026
Resolved conflicts in: - .github/workflows/ci.yml: Added Java, C#, Lua, Perl, PHP, and Python bindings tests - CMakeLists.txt: Combined Java, C#, Lua, Perl, PHP, and Python wrapper options - docker/README.md: Documented all language binding containers - scripts/docker-build.sh: Added support for all binding images This merge brings in the C# (#31), Lua (#29), Perl (#28), Python (#27), and PHP (#26) bindings alongside the existing Java bindings work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
This PR adds comprehensive Lua bindings for the liblpm C library, providing high-performance longest prefix match (LPM) routing table operations for Lua applications. The bindings deliver near-native C performance with minimal overhead, flexible input formats, dual API styles (object-oriented and functional), and automatic garbage collection integration.
Type of Change
Related Issues
Closes #
Motivation and Context
Lua is widely used in embedded systems, network appliances (OpenWrt, Kong, NGINX), game servers, and high-performance scripting scenarios where efficient IP routing lookups are critical. While Lua has various networking libraries, high-performance LPM implementations are virtually nonexistent. This implementation provides:
table:lookup()) and functional calls (lpm.lookup())This enables Lua developers to leverage liblpm's high-performance routing capabilities in networking appliances, edge devices, API gateways, and embedded systems.
Changes Made
Core Implementation
Main C Module (
src/liblpm.c): 795 lines of C code__gc) for automatic cleanup__tostringmetamethod for debuggingUtility Functions (
src/liblpm_utils.c): 354 linesAPI Features:
new_ipv4([algorithm]),new_ipv6([algorithm])insert(),delete(),lookup(),lookup_batch()close(),is_closed(),is_ipv6(),version()INVALID_NEXT_HOP,IPV4_MAX_DEPTH,IPV6_MAX_DEPTH,_VERSIONBuild System
CMakeLists.txt (209 lines): CMake integration
require()compatibilitylua_test,lua_exampleLuaRocks Specification (
liblpm-2.0.0-1.rockspec): 80 linesMakefile (standalone build support)
Testing & Quality
Test Suite (
tests/test_lpm.lua): Comprehensive test coverageExamples (3 comprehensive examples):
basic_example.lua(209 lines): Getting started, basic operationsipv6_example.lua: IPv6-specific operations and formatsbatch_example.lua: Batch processing for high throughputDocumentation
README.md (438 lines):
Inline Documentation:
Testing
Test Environment
Tests Performed
make lua_test)lua -e 'require("liblpm")')make lua_example)Test Output
Performance Impact
Performance Characteristics
Lua/C Boundary Overhead: The Lua C API adds approximately 10-30ns per call. To minimize overhead:
Batch Operations: Use
lookup_batch()for multiple addressesInput Format Selection:
Table Reuse: Avoid frequent create/destroy cycles
Benchmark Results
Key Takeaway: Batch operations reduce per-lookup cost by 2-3x. Use binary strings or byte tables in hot paths for maximum performance. Ideal for packet processing, log analysis, firewall rules, and API gateway routing.
Documentation
Documentation Highlights:
Code Quality
C Code Quality:
Lua Code Quality:
Breaking Changes
This is a new feature addition with no impact on existing C library or other language bindings.
Additional Notes
Key Features
table:lookup()) and functional (lpm.lookup(table, ...))Package Structure
Files Changed
Special Considerations
ifunc Resolver Issue: Due to GNU ifunc used in liblpm for SIMD runtime dispatch, the Lua module may require preloading:
The CMake build system handles this automatically for tests and examples. The LuaRocks spec includes notes about this requirement.
LuaRocks Distribution
Package is ready for LuaRocks upload:
Platform Support
Lua Versions:
Use Cases
Checklist
Reviewer Notes
Areas for Review
C Code Safety: Memory management and error handling
Lua API Design: Idiomatic and intuitive?
Input Format Parsing: Robustness and completeness
Build System: CMake and LuaRocks configuration
Documentation: Completeness and clarity
Compatibility: Lua version support
Testing Instructions
Development Workflow
Performance Testing
Known Limitations
Future Enhancements (Out of Scope)