Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add options and properties #357

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ set(LUA_VERSION "lua" CACHE STRING "lua version")
if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/lua5.4/lua.h")
find_package(PkgConfig)
if(PkgConfig_FOUND)
foreach(pkg ${LUA_VERSION} lua54 lua53 lua52 luajit lua51)
foreach(pkg $ENV{LUA_VERSION} ${LUA_VERSION} lua lua54 lua53 lua52 luajit lua51)
pkg_check_modules(LUA IMPORTED_TARGET GLOBAL ${pkg})
if(LUA_FOUND)
break()
break()
endif()
endforeach()
endif()
Expand Down
18 changes: 18 additions & 0 deletions src/lib/lauxlib-compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,21 @@ void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
lua_pop(L, nup); /* remove upvalues */
}
#endif

//copy from lua 5.4
#if LUA_VERSION_NUM < 504
int luaL_typeerror(lua_State *L, int arg, const char *tname) {
const char *msg;
const char *typearg;
luaL_getmetafield(L, arg, "__name");
int type = lua_type(L, -1);
if (type == LUA_TSTRING)
typearg = lua_tostring(L, -1);
else if (type == LUA_TLIGHTUSERDATA)
typearg = "light userdata";
else
typearg = luaL_typename(L, arg);
msg = lua_pushfstring(L, "%s expected, got %s", tname, typearg);
return luaL_argerror(L, arg, msg);
}
#endif
4 changes: 4 additions & 0 deletions src/lib/lua-compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,8 @@ static inline int xlua_resume(lua_State *L, int nargs)

void xluaopen_utf8(lua_State *);

#if LUA_VERSION_NUM < 504
LUALIB_API int luaL_typeerror(lua_State *L, int arg, const char *tname);
#endif

#endif /* LUA_COMPAT_H */
31 changes: 31 additions & 0 deletions src/lib/lua_templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <typeinfo>
#include <vector>
#include <set>
#include <map>
#include <cstring>

#ifdef __GNUC__
Expand Down Expand Up @@ -419,6 +420,36 @@ struct LuaType<std::set<T>> {
}
};

// Map
template<typename K, typename V>
struct LuaType<std::map<K,V>> {
static void pushdata(lua_State *L, const std::map<K, V> &o) {
lua_createtable(L, 0, o.size());
for (auto it = o.begin(); it != o.end(); it++) {
LuaType<K>::pushdata(L, it->first);
LuaType<V>::pushdata(L, it->second);
lua_rawset(L, -3);
}
}

static std::map<K, V> &todata(lua_State *L, int j, C_State *C) {
auto &o = C->alloc<std::map<K, V>>();
o.clear();
lua_pushnil(L); /* first key */
while (lua_next(L, j) != 0) {
o.insert( {LuaType<K>::todata(L, -2, C), LuaType<V>::todata(L, -1, C)});
lua_pop(L, 1);
}
return o;
}
};

template<typename K, typename V>
struct LuaType<const std::map<K, V>> : LuaType<std::map<K, V>> {};

template<typename K, typename V>
struct LuaType<const std::map<K, V> &> : LuaType<std::map<K, V>> {};

template<typename T>
struct LuaType<const std::vector<T>> : LuaType<std::vector<T>> {};

Expand Down
6 changes: 6 additions & 0 deletions src/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,8 @@ namespace ContextReg {
{ "get_option", WRAPMEM(T::get_option) },
{ "set_property", WRAPMEM(T::set_property) },
{ "get_property", WRAPMEM(T::get_property) },
{ "get_options", WRAPMEM(T, options) },
{ "get_properties", WRAPMEM(T, properties) },
{ "clear_transient_options", WRAPMEM(T::ClearTransientOptions) },
{ NULL, NULL },
};
Expand All @@ -810,6 +812,8 @@ namespace ContextReg {
{ "property_update_notifier", WRAPMEM(T::property_update_notifier) },
{ "unhandled_key_notifier", WRAPMEM(T::unhandled_key_notifier) },
{ "commit_history", WRAP(get_commit_history) },
{ "options", WRAPMEM(T, options) },
{ "properties", WRAPMEM(T, properties) },
{ NULL, NULL },
};

Expand Down Expand Up @@ -1448,6 +1452,7 @@ static int raw_connect(lua_State *L) {
return 1;
}


namespace ConnectionReg {
using T = boost::signals2::connection;

Expand All @@ -1472,6 +1477,7 @@ namespace ConnectionReg {
namespace NotifierReg {
typedef Context::Notifier T;


static const luaL_Reg funcs[] = {
{ NULL, NULL },
};
Expand Down