From 9edaf7a47b02bd351c400f0c6aec517884449551 Mon Sep 17 00:00:00 2001 From: jussi Date: Mon, 20 May 2024 15:45:31 +0300 Subject: Use GetApplicationDirectory instead of GetWorkingDirectory for basePath if no path argument given. --- src/core.c | 2 +- src/gl.c | 4 ++-- src/lua_core.c | 4 ++-- src/main.c | 13 +++++++------ src/state.c | 8 ++++---- 5 files changed, 16 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/core.c b/src/core.c index a687b2a..2146510 100644 --- a/src/core.c +++ b/src/core.c @@ -1591,7 +1591,7 @@ Return game directory (where main.lua is located) - Success return string */ int lcoreGetBasePath( lua_State* L ) { - lua_pushstring( L, state->exePath ); + lua_pushstring( L, state->basePath ); return 1; } diff --git a/src/gl.c b/src/gl.c index 31c5293..ec27d3b 100644 --- a/src/gl.c +++ b/src/gl.c @@ -32,7 +32,7 @@ Copy a block of pixels from one framebuffer object to another. Use nil RenderTexture for window framebuffer */ int lglBlitFramebuffer( lua_State* L ) { -// #if defined( PLATFORM_DESKTOP ) || defined( PLATFORM_DESKTOP_SDL ) +#if defined( PLATFORM_DESKTOP ) || defined( PLATFORM_DESKTOP_SDL ) if ( !( lua_isuserdata( L, 1 ) || lua_isnil( L, 1 ) ) || !( lua_isuserdata( L, 2 ) || lua_isnil( L, 2 ) ) ) { TraceLog( state->logLevelInvalid, "%s", "Argument needs to be RenderTexture or nil" ); lua_pushnil( L ); @@ -70,7 +70,7 @@ int lglBlitFramebuffer( lua_State* L ) { glBindFramebuffer( GL_DRAW_FRAMEBUFFER, 0 ); return 1; -// #endif +#endif } /* diff --git a/src/lua_core.c b/src/lua_core.c index 633cb8b..6d89777 100644 --- a/src/lua_core.c +++ b/src/lua_core.c @@ -1160,10 +1160,10 @@ bool luaCallMain() { snprintf( path, STRING_LEN, "main" ); } #else - snprintf( path, STRING_LEN, "%smain.lua", state->exePath ); + snprintf( path, STRING_LEN, "%smain.lua", state->basePath ); /* Alternatively look for main. Could be precompiled binary file. */ if ( !FileExists( path ) ) { - snprintf( path, STRING_LEN, "%smain", state->exePath ); + snprintf( path, STRING_LEN, "%smain", state->basePath ); } #endif luaL_dofile( L, path ); diff --git a/src/main.c b/src/main.c index 1dcac9c..95184cf 100644 --- a/src/main.c +++ b/src/main.c @@ -20,7 +20,7 @@ inline static void printVersion() { } int main( int argn, const char** argc ) { - char exePath[ STRING_LEN ] = { '\0' }; + char basePath[ STRING_LEN ] = { '\0' }; bool interpret_mode = false; if ( 1 < argn ) { @@ -36,15 +36,16 @@ int main( int argn, const char** argc ) { interpret_mode = true; if ( 2 < argn ) { - sprintf( exePath, "%s/%s", GetWorkingDirectory(), argc[2] ); + sprintf( basePath, "%s/%s", GetWorkingDirectory(), argc[2] ); } } else{ - sprintf( exePath, "%s/%s", GetWorkingDirectory(), argc[1] ); + sprintf( basePath, "%s/%s", GetWorkingDirectory(), argc[1] ); } } + /* If no argument given, assume main.lua is in exe directory. */ else { - sprintf( exePath, "%s/", GetWorkingDirectory() ); + sprintf( basePath, "%s", GetApplicationDirectory() ); } if ( interpret_mode ) { @@ -54,7 +55,7 @@ int main( int argn, const char** argc ) { lua_pushcfunction( L, luaTraceback ); int tracebackidx = lua_gettop( L ); - luaL_loadfile( L, exePath ); + luaL_loadfile( L, basePath ); if ( lua_pcall( L, 0, 0, tracebackidx ) != 0 ) { TraceLog( LOG_ERROR, "Lua error: %s", lua_tostring( L, -1 ) ); @@ -63,7 +64,7 @@ int main( int argn, const char** argc ) { } else { printVersion(); - stateInit( argn, argc, exePath ); + stateInit( argn, argc, basePath ); state->run = luaCallMain(); while ( state->run ) { diff --git a/src/state.c b/src/state.c index ea737d4..52742e5 100644 --- a/src/state.c +++ b/src/state.c @@ -6,11 +6,11 @@ State* state; -bool stateInit( int argn, const char** argc, const char* exePath ) { +bool stateInit( int argn, const char** argc, const char* basePath ) { state = malloc( sizeof( State ) ); - state->exePath = malloc( STRING_LEN * sizeof( char ) ); - strncpy( state->exePath, exePath, STRING_LEN - 1 ); + state->basePath = malloc( STRING_LEN * sizeof( char ) ); + strncpy( state->basePath, basePath, STRING_LEN - 1 ); state->hasWindow = true; state->run = true; @@ -65,7 +65,7 @@ void stateFree() { #ifdef PLATFORM_DESKTOP_SDL free( state->SDL_eventQueue ); #endif - free( state->exePath ); + free( state->basePath ); free( state->RLGLcurrentShaderLocs ); free( state ); } -- cgit v1.2.3