@@ -103,7 +103,7 @@ int premake_luaL_loadfilex (lua_State* L, const char* filename, const char* mode
103103 * script chunk on the stack. Turn these into a closure that will call my
104104 * wrapper below when the loaded script needs to be executed. */
105105
106- assert (lua_gettop (L ) == bottom + 2 );
106+ assert (lua_gettop (L ) == bottom + ( z == OKAY ? 2 : 0 ) );
107107
108108 if (z == OKAY ) {
109109 /* if we are called with an env, then our caller, luaB_loadfile, will
@@ -149,7 +149,7 @@ static int chunk_wrapper(lua_State* L)
149149 /* Remember the current _SCRIPT and working directory so I can
150150 * restore them after this new chunk has been run. */
151151
152- do_getcwd (cwd , PATH_MAX );
152+ do_getcwd (cwd , sizeof ( cwd ) / sizeof ( cwd [ 0 ]) );
153153 lua_getglobal (L , "_SCRIPT" );
154154 lua_getglobal (L , "_SCRIPT_DIR" );
155155
@@ -265,11 +265,19 @@ int premake_luaB_dofile(lua_State *L)
265265 /**
266266 * Copy of readable from loadlib.c in Lua source
267267 */
268- static int readable (const char * filename ) {
269- FILE * f = fopen (filename , "r" ); /* try to open file */
270- if (f == NULL ) return 0 ; /* open failed */
271- fclose (f );
272- return 1 ;
268+ static int readable (lua_State * L , const char * filename ) {
269+ #if PLATFORM_WINDOWS
270+ const wchar_t * wfilename = luaL_convertstring (L , filename );
271+ if (wfilename == NULL ) return 0 ; /* conversion failed */
272+ FILE * f = _wfopen (wfilename , L"r" );
273+ lua_pop (L , 1 );
274+ #else
275+ (void )(L );
276+ FILE * f = fopen (filename , "r" );
277+ #endif
278+ if (f == NULL ) return 0 ; /* open failed */
279+ fclose (f );
280+ return 1 ;
273281}
274282
275283
@@ -302,7 +310,7 @@ static const char *searchpath(lua_State *L, const char *name,
302310 const char * filename = luaL_gsub (L , lua_tostring (L , -1 ),
303311 LUA_PATH_MARK , name );
304312 lua_remove (L , -2 ); /* remove path template */
305- if (readable (filename )) /* does file exist and is readable? */
313+ if (readable (L , filename )) /* does file exist and is readable? */
306314 return filename ; /* return that file name */
307315 lua_pushfstring (L , "\n\tno file '%s'" , filename );
308316 lua_remove (L , -2 ); /* remove file name */
0 commit comments