Skip to content

Commit

Permalink
[lua] add stack_push_generic, to push a lua_generic onto the stack.
Browse files Browse the repository at this point in the history
  • Loading branch information
harrand committed Jan 27, 2024
1 parent 0344c2d commit c3a4dd3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/tz/lua/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,34 @@ namespace tz::lua
lua_pushlstring(s, sv.data(), sv.size());
}

void state::stack_push_generic(lua_generic generic) const
{
std::visit([this](auto&& arg)
{
using T = std::decay_t<decltype(arg)>;
if constexpr(std::is_same_v<T, bool>)
{
this->stack_push_bool(arg);
}
else if constexpr(std::is_same_v<T, double>)
{
this->stack_push_double(arg);
}
else if constexpr(std::is_same_v<T, std::int64_t>)
{
this->stack_push_int(arg);
}
else if constexpr(std::is_same_v<T, std::string>)
{
this->stack_push_string(arg);
}
else if constexpr(std::is_same_v<T, tz::lua::nil>)
{
this->stack_push_nil();
}
}, generic);
}

void state::stack_push_ptr(void* ptr) const
{
auto* s = static_cast<lua_State*>(this->lstate);
Expand Down
1 change: 1 addition & 0 deletions src/tz/lua/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ namespace tz::lua
void stack_push_int(std::int64_t i) const;
void stack_push_uint(std::uint64_t u) const;
void stack_push_string(std::string_view sv) const;
void stack_push_generic(lua_generic generic) const;
// light user data
void stack_push_ptr(void* ptr) const;
template<typename T>
Expand Down

0 comments on commit c3a4dd3

Please sign in to comment.