Skip to content

Commit

Permalink
lua_state: Add integer overloads for pushOne
Browse files Browse the repository at this point in the history
Otherwise, a small type mismatch (e.g. long long instead of int) will
cause ambiguity with e.g. the double overload.
  • Loading branch information
taminob committed Mar 28, 2024
1 parent fc5e63b commit b4e1943
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions include/lua/lua_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,15 @@ class LuaState {
std::optional<std::function<Func>> popFunction(bool always_pop = false);

void pushOne(double value);
void pushOne(int value);
// NOLINTBEGIN(google-runtime-int)
// TODO: use template instead
void pushOne(unsigned int value) { pushOne(static_cast<long long>(value)); }
void pushOne(int value) { pushOne(static_cast<long long>(value)); }
void pushOne(unsigned long value) { pushOne(static_cast<long long>(value)); }
void pushOne(long value) { pushOne(static_cast<long long>(value)); }
void pushOne(unsigned long long value) { pushOne(static_cast<long long>(value)); }
void pushOne(long long value);
// NOLINTEND(google-runtime-int)
void pushOne(const char* value);
void pushOne(std::string_view value);
void pushOne(bool value);
Expand Down Expand Up @@ -259,7 +267,6 @@ auto LuaState::topFunction()
}
return std::optional<decltype(top_function)> { std::nullopt };
}

} // namespace ppplugin

#endif // PPPLUGIN_LUA_STATE_H
3 changes: 2 additions & 1 deletion src/lua_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ void LuaState::pushOne(double value)
lua_pushnumber(state(), value);
}

void LuaState::pushOne(int value)
// NOLINTNEXTLINE(google-runtime-int)
void LuaState::pushOne(long long value)
{
lua_pushinteger(state(), value);
}
Expand Down

0 comments on commit b4e1943

Please sign in to comment.