Skip to content

LuaRef::getPointer implementation - #259

Merged
kunitoki merged 4 commits into
masterfrom
dev/function_as_arguments
Jul 16, 2026
Merged

kunitoki merged 4 commits into
masterfrom
dev/function_as_arguments

Conversation

@kunitoki

@kunitoki kunitoki commented Jul 16, 2026

Copy link
Copy Markdown
Owner

This pull request updates the macOS GitHub Actions workflow and improves the LuaRef::getPointer() method in the LuaBridge codebase. The workflow now uses the correct method to determine the number of CPU cores on macOS, and the getPointer() method is enhanced to better handle Lua userdata and registered classes. Additional unit tests have been added to ensure correct behavior of getPointer() across various Lua types.

GitHub Actions Workflow Improvements:

  • Replaced usage of $(nproc) with $(sysctl -n hw.ncpu) in .github/workflows/build_macos.yml to correctly determine the number of CPU cores on macOS for parallel builds and tests. This change is applied for all Lua, LuaJIT, Luau, and Ravi build and test jobs across C++17, C++20, and C++23 configurations. [1] [2] [3] [4] [5] [6] [7] [8]

LuaRef Enhancements:

  • Improved the LuaRef::getPointer() implementation to correctly retrieve pointers for LuaBridge-registered userdata types by checking for a LuaBridge-specific metatable key and extracting the actual pointer from the internal userdata structure.
  • Adjusted stack space checks in getPointer() to reserve more slots for internal operations, improving safety when stack space is low.

Testing Improvements:

  • Added comprehensive unit tests for LuaRef::getPointer() covering default-constructed refs, nil, booleans, numbers, strings, tables, functions, light userdata, regular userdata, registered classes, and Lua threads. Also includes tests for stack overflow scenarios when safe stack checks are enabled.

Internal Code Quality:

  • Made the Userdata::getPointer() method public for better access in type extraction logic, and moved the constructor back to protected for proper encapsulation.
  • Added a call to detail::unreachable() after lua_error() to indicate to the compiler that the function does not return, improving code correctness and optimization. [1] [2]

@kunitoki
kunitoki force-pushed the dev/function_as_arguments branch from dd39388 to 4b61493 Compare July 16, 2026 15:12
@kunitoki kunitoki changed the title Unit tests for LuaRef::getPointer LuaRef::getPointer implementation Jul 16, 2026
@kunitoki kunitoki self-assigned this Jul 16, 2026
@kunitoki kunitoki added the enhancement New feature or request label Jul 16, 2026
@kunitoki
kunitoki merged commit 51e9102 into master Jul 16, 2026
45 checks passed
@kunitoki
kunitoki deleted the dev/function_as_arguments branch July 16, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant