Skip to content

Commit a36886f

Browse files
committed
Move variable definition to the top
1 parent 75af8cc commit a36886f

File tree

1 file changed

+22
-10
lines changed

1 file changed

+22
-10
lines changed

src/util/line.c

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@
1414

1515
/* Check if line is incomplete */
1616
static bool incomplete(lua_State* L, int status) {
17+
size_t lmess;
18+
size_t eof_size;
19+
const char* mess;
20+
const char* mess_end;
21+
1722
bool result = false;
1823

1924
if(status == LUA_ERRSYNTAX) {
20-
size_t lmess;
21-
const char* mess = lua_tolstring(L, -1, &lmess);
25+
mess = lua_tolstring(L, -1, &lmess);
2226

2327
/* Check if the error ends in '<eof>' */
24-
size_t eof_size = sizeof(LUA_QL("<eof>")) - 1;
25-
const char* mess_end = mess + lmess - eof_size;
28+
eof_size = sizeof(LUA_QL("<eof>")) - 1;
29+
mess_end = mess + lmess - eof_size;
30+
2631
if(strstr(mess, LUA_QL("<eof>")) == mess_end) {
2732
lua_pop(L, 1);
2833
result = true;
@@ -34,30 +39,37 @@ static bool incomplete(lua_State* L, int status) {
3439

3540
/* Check if line can be printed */
3641
static bool is_printable(lua_State* L, int status) {
42+
const char* mess;
43+
const char* literal;
44+
const char* func;
45+
bool is_assignment;
46+
bool is_literal;
47+
bool is_variable;
48+
3749
bool result = false;
3850

3951
if(status == LUA_ERRSYNTAX) {
40-
const char* mess = lua_tostring(L, -1);
52+
mess = lua_tostring(L, -1);
4153

42-
bool is_literal = strstr(mess, "unexpected symbol") != NULL;
43-
bool is_variable = strstr(mess, "'=' expected") != NULL;
54+
is_literal = strstr(mess, "unexpected symbol") != NULL;
55+
is_variable = strstr(mess, "'=' expected") != NULL;
4456

4557
if(is_literal || is_variable) {
4658
/* pop off error message */
4759
lua_pop(L, 1);
4860

49-
const char* literal = lua_tostring(L, -1);
61+
literal = lua_tostring(L, -1);
5062
lua_pop(L, 1);
5163

5264
lua_pushfstring(L, "return %s", literal);
5365

5466
result = true;
5567
}
5668
} else if(lua_type(L, -1) == LUA_TFUNCTION) {
57-
const char* func = lua_tostring(L, -2);
69+
func = lua_tostring(L, -2);
5870

5971
/* check for a return statement */
60-
bool is_assignment = strstr(func, "=");
72+
is_assignment = strstr(func, "=");
6173

6274
if(!strstr(func, "return ") && !is_assignment) {
6375
lua_pop(L, 2);

0 commit comments

Comments
 (0)