Use GetApplicationDirectory instead of GetWorkingDirectory for basePath if no path argument given.
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
4
src/gl.c
4
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
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -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 );
|
||||
|
||||
13
src/main.c
13
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 ) {
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user