From 7134baafef4e88be3cae8f8b5e8f2574f9cd638f Mon Sep 17 00:00:00 2001 From: Joshua Granick Date: Wed, 4 Feb 2015 17:13:27 -0800 Subject: [PATCH] Add lime.utils.JNI, initially supporting JNI.getEnv --- lime/utils/JNI.hx | 33 ++++++++++++++++++++++++++++++ project/Build.xml | 1 + project/include/utils/JNI.h | 22 ++++++++++++++++++++ project/src/ExternalInterface.cpp | 13 ++++++++++++ project/src/backend/sdl/SDLJNI.cpp | 21 +++++++++++++++++++ 5 files changed, 90 insertions(+) create mode 100644 lime/utils/JNI.hx create mode 100644 project/include/utils/JNI.h create mode 100644 project/src/backend/sdl/SDLJNI.cpp diff --git a/lime/utils/JNI.hx b/lime/utils/JNI.hx new file mode 100644 index 000000000..ec2aa92ba --- /dev/null +++ b/lime/utils/JNI.hx @@ -0,0 +1,33 @@ +package lime.utils; + + +import lime.system.System; + + +class JNI { + + + public static function getEnv ():Dynamic { + + #if android + return lime_jni_getenv (); + #else + return null; + #end + + } + + + + + // Native Methods + + + + + #if (cpp || neko || nodejs) + private static var lime_jni_getenv = System.load ("lime", "lime_jni_getenv", 0); + #end + + +} \ No newline at end of file diff --git a/project/Build.xml b/project/Build.xml index 105071579..1fcc98f55 100644 --- a/project/Build.xml +++ b/project/Build.xml @@ -135,6 +135,7 @@ + diff --git a/project/include/utils/JNI.h b/project/include/utils/JNI.h new file mode 100644 index 000000000..60a232108 --- /dev/null +++ b/project/include/utils/JNI.h @@ -0,0 +1,22 @@ +#ifndef LIME_UTILS_JNI_H +#define LIME_UTILS_JNI_H + + +namespace lime { + + + class JNI { + + + public: + + static void *GetEnv (); + + + }; + + +} + + +#endif \ No newline at end of file diff --git a/project/src/ExternalInterface.cpp b/project/src/ExternalInterface.cpp index 272cedf96..695d98b7e 100644 --- a/project/src/ExternalInterface.cpp +++ b/project/src/ExternalInterface.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include @@ -295,6 +296,17 @@ namespace lime { } + value lime_jni_getenv () { + + #ifdef ANDROID + return alloc_float ((intptr_t)JNI::GetEnv ()); + #else + return alloc_null (); + #endif + + } + + value lime_key_event_manager_register (value callback, value eventObject) { KeyEvent::callback = new AutoGCRoot (callback); @@ -531,6 +543,7 @@ namespace lime { DEFINE_PRIM (lime_font_outline_decompose, 2); DEFINE_PRIM (lime_image_encode, 3); DEFINE_PRIM (lime_image_load, 1); + DEFINE_PRIM (lime_jni_getenv, 0); DEFINE_PRIM (lime_key_event_manager_register, 2); DEFINE_PRIM (lime_lzma_encode, 1); DEFINE_PRIM (lime_lzma_decode, 1); diff --git a/project/src/backend/sdl/SDLJNI.cpp b/project/src/backend/sdl/SDLJNI.cpp new file mode 100644 index 000000000..aa18bd649 --- /dev/null +++ b/project/src/backend/sdl/SDLJNI.cpp @@ -0,0 +1,21 @@ +#ifdef ANDROID + + +#include +#include + + +namespace lime { + + + void *JNI::GetEnv () { + + return SDL_AndroidGetJNIEnv (); + + } + + +} + + +#endif \ No newline at end of file