Skip to content

Commit a858212

Browse files
authored
Merge pull request #354 from cnjhb/literal
refactor: use lua_pushliteral instead of lua_pushstring
2 parents c9b8e44 + ecd706a commit a858212

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

lgi/core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ lgi_type_get_name (lua_State *L, GIBaseInfo *info)
139139
{
140140
if (g_base_info_get_type (i->data) != GI_INFO_TYPE_TYPE)
141141
{
142-
lua_pushstring (L, ".");
142+
lua_pushliteral (L, ".");
143143
lua_pushstring (L, g_base_info_get_name (i->data));
144144
n += 2;
145145
}
@@ -228,7 +228,7 @@ lgi_type_get_gtype (lua_State *L, int narg)
228228
{
229229
GType gtype;
230230
lgi_makeabs (L, narg);
231-
lua_pushstring (L, "_gtype");
231+
lua_pushliteral (L, "_gtype");
232232
lua_rawget (L, narg);
233233
gtype = lgi_type_get_gtype (L, -1);
234234
lua_pop (L, 1);

lgi/gi.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ info_push_transfer (lua_State *L, GITransfer transfer)
143143
#define H(n1, n2) \
144144
else if (transfer == GI_TRANSFER_ ## n1) \
145145
{ \
146-
lua_pushstring (L, #n2); \
146+
lua_pushliteral (L, #n2); \
147147
return 1; \
148148
}
149149
H(NOTHING, none)
@@ -177,7 +177,7 @@ info_index (lua_State *L)
177177
{
178178
#define H(n1, n2) \
179179
case GI_INFO_TYPE_ ## n1: \
180-
lua_pushstring (L, #n2); \
180+
lua_pushliteral (L, #n2); \
181181
return 1;
182182

183183
H(FUNCTION, function)
@@ -435,11 +435,20 @@ info_index (lua_State *L)
435435
if (strcmp (prop, "direction") == 0)
436436
{
437437
GIDirection dir = g_arg_info_get_direction (*info);
438-
if (dir == GI_DIRECTION_OUT)
439-
lua_pushstring (L, g_arg_info_is_caller_allocates (*info)
440-
? "out-caller-alloc" : "out");
441-
else
442-
lua_pushstring (L, dir == GI_DIRECTION_IN ? "in" : "inout");
438+
switch (dir) {
439+
case GI_DIRECTION_IN:
440+
lua_pushliteral(L, "in");
441+
break;
442+
case GI_DIRECTION_OUT:
443+
if (g_arg_info_is_caller_allocates(*info))
444+
lua_pushliteral(L, "out-caller-alloc");
445+
else
446+
lua_pushliteral(L, "out");
447+
break;
448+
case GI_DIRECTION_INOUT:
449+
lua_pushliteral(L, "inout");
450+
break;
451+
}
443452
return 1;
444453
}
445454
if (strcmp (prop, "transfer") == 0)
@@ -536,7 +545,7 @@ info_index (lua_State *L)
536545
{
537546
#define H(n1, n2) \
538547
case GI_ARRAY_TYPE_ ## n1: \
539-
lua_pushstring (L, #n2); \
548+
lua_pushliteral (L, #n2); \
540549
return 1;
541550

542551
H(C, c)

0 commit comments

Comments
 (0)