Skip to content

Commit

Permalink
Allow overriding the main entry point on Android
Browse files Browse the repository at this point in the history
  • Loading branch information
slouken committed Aug 28, 2017
1 parent dbb0a2a commit 60182eb
Showing 1 changed file with 27 additions and 9 deletions.
36 changes: 27 additions & 9 deletions android-project/src/org/libsdl/app/SDLActivity.java
Expand Up @@ -73,6 +73,29 @@ public enum NativeState {
protected static AudioTrack mAudioTrack;
protected static AudioRecord mAudioRecord;

/**
* This method returns the name of the shared object with the application entry point
* It can be overridden by derived classes.
*/
protected String getMainSharedObject() {
String library;
String[] libraries = SDLActivity.mSingleton.getLibraries();
if (libraries.length > 0) {
library = "lib" + libraries[libraries.length - 1] + ".so";
} else {
library = "libmain.so";
}
return library;
}

/**
* This method returns the name of the application entry point
* It can be overridden by derived classes.
*/
protected String getMainFunction() {
return "SDL_main";
}

/**
* This method is called by SDL before loading the native shared libraries.
* It can be overridden to provide names of shared libraries to be loaded.
Expand Down Expand Up @@ -1218,17 +1241,12 @@ class SDLMain implements Runnable {
@Override
public void run() {
// Runs SDL_main()
String library;
String[] libraries = SDLActivity.mSingleton.getLibraries();
if (libraries.length > 0) {
library = "lib" + libraries[libraries.length - 1] + ".so";
} else {
library = "libmain.so";
}
String function = "SDL_main";
String library = SDLActivity.mSingleton.getMainSharedObject();
String function = SDLActivity.mSingleton.getMainFunction();
String[] arguments = SDLActivity.mSingleton.getArguments();

Log.v("SDL", "Running main function " + function + " from library " + library);
SDLActivity.nativeRunMain(library, function, SDLActivity.mSingleton.getArguments());
SDLActivity.nativeRunMain(library, function, arguments);

Log.v("SDL", "Finished main function");
}
Expand Down

0 comments on commit 60182eb

Please sign in to comment.