Skip to content

Commit

Permalink
[lua] failed attempt to allow captureless lambdas for tz::lua::state:…
Browse files Browse the repository at this point in the history
…:assign_func :(
  • Loading branch information
harrand committed Aug 6, 2023
1 parent 349f6d3 commit b5e2921
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion src/tz/lua/state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#include "tz/core/data/handle.hpp"
#include <string>
#include <cstdint>
#include <type_traits>
#include <functional>

namespace tz::lua
{
Expand Down Expand Up @@ -43,7 +45,15 @@ namespace tz::lua
bool assign_uint(const char* varname, std::uint64_t u) const;
bool assign_func(const char* varname, auto anon_ptr) const
{
return this->assign_func(varname, reinterpret_cast<void*>(anon_ptr));
using T = std::decay_t<decltype(anon_ptr)>;
if constexpr(std::is_pointer_v<T>)
{
return this->assign_func(varname, reinterpret_cast<void*>(anon_ptr));
}
else
{
static_assert(false, "assign_func does not work with lambdas, sorry");
}
}
bool assign_func(const char* varname, void* func_ptr) const;
bool assign_string(const char* varname, std::string str) const;
Expand Down

0 comments on commit b5e2921

Please sign in to comment.