Skip to content

Feat/Lua loader#781

Open
k5602 wants to merge 12 commits into
metacall:developfrom
k5602:feat/lua_loader
Open

Feat/Lua loader#781
k5602 wants to merge 12 commits into
metacall:developfrom
k5602:feat/lua_loader

Conversation

@k5602
Copy link
Copy Markdown
Contributor

@k5602 k5602 commented Apr 21, 2026

Description

This PR implements a robust, production-ready Lua loader for MetaCall, transitioning from standard scaffolded Lua to LuaJIT. It introduces a complete value conversion system, enhanced function discovery, and comprehensive edge-case testing.

Key Changes

  • LuaJIT Integration: Added FindLuaJIT.cmake and updated the build system to prioritize LuaJIT for improved performance and integration.
  • Deep Value Conversion: Implemented lua_loader_convert.c which handles bidirectional conversion between Lua tables (detecting both arrays and maps) and MetaCall types, including a safety recursion limit of 10 as a best practice.
  • Environment Isolation: Each loaded script now runs in its own isolated environment table, preventing global namespace pollution between handles.
  • Enhanced Discovery: Function discovery uses debug.getinfo to introspect parameter counts and supports variadic functions (up to 64 arguments).
  • Execution Path Management: Added support for adding and searching multiple execution paths for relative file lookups.
  • Edge-Case Test Suite: Introduced metacall_lua_mixed_test, a comprehensive test suite covering 40+ scenarios including numeric boundaries (INT64), Unicode strings, sparse arrays, and multiple return values.

Closes #675

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) - Switch to LuaJIT requirement.
  • This change requires a documentation update
  • Documentation update - Updated READMEs and inline documentation.

Checklist:

  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have made corresponding changes to the documentation.
  • My changes generate no new warnings.
  • I have added tests/screenshots (if any) that prove my fix is effective or that my feature works.
  • I have tested the tests implicated (if any) by my own code and they pass (make test or ctest -VV -R <test-name>).
  • If my change is significant or breaking, I have passed all tests with ./docker-compose.sh test &> output and attached the output.
  • I have tested my code with OPTION_BUILD_ADDRESS_SANITIZER or ./docker-compose.sh test-address-sanitizer &> output and OPTION_TEST_MEMORYCHECK.
  • I have tested my code with OPTION_BUILD_THREAD_SANITIZER or ./docker-compose.sh test-thread-sanitizer &> output.
  • I have tested with Helgrind in case my code works with threading.
  • I have run make clang-format in order to format my code and my code follows the style guidelines.

k5602 added 11 commits April 10, 2026 14:23
Enhance the Lua loader to correctly identify empty tables as maps and
improve function reflection to support variadic arguments by allowing
up to 64 parameters.

Additionally, improve the robustness of table-to-array conversion by
verifying consecutive indexing and add a comprehensive test suite
covering numeric boundaries, string edge cases, and mixed types.
Use early returns in Lua to value conversion and remove redundant
name and handle fields from the internal function structure.
@k5602 k5602 force-pushed the feat/lua_loader branch from 9097bf1 to 9ab1201 Compare April 22, 2026 13:52
Implement native integer detection for Lua 5.3+ and improve conversion
safety for Lua 5.1/LuaJIT by using a 2^53 safe integer limit.
Integral numbers are now mapped to METACALL_LONG instead of
METACALL_INT. Additionally, standardize header includes and
increase recursion depth.
@k5602 k5602 force-pushed the feat/lua_loader branch from 1500311 to d096e92 Compare April 22, 2026 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lua Loader

1 participant