Efficiently creates new LUA "named tuples" with the specified field names. More...
#include <lua_common.hpp>
Public Member Functions | |
| lua_named_tuple_builder (const std::vector< std::string > &names) | |
| void | push (lua_State *L) const |
| Push an empty "named tuple" onto the stack. More... | |
Static Private Member Functions | |
| static int | impl_get (lua_State *L) |
| static int | impl_set (lua_State *L) |
| static int | impl_dir (lua_State *L) |
| static int | impl_tostring (lua_State *L) |
| static int | impl_compare (lua_State *L) |
| static std::string | build_key (const std::vector< std::string > &names) |
Private Attributes | |
| const std::vector< std::string > | names_ |
| const std::string | key_ |
Static Private Attributes | |
| static constexpr std::string_view | base_name_ = "named tuple" |
Efficiently creates new LUA "named tuples" with the specified field names.
Use the push method to create a new empty tuple instance at the top of the stack.
All tuples have some fixed layout and the total set of layouts is small (10-ish). So, we simply store the meta table the LUA registry once and then keep reusing it. Saves tons of construction effort. For maximum reuse, you should create static instances of this class.
Definition at line 84 of file lua_common.hpp.
| lua_named_tuple_builder::lua_named_tuple_builder | ( | const std::vector< std::string > & | names | ) |
Definition at line 727 of file lua_common.cpp.
|
staticprivate |
Definition at line 758 of file lua_common.cpp.
References base_name_, i, and names.
|
staticprivate |
|
staticprivate |
Definition at line 677 of file lua_common.cpp.
Referenced by push().
|
staticprivate |
Definition at line 641 of file lua_common.cpp.
References utils::find(), i, and names.
Referenced by push().
|
staticprivate |
Definition at line 657 of file lua_common.cpp.
References utils::find(), i, and names.
Referenced by push().
|
staticprivate |
Definition at line 683 of file lua_common.cpp.
References i, utils::join(), and lua_push().
Referenced by push().
| void lua_named_tuple_builder::push | ( | lua_State * | L | ) | const |
Push an empty "named tuple" onto the stack.
A named tuple is an array where each index can also be accessed by name. Once it's pushed, you can set the elements, eg with lua_rawseti.
Definition at line 733 of file lua_common.cpp.
References impl_compare(), impl_dir(), impl_get(), impl_set(), impl_tostring(), key_, lua_push(), and names_.
Referenced by luaW_filltable(), luaW_pushcubeloc(), and luaW_pushlocation().
|
staticconstexprprivate |
Definition at line 107 of file lua_common.hpp.
Referenced by build_key().
|
private |
Definition at line 110 of file lua_common.hpp.
Referenced by push().
|
private |
Definition at line 109 of file lua_common.hpp.
Referenced by push().