@@ -81,34 +81,56 @@ int icelua_fn_common_mk_compat_disable(lua_State *L)
81
81
return 0 ;
82
82
}
83
83
#ifndef DEDI
84
+ static void update_lua_args (lua_State * L )
85
+ {
86
+ int top = lua_gettop (L );
87
+
88
+ if (lua_args ) {
89
+ for (int i = 0 ; i < lua_args_len ; ++ i ) {
90
+ free (lua_args [i ]);
91
+ }
92
+
93
+ free (lua_args );
94
+ lua_args = NULL ;
95
+ }
96
+
97
+ if (top > 2 ) {
98
+ lua_args = malloc (sizeof (* lua_args ) * (top - 3 ));
99
+
100
+ for (int i = 3 ; i <= top ; i ++ ) {
101
+ lua_args [i - 3 ] = strdup (lua_tostring (L , i ));
102
+ }
103
+ }
104
+ }
105
+
84
106
int icelua_fn_client_join_server (lua_State * L )
85
107
{
86
108
if (!(boot_mode & IB_LAUNCHER ))
87
109
return luaL_error (L , "join_server called when not in -l mode" );
88
110
89
- int top = lua_gettop (L );
111
+ update_lua_args (L );
90
112
91
- const char * address = lua_tostring (L , -2 );
92
- int port = lua_tonumber (L , -1 );
113
+ const char * address = lua_tostring (L , 1 );
114
+ int port = lua_tonumber (L , 2 );
93
115
94
116
ib_join_server (address , port );
95
117
96
- return 2 ;
118
+ return 0 ;
97
119
}
98
120
99
121
int icelua_fn_client_create_server (lua_State * L )
100
122
{
101
123
if (!(boot_mode & IB_LAUNCHER ))
102
124
return luaL_error (L , "create_server called when not in -l mode" );
103
125
104
- int top = lua_gettop (L );
126
+ update_lua_args (L );
105
127
106
- int port = lua_tonumber (L , -2 );
107
- const char * pkg = lua_tostring (L , -1 );
128
+ int port = lua_tonumber (L , 1 );
129
+ const char * pkg = lua_tostring (L , 2 );
108
130
109
131
ib_create_server (port , pkg );
110
132
111
- return 2 ;
133
+ return 0 ;
112
134
}
113
135
114
136
int icelua_fn_client_create_launcher (lua_State * L )
@@ -118,95 +140,10 @@ int icelua_fn_client_create_launcher(lua_State *L)
118
140
119
141
int top = lua_gettop (L );
120
142
121
- int port = lua_tonumber (L , -2 );
122
143
const char * pkg = lua_tostring (L , -1 );
123
144
124
- ib_create_launcher (port , pkg );
145
+ ib_create_launcher (pkg );
125
146
126
- return 2 ;
127
- }
128
-
129
- int icelua_fn_client_mk_sys_execv (lua_State * L )
130
- {
131
- if (!(boot_mode & IB_LAUNCHER ))
132
- return luaL_error (L , "mk_sys_execv called when not in -l mode" );
133
-
134
- int top = lua_gettop (L );
135
- char * * arglist = malloc (sizeof (char * ) * (top + 2 ));
136
- int i ;
137
-
138
- for (i = 1 ; i <= top ; i ++ )
139
- arglist [i ] = strdup (lua_tostring (L , i ));
140
-
141
- arglist [0 ] = strdup (main_argv0 );
142
- arglist [top + 1 ] = NULL ;
143
-
144
- SDL_Quit ();
145
- #ifdef WIN32
146
- #if 1
147
- //if(main_oldcwd != NULL)
148
- // _chdir(main_oldcwd);
149
-
150
- char cwd [2048 ] = "" ;
151
- GetModuleFileName (NULL , cwd , 2047 );
152
- char * v = cwd + strlen (cwd ) - 1 ;
153
- while (v >= cwd )
154
- {
155
- if (* v == '\\' )
156
- {
157
- v ++ ;
158
- break ;
159
- }
160
- v -- ;
161
- }
162
- arglist [0 ] = v ;
163
-
164
- for (i = 0 ; i <= top ; i ++ )
165
- {
166
- int new_size = strlen (arglist [i ]) + 3 ;
167
- int j ;
168
- for (j = 0 ; j < strlen (arglist [i ]); j ++ )
169
- {
170
- if (arglist [i ][j ] == '"' || arglist [i ][j ] == '\\' )
171
- new_size ++ ;
172
- }
173
- char * new_arg = malloc (new_size );
174
- char * k = new_arg ;
175
- char * l = arglist [i ];
176
- * (k ++ ) = '"' ;
177
- while (* l != 0 )
178
- {
179
- if (* l == '"' || * l == '\\' )
180
- * (k ++ ) = '\\' ;
181
- * (k ++ ) = * (l ++ );
182
- }
183
- * (k ++ ) = '"' ;
184
- * (k ++ ) = 0 ;
185
- arglist [i ] = new_arg ;
186
- }
187
- /*FILE *fp = fopen("FUCK.txt", "w");
188
- for (i = 0; i <= top; i++)
189
- {
190
- fprintf(fp, "%s ", arglist[i]);
191
- fflush(fp);
192
- }*/
193
- #else
194
- char * v = strdup ("iceball.exe" );
195
- arglist [0 ] = v ;
196
- #endif
197
- #endif
198
- printf ("argv0: [%s]\n" , main_argv0 );
199
- fflush (stdout );
200
-
201
- execv (main_argv0 , arglist );
202
-
203
- printf ("WORK YOU FUCKASS: %s\n" , strerror (errno ));
204
- fflush (stdout );
205
-
206
- // DOES NOT RETURN.
207
- fprintf (stderr , "ABORT: sys_execv must not return!\n" );
208
- fflush (stderr );
209
- abort ();
210
147
return 0 ;
211
148
}
212
149
@@ -257,7 +194,6 @@ struct icelua_entry icelua_client[] = {
257
194
{icelua_fn_client_create_server , "create_server" },
258
195
{icelua_fn_client_join_server , "join_server" },
259
196
{icelua_fn_client_mk_set_title , "mk_set_title" },
260
- {icelua_fn_client_mk_sys_execv , "mk_sys_execv" },
261
197
262
198
{icelua_fn_client_text_input_start , "text_input_start" },
263
199
{icelua_fn_client_text_input_stop , "text_input_stop" },
@@ -450,11 +386,7 @@ void icelua_loadbasefuncs(lua_State *L)
450
386
451
387
int icelua_initfetch (void )
452
388
{
453
- int i ;
454
389
char xpath [128 + 1 ];
455
- int argct = (main_largstart == -1 || (main_largstart >= main_argc )
456
- ? 0
457
- : main_argc - main_largstart );
458
390
459
391
if (to_client_local .sockfd == -1 )
460
392
to_client_local .sockfd = SOCKFD_LOCAL ;
@@ -487,9 +419,11 @@ int icelua_initfetch(void)
487
419
}
488
420
489
421
printf ("Client loaded! Initialising...\n" );
490
- for (i = 0 ; i < argct ; i ++ )
491
- lua_pushstring (lstate_client , main_argv [i + main_largstart ]);
492
- if ((boot_mode & IB_CLIENT ) && (net_path && net_path [1 ] != '\x00' ))
422
+ for (int i = 0 ; i < lua_args_len ; i ++ )
423
+ lua_pushstring (lstate_client , lua_args [i ]);
424
+
425
+ int argct = lua_args_len ;
426
+ if ((boot_mode & IB_CLIENT ) && net_path [1 ] != '\x00' )
493
427
{
494
428
lua_pushstring (lstate_client , net_path );
495
429
argct ++ ;
@@ -554,8 +488,6 @@ void icelua_pushversion(lua_State *L, const char *tabname)
554
488
555
489
int icelua_init (void )
556
490
{
557
- int i , argct ;
558
-
559
491
// create states
560
492
if (boot_mode & IB_CLIENT )
561
493
{
@@ -729,7 +661,7 @@ int icelua_init(void)
729
661
raw_whitelist = malloc (sizeof (struct icelua_whitelist )* raw_whitelist_len );
730
662
731
663
// read each entry
732
- for (i = 0 ; i < raw_whitelist_len ; i ++ )
664
+ for (int i = 0 ; i < raw_whitelist_len ; i ++ )
733
665
{
734
666
printf ("entry %i/%i\n" , i + 1 , raw_whitelist_len );
735
667
// get entry
@@ -866,15 +798,12 @@ int icelua_init(void)
866
798
return 1 ;
867
799
}
868
800
869
- argct = (main_largstart == -1 || (main_largstart >= main_argc )
870
- ? 0
871
- : main_argc - main_largstart );
872
-
873
801
if (lstate_server != NULL )
874
802
{
875
- for (i = 0 ; i < argct ; i ++ )
876
- lua_pushstring (lstate_server , main_argv [i + main_largstart ]);
877
- if (lua_pcall (lstate_server , argct , 0 , 0 ) != 0 )
803
+ for (int i = 0 ; i < lua_args_len ; i ++ )
804
+ lua_pushstring (lstate_server , lua_args [i ]);
805
+
806
+ if (lua_pcall (lstate_server , lua_args_len , 0 , 0 ) != 0 )
878
807
{
879
808
printf ("ERROR running server Lua: %s\n" , lua_tostring (lstate_server , -1 ));
880
809
lua_pop (lstate_server , 1 );
0 commit comments