diff --git a/client.c b/client.c index 5b00a8e10..65a0331b7 100644 --- a/client.c +++ b/client.c @@ -1598,7 +1598,7 @@ luaA_client_geometry(lua_State *L) static inline int luaA_pushstruts(lua_State *L, strut_t struts) { - lua_newtable(L); + lua_createtable(L, 4, 0); lua_pushnumber(L, struts.left); lua_setfield(L, -2, "left"); lua_pushnumber(L, struts.right); @@ -1980,7 +1980,7 @@ luaA_client_index(lua_State *L) { const char *u_or_p = NULL; - lua_newtable(L); + lua_createtable(L, 0, 1); if(c->size_hints.flags & XCB_SIZE_HINT_US_POSITION) u_or_p = "user_position"; @@ -1989,7 +1989,7 @@ luaA_client_index(lua_State *L) if(u_or_p) { - lua_newtable(L); + lua_createtable(L, 0, 2); lua_pushnumber(L, c->size_hints.x); lua_setfield(L, -2, "x"); lua_pushnumber(L, c->size_hints.y); @@ -2005,7 +2005,7 @@ luaA_client_index(lua_State *L) if(u_or_p) { - lua_newtable(L); + lua_createtable(L, 0, 2); lua_pushnumber(L, c->size_hints.width); lua_setfield(L, -2, "width"); lua_pushnumber(L, c->size_hints.height); diff --git a/dbus.c b/dbus.c index d19b977cd..bd44ae8ac 100644 --- a/dbus.c +++ b/dbus.c @@ -72,15 +72,17 @@ a_dbus_message_iter(DBusMessageIter *iter) break; case DBUS_TYPE_STRUCT: { - /* create a new table to store all the value */ - lua_newtable(globalconf.L); - DBusMessageIter subiter; /* initialize a sub iterator */ dbus_message_iter_recurse(iter, &subiter); - /* create a new table to store the dict */ + int n = a_dbus_message_iter(&subiter); + /* create a new table to store all the value */ + lua_createtable(globalconf.L, n, 0); + /* move the table before array elements */ + lua_insert(globalconf.L, - n - 1); + for(int i = n; i > 0; i--) lua_rawseti(globalconf.L, - i - 1, i); } @@ -102,8 +104,8 @@ a_dbus_message_iter(DBusMessageIter *iter) case dbustype: \ { \ const type *data; \ - lua_newtable(globalconf.L); \ dbus_message_iter_get_fixed_array(&sub, &data, &datalen); \ + lua_createtable(globalconf.L, datalen, 0); \ for(int i = 0; i < datalen; i++) \ { \ lua_pushnumber(globalconf.L, data[i]); \ @@ -129,8 +131,8 @@ a_dbus_message_iter(DBusMessageIter *iter) case DBUS_TYPE_BOOLEAN: { const bool *b; - lua_newtable(globalconf.L); dbus_message_iter_get_fixed_array(&sub, &b, &datalen); + lua_createtable(globalconf.L, datalen, 0); for(int i = 0; i < datalen; i++) { lua_pushboolean(globalconf.L, b[i]); @@ -143,30 +145,35 @@ a_dbus_message_iter(DBusMessageIter *iter) else if(array_type == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter subiter; - - lua_newtable(globalconf.L); - /* initialize a sub iterator */ dbus_message_iter_recurse(iter, &subiter); + /* get the keys and the values - * n is the number of entry in * dict */ + * n is the number of entry in dict */ int n = a_dbus_message_iter(&subiter); + /* create a new table to store all the value */ + lua_createtable(globalconf.L, n, 0); + /* move the table before array elements */ + lua_insert(globalconf.L, - (n * 2) - 1); + for(int i = 0; i < n; i ++) lua_rawset(globalconf.L, - (n * 2) - 1 + i * 2); } else { DBusMessageIter subiter; - - lua_newtable(globalconf.L); - /* prepare to dig into the array*/ dbus_message_iter_recurse(iter, &subiter); /* now iterate over every element of the array */ int n = a_dbus_message_iter(&subiter); + /* create a new table to store all the value */ + lua_createtable(globalconf.L, n, 0); + /* move the table before array elements */ + lua_insert(globalconf.L, - n - 1); + for(int i = n; i > 0; i--) lua_rawseti(globalconf.L, - i - 1, i); } @@ -225,7 +232,7 @@ a_dbus_process_request(DBusConnection *dbus_connection, DBusMessage *msg) if(globalconf.hooks.dbus == LUA_REFNIL) return; - lua_newtable(globalconf.L); + lua_createtable(globalconf.L, 0, 5); switch(dbus_message_get_type(msg)) { diff --git a/keygrabber.c b/keygrabber.c index 35b9ae57e..710924732 100644 --- a/keygrabber.c +++ b/keygrabber.c @@ -692,7 +692,7 @@ keygrabber_handlekpress(lua_State *L, xcb_key_press_event_t *e) if(!key_press_lookup_string(e, buf, countof(buf), &ksym)) return false; - lua_newtable(L); + lua_createtable(L, 0, 8); lua_pushboolean(L, e->state & XCB_MOD_MASK_CONTROL); lua_setfield(L, -2, "Control"); diff --git a/luaa.c b/luaa.c index 0a43e5bff..1e06befc6 100644 --- a/luaa.c +++ b/luaa.c @@ -418,7 +418,7 @@ luaA_table2wtable(lua_State *L) return; lua_newtable(L); /* create *real* content table */ - lua_newtable(L); /* metatable */ + lua_createtable(L, 0, 5); /* metatable */ lua_pushvalue(L, -2); /* copy content table */ lua_pushcfunction(L, luaA_ipairs_aux); /* push ipairs aux */ lua_pushcclosure(L, luaA_wtable_ipairs, 2); diff --git a/luaa.h b/luaa.h index cfb6b815f..3eaad1bbe 100644 --- a/luaa.h +++ b/luaa.h @@ -173,7 +173,7 @@ luaA_getopt_boolean(lua_State *L, int idx, const char *name, bool def) static inline int luaA_pusharea(lua_State *L, area_t geometry) { - lua_newtable(L); + lua_createtable(L, 0, 4); lua_pushnumber(L, geometry.x); lua_setfield(L, -2, "x"); lua_pushnumber(L, geometry.y); @@ -316,7 +316,7 @@ luaA_getopt_padding(lua_State *L, int idx, padding_t *dpadding) static inline int luaA_pushpadding(lua_State *L, padding_t *padding) { - lua_newtable(L); + lua_createtable(L, 0, 4); lua_pushnumber(L, padding->right); lua_setfield(L, -2, "right"); lua_pushnumber(L, padding->left); diff --git a/mouse.c b/mouse.c index 810a172d0..ef0c805ec 100644 --- a/mouse.c +++ b/mouse.c @@ -393,13 +393,13 @@ luaA_mouse_newindex(lua_State *L) int luaA_mouse_pushstatus(lua_State *L, int x, int y, uint16_t mask) { - lua_newtable(L); + lua_createtable(L, 0, 2); lua_pushnumber(L, x); lua_setfield(L, -2, "x"); lua_pushnumber(L, y); lua_setfield(L, -2, "y"); - lua_newtable(L); + lua_createtable(L, 5, 0); int i = 1; diff --git a/screen.c b/screen.c index 83be66d2e..434dd6750 100644 --- a/screen.c +++ b/screen.c @@ -431,7 +431,7 @@ luaA_screen_tags(lua_State *L) } else { - lua_newtable(L); + lua_createtable(L, s->tags.len, 0); for(i = 0; i < s->tags.len; i++) { tag_push(L, s->tags.tab[i]); diff --git a/spawn.c b/spawn.c index b9d1ec636..bb35b3a84 100644 --- a/spawn.c +++ b/spawn.c @@ -77,7 +77,7 @@ spawn_monitor_event(SnMonitorEvent *event, void *data) SnStartupSequence *sequence = sn_monitor_event_get_startup_sequence(event); SnMonitorEventType event_type = sn_monitor_event_get_type(event); - lua_newtable(globalconf.L); + lua_createtable(globalconf.L, 0, 2); lua_pushstring(globalconf.L, sn_startup_sequence_get_id(sequence)); lua_setfield(globalconf.L, -2, "id");