Skip to content

Commit a3d8151

Browse files
Code style adjustments.
1 parent c394eb0 commit a3d8151

File tree

1 file changed

+46
-29
lines changed

1 file changed

+46
-29
lines changed

source/luaKeyboard.cpp

Lines changed: 46 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,27 +46,40 @@ static uint8_t RUNNING = SCE_COMMON_DIALOG_STATUS_RUNNING;
4646
static uint8_t CANCELED = 3;
4747
bool keyboardStarted = false;
4848

49-
static int lua_setup(lua_State *L){
49+
static int lua_setup(lua_State *L) {
5050
int argc = lua_gettop(L);
51-
#ifndef SKIP_ERROR_HANDLING
52-
if (argc != 2 && argc != 3 && argc != 4 && argc != 5 && argc != 6) return luaL_error(L, "wrong number of arguments");
53-
#endif
51+
#ifndef SKIP_ERROR_HANDLING
52+
if (argc < 2 || argc > 6)
53+
return luaL_error(L, "wrong number of arguments");
54+
#endif
5455
char* title_ascii = (char*)luaL_checkstring(L, 1);
5556
char* text = (char*)luaL_checkstring(L, 2);
5657
SceUInt32 length = SCE_IME_DIALOG_MAX_TEXT_LENGTH;
5758
SceUInt32 type = SCE_IME_TYPE_BASIC_LATIN;
5859
SceUInt32 mode = SCE_IME_DIALOG_TEXTBOX_MODE_DEFAULT;
5960
SceUInt32 option = 0;
60-
if (argc >= 3) length = luaL_checkinteger(L, 3);
61-
if (argc >= 4) type = luaL_checkinteger(L, 4);
62-
if (argc >= 5) mode = luaL_checkinteger(L, 5);
63-
if (argc == 6) option = luaL_checkinteger(L, 6);
64-
#ifndef SKIP_ERROR_HANDLING
65-
if (length > SCE_IME_DIALOG_MAX_TEXT_LENGTH) length = SCE_IME_DIALOG_MAX_TEXT_LENGTH;
66-
if (type > 3) return luaL_error(L, "invalid keyboard type");
67-
if (mode > 1) return luaL_error(L, "invalid keyboard mode");
68-
if (strlen(title_ascii) > SCE_IME_DIALOG_MAX_TITLE_LENGTH) return luaL_error(L, "title is too long");
69-
#endif
61+
switch (argc) {
62+
case 6:
63+
option = luaL_checkinteger(L, 6);
64+
case 5:
65+
mode = luaL_checkinteger(L, 5);
66+
case 4:
67+
type = luaL_checkinteger(L, 4);
68+
case 3:
69+
length = luaL_checkinteger(L, 3);
70+
default:
71+
break;
72+
}
73+
#ifndef SKIP_ERROR_HANDLING
74+
if (length > SCE_IME_DIALOG_MAX_TEXT_LENGTH)
75+
length = SCE_IME_DIALOG_MAX_TEXT_LENGTH;
76+
if (type > 3)
77+
return luaL_error(L, "invalid keyboard type");
78+
if (mode > 1)
79+
return luaL_error(L, "invalid keyboard mode");
80+
if (strlen(title_ascii) > SCE_IME_DIALOG_MAX_TITLE_LENGTH)
81+
return luaL_error(L, "title is too long");
82+
#endif
7083

7184
// Converting input to UTF16
7285
ascii2utf(initial_text, text);
@@ -83,20 +96,22 @@ static int lua_setup(lua_State *L){
8396
param.maxTextLength = length;
8497
param.initialText = initial_text;
8598
param.inputTextBuffer = input_text;
86-
if (option > 0) param.option = option;
99+
if (option > 0)
100+
param.option = option;
87101
sceImeDialogInit(&param);
88102
keyboardStarted = true;
89103

90104
return 0;
91105
}
92106

93-
static int lua_state(lua_State *L){
107+
static int lua_state(lua_State *L) {
94108
int argc = lua_gettop(L);
95-
#ifndef SKIP_ERROR_HANDLING
96-
if (argc != 0) return luaL_error(L, "wrong number of arguments");
97-
#endif
109+
#ifndef SKIP_ERROR_HANDLING
110+
if (argc != 0)
111+
return luaL_error(L, "wrong number of arguments");
112+
#endif
98113
SceCommonDialogStatus status = sceImeDialogGetStatus();
99-
if (status == SCE_COMMON_DIALOG_STATUS_FINISHED){
114+
if (status == SCE_COMMON_DIALOG_STATUS_FINISHED) {
100115
SceImeDialogResult result;
101116
memset(&result, 0, sizeof(SceImeDialogResult));
102117
sceImeDialogGetResult(&result);
@@ -108,22 +123,24 @@ static int lua_state(lua_State *L){
108123
return 1;
109124
}
110125

111-
static int lua_input(lua_State *L){
126+
static int lua_input(lua_State *L) {
112127
int argc = lua_gettop(L);
113-
#ifndef SKIP_ERROR_HANDLING
114-
if (argc != 0) return luaL_error(L, "wrong number of arguments");
115-
#endif
116-
char res[SCE_IME_DIALOG_MAX_TEXT_LENGTH+1];
128+
#ifndef SKIP_ERROR_HANDLING
129+
if (argc != 0)
130+
return luaL_error(L, "wrong number of arguments");
131+
#endif
132+
char res[SCE_IME_DIALOG_MAX_TEXT_LENGTH + 1];
117133
utf2ascii(res, input_text);
118134
lua_pushstring(L, res);
119135
return 1;
120136
}
121137

122-
static int lua_clear(lua_State *L){
138+
static int lua_clear(lua_State *L) {
123139
int argc = lua_gettop(L);
124-
#ifndef SKIP_ERROR_HANDLING
125-
if (argc != 0) return luaL_error(L, "wrong number of arguments");
126-
#endif
140+
#ifndef SKIP_ERROR_HANDLING
141+
if (argc != 0)
142+
return luaL_error(L, "wrong number of arguments");
143+
#endif
127144
keyboardStarted = false;
128145
sceImeDialogTerm();
129146
return 0;

0 commit comments

Comments
 (0)