Skip to content

feat: richer errors, values/smart pointers, inheritance, and Lua-side DX - #3

Open
esrrhs wants to merge 5 commits into
masterfrom
feature/dx-value-inheritance
Open

esrrhs wants to merge 5 commits into
masterfrom
feature/dx-value-inheritance

Conversation

@esrrhs

@esrrhs esrrhs commented Dec 1, 2026

Copy link
Copy Markdown
Owner

Summary

Six follow-up improvements on master (8789f16):

  1. Richer errors — missing Lua functions/tables include the path or name (no function 'foo', no table 'bar' in path '...'); conversion failures include a position prefix (argument 2:, return 1:, element 3:).
  2. Value objects and smart pointers — copy-constructible registered classes can be pushed/read by value (Lua owns the copy); const T* is a non-owning borrow; std::unique_ptr<T> can be moved into Lua but not recovered; std::shared_ptr<T> shares the control block and can be recovered only from exact-type shared-backed userdata.
  3. Inheritance / safe upcast — reg_base<Derived, Base> lets a derived pointer be used where a base is expected. Base methods/properties are visible on derived objects. No implicit downcast; unrelated same-address types are still rejected.
  4. Lua-side DX — reg_class_overload (arity-only, including self); __call constructors on the registered type name (A(1)); field properties via __index / __newindex in addition to get_ / set_; C++ std::tuple / std::pair multi-return.
  5. Container indices — sequence indices use lua_Integer (lua_rawgeti / lua_rawseti on Lua 5.3+; a pushinteger + rawget/rawset fallback on 5.1/5.2 when the index does not fit int). lua_createtable hints remain clamped to int.
  6. Docs / version hygiene — CMake project(bLua VERSION 1.1.0) (find_package(bLua 1.0) still matches under SameMajorVersion). CHANGELOG no longer describes Windows CI as vcpkg Lua; it matches the pinned official Lua 5.4.7 / MSVC sources. README / README_CN list Lua 5.1, 5.2, and LuaJIT as Supported (CI). Changelog is prepared for a possible v1.1.0; this PR does not tag or create a GitHub Release.

Header-only C++17 design is unchanged. reg_constructor’s name is now optional; additional named constructors with the same arity reuse the existing __call slot.

Local tests

All 5/5 (blua_test, regressions, intentional failure exits, relocated find_package consumer):

  • Lua 5.4.9 Debug
  • Lua 5.4.9 Release
  • Lua 5.4.9 Debug + ASan/UBSan
  • Lua 5.3.4 Release

Lua 5.1/5.2, LuaJIT, Windows, and macOS were not run locally; this PR is meant to verify them on CI.

Notes

Please do not merge until CI is green and the maintainer asks for it. Do not tag v1.1.0 in this PR.

Add named lookup and positional conversion errors; by-value classes,
const T* borrows, unique_ptr move-in and shared_ptr sharing; reg_base
safe upcasts with inherited methods/properties; class method overloads,
__call constructors, field properties, and tuple multi-return; and
lua_Integer container indices. Prepare CMake/docs for a possible v1.1.0
without tagging a release.
thread_local state around the C++ exception to luaL_error boundary
caused LuaJIT (shared library) to report "unknown C++ exception"
from call_lua_* instead of the native what(). Keep prefixes
state-local and avoid TLS.
On MSVC, luaL_error longjmps out of a boundary try block when a
field getter/setter or overload is invoked via lua_call, which can
abort regressions with 0xC0000409. Catch Lua errors with lua_pcall
and rethrow as C++ so the boundary unwinds first. Also log
regression steps for diagnosis.
pcall_checked now treats a non-zero lua_pcall result as failure, matching
other protected-call sites. Retry apt-get in Linux CI after a transient
mirror 503 on liblua5.2.
Ubuntu universe mirrors were returning 503 for libluajit-5.1-dev even
after retries. Keep testing the shared library so the foreign-unwinder
path stays covered.
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.

1 participant