Skip to content

Assorted set of fixes#234

Merged
kunitoki merged 1 commit intomasterfrom
dev/faster_vector_array
May 6, 2026
Merged

Assorted set of fixes#234
kunitoki merged 1 commit intomasterfrom
dev/faster_vector_array

Conversation

@kunitoki
Copy link
Copy Markdown
Owner

@kunitoki kunitoki commented May 6, 2026

This pull request makes several improvements and refactorings to the LuaBridge library and its benchmarks, focusing on safer and more convenient Lua-C++ interop, enhanced API usability, and improved code correctness. The main changes include introducing new helper functions for safer field access, enhancing move semantics and API annotations for LuaRef, and updating member function binding to improve type safety. Additionally, some benchmark code is simplified to use the new helpers.

LuaBridge API Improvements and Refactoring:

  • Added tryGetGlobalField and tryGetField helper functions for safer, optional field access from Lua tables and globals, reducing boilerplate and potential errors when a field or table is missing. (Distribution/LuaBridge/LuaBridge.h [1] [2]
  • Enhanced LuaRef::TableItem with move constructors, assignment operators, and a swap method, improving efficiency and safety in resource management. (Distribution/LuaBridge/LuaBridge.h [1] [2]
  • Added rvalue overloads for LuaRef::operator[] to support move semantics and more flexible table item access. (Distribution/LuaBridge/LuaBridge.h Distribution/LuaBridge/LuaBridge.hR10474-R10514)
  • Marked various methods as [[nodiscard]] to encourage correct usage and prevent accidental discarding of important return values (e.g., getField, rawgetField, setField, rawsetField, length, append, rawget). (Distribution/LuaBridge/LuaBridge.h [1] [2] [3] [4] [5] [6]

Member Function Binding and Userdata Handling:

  • Improved member function binding by passing class and const metatables as upvalues, and introduced get_member_object and Userdata::getExactPointer helpers for more robust and type-safe object retrieval from Lua. (Distribution/LuaBridge/LuaBridge.h [1] [2] [3] [4] [5] [6] [7]

Hashing, Comparison, and Miscellaneous Fixes:

  • Reworked LuaRef::hash() to use the Lua value on the stack and type-specific hashing, improving correctness and consistency. (Distribution/LuaBridge/LuaBridge.h Distribution/LuaBridge/LuaBridge.hL10493-R10677)
  • Corrected comparison operator implementations for LuaRef and other types to ensure proper logic. (Distribution/LuaBridge/LuaBridge.h Distribution/LuaBridge/LuaBridge.hL10559-R10732)
  • Minor API improvements: made LuaRefBase::getClassName const, and cleaned up tuple type usage in bind_back. (Distribution/LuaBridge/LuaBridge.h [1] [2]

Benchmark Code Simplification:

  • Updated benchmark functions to use the new tryGetGlobalField helper, reducing manual table checks and field access logic. (Benchmarks/benchmark_luabridge3.cpp [1] [2] [3]

Array and Vector Lua Table Conversion:

  • Improved array and vector-to-Lua table conversion by using lua_rawseti for more efficient and idiomatic Lua table population. (Distribution/LuaBridge/LuaBridge.h [1] [2]

@kunitoki kunitoki merged commit d76736e into master May 6, 2026
45 checks passed
@kunitoki kunitoki deleted the dev/faster_vector_array branch May 6, 2026 13:06
@kunitoki kunitoki changed the title Asseorted set of fixes Assorted set of fixes May 6, 2026
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