Android lua module

Currently provides only a lovr.android.getApplicationId(). This returns an Android-specific identifier that doesn't cleanly map to anything specific in other OSes.
This commit is contained in:
mcc 2018-11-22 20:09:33 -05:00 committed by Bjorn Swenson
parent 8e8091ccbc
commit 961bf859f6
5 changed files with 39 additions and 1 deletions

View File

@ -73,6 +73,8 @@ elseif(ANDROID)
set(LOVR_USE_LUAJIT OFF) # Until buildvm re-invoke works
set(LOVR_USE_SSE OFF) # Assume ARM. Technically wrong on Android X86?
set(LOVR_BUILD_SHARED ON) # Android has only "activities"
option(LOVR_ENABLE_ANDROID "Enable the Android module" ON)
elseif(UNIX)
if(APPLE)
set(CMAKE_MACOSX_RPATH 1)
@ -569,7 +571,7 @@ elseif(EMSCRIPTEN)
target_sources(lovr PRIVATE src/platform/web.c)
elseif(ANDROID)
target_link_libraries(lovr log EGL GLESv3)
target_sources(lovr PRIVATE src/platform/android.c)
target_sources(lovr PRIVATE src/platform/android.c src/api/android.c)
elseif(UNIX)
target_sources(lovr PRIVATE src/platform/linux.c)
endif()

View File

@ -8,6 +8,7 @@
// Module loaders
LOVR_API int luaopen_lovr(lua_State* L);
LOVR_API int luaopen_lovr_android(lua_State* L);
LOVR_API int luaopen_lovr_audio(lua_State* L);
LOVR_API int luaopen_lovr_data(lua_State* L);
LOVR_API int luaopen_lovr_event(lua_State* L);

31
src/api/android.c Normal file
View File

@ -0,0 +1,31 @@
#include "api.h"
#include "sds.h"
static int l_lovrGetApplicationId(lua_State *L) {
pid_t pid = getpid();
sds procPath = sdscatfmt(sdsempty(), "/proc/%d/cmdline", (int)pid);
FILE *procFile = fopen(procPath, "r");
sdsfree(procPath);
if (procFile) {
sds procData = sdsempty();
char data[64];
int read;
while (read = fread(data, sizeof(data), 1, procFile)) {
procData = sdscatlen(procData, data, read);
}
sdsfree(procData);
} else {
lua_pushnil(L);
}
return 1;
}
static const luaL_Reg lovrAndroid[] = {
{ "getApplicationId", l_lovrGetApplicationId },
}
LOVR_API int luaopen_lovr_android(lua_State* L) {
lua_newtable(L);
luaL_register(L, NULL, lovrAndroid);
return 1;
}

View File

@ -6,6 +6,9 @@
const luaL_Reg lovrModules[] = {
{ "lovr", luaopen_lovr },
#ifdef LOVR_ENABLE_ANDROID
{ "lovr.android", luaopen_lovr_android },
#endif
#ifdef LOVR_ENABLE_AUDIO
{ "lovr.audio", luaopen_lovr_audio },
#endif

View File

@ -50,6 +50,7 @@ end
function lovr.boot()
local conf = {
modules = {
android = true,
audio = true,
data = true,
event = true,