@@ -46,27 +46,40 @@ static uint8_t RUNNING = SCE_COMMON_DIALOG_STATUS_RUNNING;
46
46
static uint8_t CANCELED = 3 ;
47
47
bool keyboardStarted = false ;
48
48
49
- static int lua_setup (lua_State *L){
49
+ static int lua_setup (lua_State *L) {
50
50
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
54
55
char * title_ascii = (char *)luaL_checkstring (L, 1 );
55
56
char * text = (char *)luaL_checkstring (L, 2 );
56
57
SceUInt32 length = SCE_IME_DIALOG_MAX_TEXT_LENGTH;
57
58
SceUInt32 type = SCE_IME_TYPE_BASIC_LATIN;
58
59
SceUInt32 mode = SCE_IME_DIALOG_TEXTBOX_MODE_DEFAULT;
59
60
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
70
83
71
84
// Converting input to UTF16
72
85
ascii2utf (initial_text, text);
@@ -83,20 +96,22 @@ static int lua_setup(lua_State *L){
83
96
param.maxTextLength = length;
84
97
param.initialText = initial_text;
85
98
param.inputTextBuffer = input_text;
86
- if (option > 0 ) param.option = option;
99
+ if (option > 0 )
100
+ param.option = option;
87
101
sceImeDialogInit (¶m);
88
102
keyboardStarted = true ;
89
103
90
104
return 0 ;
91
105
}
92
106
93
- static int lua_state (lua_State *L){
107
+ static int lua_state (lua_State *L) {
94
108
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
98
113
SceCommonDialogStatus status = sceImeDialogGetStatus ();
99
- if (status == SCE_COMMON_DIALOG_STATUS_FINISHED){
114
+ if (status == SCE_COMMON_DIALOG_STATUS_FINISHED) {
100
115
SceImeDialogResult result;
101
116
memset (&result, 0 , sizeof (SceImeDialogResult));
102
117
sceImeDialogGetResult (&result);
@@ -108,22 +123,24 @@ static int lua_state(lua_State *L){
108
123
return 1 ;
109
124
}
110
125
111
- static int lua_input (lua_State *L){
126
+ static int lua_input (lua_State *L) {
112
127
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 ];
117
133
utf2ascii (res, input_text);
118
134
lua_pushstring (L, res);
119
135
return 1 ;
120
136
}
121
137
122
- static int lua_clear (lua_State *L){
138
+ static int lua_clear (lua_State *L) {
123
139
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
127
144
keyboardStarted = false ;
128
145
sceImeDialogTerm ();
129
146
return 0 ;
0 commit comments