Skip to content

Commit 9a4b355

Browse files
authored
refactor: use lua_pushliteral instead of lua_pushstring (#4066)
1 parent 219fa9f commit 9a4b355

5 files changed

Lines changed: 49 additions & 51 deletions

File tree

event.c

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -392,25 +392,25 @@ event_handle_configurerequest(xcb_configure_request_event_t *ev)
392392

393393
/* Request the changes to be applied */
394394
luaA_object_push(L, c);
395-
lua_pushstring(L, "ewmh"); /* context */
395+
lua_pushliteral(L, "ewmh"); /* context */
396396
lua_newtable(L); /* props */
397397

398398
/* area, it needs to be directly in the `hints` table to comply with
399399
the "protocol"
400400
*/
401-
lua_pushstring(L, "x");
401+
lua_pushliteral(L, "x");
402402
lua_pushinteger(L, geometry.x);
403403
lua_rawset(L, -3);
404404

405-
lua_pushstring(L, "y");
405+
lua_pushliteral(L, "y");
406406
lua_pushinteger(L, geometry.y);
407407
lua_rawset(L, -3);
408408

409-
lua_pushstring(L, "width");
409+
lua_pushliteral(L, "width");
410410
lua_pushinteger(L, geometry.width);
411411
lua_rawset(L, -3);
412412

413-
lua_pushstring(L, "height");
413+
lua_pushliteral(L, "height");
414414
lua_pushinteger(L, geometry.height);
415415
lua_rawset(L, -3);
416416

@@ -898,7 +898,6 @@ event_handle_randr_output_change_notify(xcb_randr_notify_event_t *ev)
898898
if(ev->subCode == XCB_RANDR_NOTIFY_OUTPUT_CHANGE) {
899899
xcb_randr_output_t output = ev->u.oc.output;
900900
uint8_t connection = ev->u.oc.connection;
901-
const char *connection_str = NULL;
902901
xcb_randr_get_output_info_reply_t *info;
903902
lua_State *L = globalconf_get_lua_State();
904903

@@ -914,20 +913,19 @@ event_handle_randr_output_change_notify(xcb_randr_notify_event_t *ev)
914913
if(!info)
915914
return;
916915

917-
switch(connection) {
918-
case XCB_RANDR_CONNECTION_CONNECTED:
919-
connection_str = "Connected";
920-
break;
921-
case XCB_RANDR_CONNECTION_DISCONNECTED:
922-
connection_str = "Disconnected";
923-
break;
924-
default:
925-
connection_str = "Unknown";
926-
break;
916+
lua_pushlstring(L, (char*)xcb_randr_get_output_info_name(info), xcb_randr_get_output_info_name_length(info));
917+
switch (connection) {
918+
case XCB_RANDR_CONNECTION_CONNECTED:
919+
lua_pushliteral(L, "Connected");
920+
break;
921+
case XCB_RANDR_CONNECTION_DISCONNECTED:
922+
lua_pushliteral(L, "Disconnected");
923+
break;
924+
default:
925+
lua_pushliteral(L, "Unknown");
926+
break;
927927
}
928928

929-
lua_pushlstring(L, (char *)xcb_randr_get_output_info_name(info), xcb_randr_get_output_info_name_length(info));
930-
lua_pushstring(L, connection_str);
931929
signal_object_emit(L, &global_signals, "screen::change", 2);
932930

933931
p_delete(&info);

ewmh.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -215,16 +215,16 @@ ewmh_update_maximize(bool h, bool status, bool toggle)
215215
lua_State *L = globalconf_get_lua_State();
216216

217217
if (h)
218-
lua_pushstring(L, "client_maximize_horizontal");
218+
lua_pushliteral(L, "client_maximize_horizontal");
219219
else
220-
lua_pushstring(L, "client_maximize_vertical");
220+
lua_pushliteral(L, "client_maximize_vertical");
221221

222222
/* Create table argument with raise=true. */
223223
lua_newtable(L);
224-
lua_pushstring(L, "toggle");
224+
lua_pushliteral(L, "toggle");
225225
lua_pushboolean(L, toggle);
226226
lua_settable(L, -3);
227-
lua_pushstring(L, "status");
227+
lua_pushliteral(L, "status");
228228
lua_pushboolean(L, status);
229229
lua_settable(L, -3);
230230

@@ -467,7 +467,7 @@ ewmh_process_client_message(xcb_client_message_event_t *ev)
467467
{
468468
lua_State *L = globalconf_get_lua_State();
469469
luaA_object_push(L, globalconf.tags.tab[idx]);
470-
lua_pushstring(L, "ewmh");
470+
lua_pushliteral(L, "ewmh");
471471
luaA_object_emit_signal(L, -2, "request::select", 1);
472472
lua_pop(L, 1);
473473
}
@@ -499,11 +499,11 @@ ewmh_process_client_message(xcb_client_message_event_t *ev)
499499
if((c = client_getbywin(ev->window))) {
500500
lua_State *L = globalconf_get_lua_State();
501501
luaA_object_push(L, c);
502-
lua_pushstring(L, "ewmh");
502+
lua_pushliteral(L, "ewmh");
503503

504504
/* Create table argument with raise=true. */
505505
lua_newtable(L);
506-
lua_pushstring(L, "raise");
506+
lua_pushliteral(L, "raise");
507507
lua_pushboolean(L, true);
508508
lua_settable(L, -3);
509509

luaa.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -591,14 +591,14 @@ static int luaA_get_modifiers(lua_State *L)
591591

592592
lua_newtable(L);
593593

594-
lua_pushstring(L, "keycode");
594+
lua_pushliteral(L, "keycode");
595595
lua_pushinteger(L, key_code);
596596
lua_settable(L, -3);
597597

598598
/* Technically it is possible to get multiple keysyms here,
599599
* but... we just use the first one.
600600
*/
601-
lua_pushstring(L, "keysym");
601+
lua_pushliteral(L, "keysym");
602602
char *string = key_get_keysym_name(keysyms[0]);
603603
lua_pushstring(L, string);
604604
p_delete(&string);
@@ -900,7 +900,7 @@ luaA_tolstring(lua_State *L, int idx, size_t *len)
900900
lua_pushfstring(L, "%f", lua_tonumber(L, -1));
901901
break;
902902
case LUA_TNIL:
903-
lua_pushstring(L, "nil");
903+
lua_pushliteral(L, "nil");
904904
break;
905905
default:
906906
lua_pushfstring(L, "%s: %p",
@@ -941,7 +941,7 @@ static void
941941
setup_awesome_signals(lua_State *L)
942942
{
943943
lua_getglobal(L, "awesome");
944-
lua_pushstring(L, "unix_signal");
944+
lua_pushliteral(L, "unix_signal");
945945
lua_newtable(L);
946946

947947
#define SETUP_SIGNAL(sig) \
@@ -951,7 +951,7 @@ setup_awesome_signals(lua_State *L)
951951
lua_setfield(L, -2, #sig); \
952952
/* Set awesome.unix_signal[42] = "SIGSTOP" */ \
953953
lua_pushinteger(L, sig); \
954-
lua_pushstring(L, #sig); \
954+
lua_pushliteral(L, #sig); \
955955
lua_settable(L, -3); \
956956
} while (0)
957957

objects/client.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2297,9 +2297,9 @@ client_manage(xcb_window_t w, xcb_get_geometry_reply_t *wgeom, xcb_get_window_at
22972297

22982298
/* Add the context */
22992299
if (globalconf.loop == NULL)
2300-
lua_pushstring(L, "startup");
2300+
lua_pushliteral(L, "startup");
23012301
else
2302-
lua_pushstring(L, "new");
2302+
lua_pushliteral(L, "new");
23032303

23042304
/* Hints */
23052305
lua_newtable(L);
@@ -2741,7 +2741,7 @@ client_set_fullscreen(lua_State *L, int cidx, bool s)
27412741
client_set_ontop(L, cidx, false);
27422742
}
27432743
int abs_cidx = luaA_absindex(L, cidx); \
2744-
lua_pushstring(L, "fullscreen");
2744+
lua_pushliteral(L, "fullscreen");
27452745
c->fullscreen = s;
27462746
luaA_object_emit_signal(L, abs_cidx, "request::geometry", 1);
27472747
luaA_object_emit_signal(L, abs_cidx, "property::fullscreen", 0);
@@ -2983,15 +2983,15 @@ client_unmanage(client_t *c, client_unmanage_t reason)
29832983
{
29842984
break;
29852985
case CLIENT_UNMANAGE_USER:
2986-
lua_pushstring(L, "user");
2986+
lua_pushliteral(L, "user");
29872987
break;
29882988
case CLIENT_UNMANAGE_REPARENT:
2989-
lua_pushstring(L, "reparented");
2989+
lua_pushliteral(L, "reparented");
29902990
break;
29912991
case CLIENT_UNMANAGE_UNMAP:
29922992
case CLIENT_UNMANAGE_FAILED:
29932993
case CLIENT_UNMANAGE_DESTROYED:
2994-
lua_pushstring(L, "destroyed");
2994+
lua_pushliteral(L, "destroyed");
29952995
break;
29962996
}
29972997

@@ -4480,7 +4480,7 @@ client_tostring(lua_State *L, client_t *c)
44804480

44814481
lua_pushlstring(L, name, MIN(len, limit));
44824482
if (len > limit)
4483-
lua_pushstring(L, "...");
4483+
lua_pushliteral(L, "...");
44844484
return len > limit ? 2 : 1;
44854485
}
44864486

objects/screen.c

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -396,19 +396,19 @@ luaA_viewport_get_outputs(lua_State *L, viewport_t *a)
396396
foreach(output, a->outputs) {
397397
lua_createtable(L, 3, 0);
398398

399-
lua_pushstring(L, "mm_width");
399+
lua_pushliteral(L, "mm_width");
400400
lua_pushinteger(L, output->mm_width);
401401
lua_settable(L, -3);
402402

403-
lua_pushstring(L, "mm_height");
403+
lua_pushliteral(L, "mm_height");
404404
lua_pushinteger(L, output->mm_height);
405405
lua_settable(L, -3);
406406

407-
lua_pushstring(L, "name");
407+
lua_pushliteral(L, "name");
408408
lua_pushstring(L, output->name);
409409
lua_settable(L, -3);
410410

411-
lua_pushstring(L, "viewport_id");
411+
lua_pushliteral(L, "viewport_id");
412412
lua_pushinteger(L, a->id);
413413
lua_settable(L, -3);
414414

@@ -434,33 +434,33 @@ luaA_viewports(lua_State *L)
434434
lua_newtable(L);
435435

436436
/* The geometry */
437-
lua_pushstring(L, "geometry");
437+
lua_pushliteral(L, "geometry");
438438

439439
lua_newtable(L);
440440

441-
lua_pushstring(L, "x");
441+
lua_pushliteral(L, "x");
442442
lua_pushinteger(L, a->x);
443443
lua_settable(L, -3);
444-
lua_pushstring(L, "y");
444+
lua_pushliteral(L, "y");
445445
lua_pushinteger(L, a->y);
446446
lua_settable(L, -3);
447-
lua_pushstring(L, "width");
447+
lua_pushliteral(L, "width");
448448
lua_pushinteger(L, a->width);
449449
lua_settable(L, -3);
450-
lua_pushstring(L, "height");
450+
lua_pushliteral(L, "height");
451451
lua_pushinteger(L, a->height);
452452
lua_settable(L, -3);
453453

454454
/* Add the geometry table to the arguments */
455455
lua_settable(L, -3);
456456

457457
/* Add the outputs table to the arguments */
458-
lua_pushstring(L, "outputs");
458+
lua_pushliteral(L, "outputs");
459459
luaA_viewport_get_outputs(L, a);
460460
lua_settable(L, -3);
461461

462462
/* Add an identifier to better detect when screens are removed */
463-
lua_pushstring(L, "id");
463+
lua_pushliteral(L, "id");
464464
lua_pushinteger(L, a->id);
465465
lua_settable(L, -3);
466466

@@ -1609,11 +1609,11 @@ static int
16091609
luaA_screen_get_managed(lua_State *L, screen_t *s)
16101610
{
16111611
if (s->lifecycle & SCREEN_LIFECYCLE_LUA)
1612-
lua_pushstring(L, "Lua");
1612+
lua_pushliteral(L, "Lua");
16131613
else if (s->lifecycle & SCREEN_LIFECYCLE_C)
1614-
lua_pushstring(L, "C");
1614+
lua_pushliteral(L, "C");
16151615
else
1616-
lua_pushstring(L, "none");
1616+
lua_pushliteral(L, "none");
16171617

16181618
return 1;
16191619
}

0 commit comments

Comments
 (0)