1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2025-02-04 21:18:33 +00:00

Use SFINAE to collapse numeric pust_table_value impls

Signed-off-by: Tin <tin.svagelj@live.com>
This commit is contained in:
Tin 2023-11-08 05:25:15 +01:00 committed by Brenden Matthews
parent b5652006ef
commit c4ef5f5e8c
No known key found for this signature in database
GPG Key ID: 137B7AC2BDFD8DF0

View File

@ -24,32 +24,28 @@
#include <string>
#include <lua.h>
#include <time.h>
#include <type_traits>
/* Lua helper functions */
template <typename T>
void push_table_value(lua_State *L, std::string key, T value);
void push_table_value(lua_State *L, std::string key, std::string value) {
lua_pushstring(L, key.c_str());
lua_pushstring(L, value.c_str());
lua_settable(L, -3);
}
void push_table_value(lua_State *L, std::string key, int value) {
lua_pushstring(L, key.c_str());
lua_pushinteger(L, value);
lua_settable(L, -3);
template <typename T>
typename std::enable_if<std::is_integral<T>::value>::type
push_table_value(lua_State *L, std::string key, T value) {
lua_pushstring(L, key.c_str());
lua_pushinteger(L, value);
lua_settable(L, -3);
}
void push_table_value(lua_State *L, std::string key, uint32_t value) {
template <typename T>
typename std::enable_if<std::is_floating_point<T>::value>::type
push_table_value(lua_State *L, std::string key, T value) {
lua_pushstring(L, key.c_str());
lua_pushinteger(L, value);
lua_settable(L, -3);
}
void push_table_value(lua_State *L, std::string key, uint64_t value) {
lua_pushstring(L, key.c_str());
lua_pushinteger(L, value);
lua_pushnumber(L, value);
lua_settable(L, -3);
}
@ -59,18 +55,6 @@ void push_table_value(lua_State *L, std::string key, bool value) {
lua_settable(L, -3);
}
void push_table_value(lua_State *L, std::string key, float value) {
lua_pushstring(L, key.c_str());
lua_pushnumber(L, value);
lua_settable(L, -3);
}
void push_table_value(lua_State *L, std::string key, double value) {
lua_pushstring(L, key.c_str());
lua_pushnumber(L, value);
lua_settable(L, -3);
}
template <size_t N>
void push_bitset(lua_State *L, std::bitset<N> it,
std::array<std::string, N> labels) {