Add lime.utils.JNI, initially supporting JNI.getEnv

This commit is contained in:
Joshua Granick
2015-02-04 17:13:27 -08:00
parent 4dde860505
commit 7134baafef
5 changed files with 90 additions and 0 deletions

33
lime/utils/JNI.hx Normal file
View File

@@ -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
}

View File

@@ -135,6 +135,7 @@
<file name="src/backend/sdl/SDLRenderer.cpp" />
<file name="src/backend/sdl/SDLMouse.cpp" />
<file name="src/backend/sdl/SDLSystem.cpp" />
<file name="src/backend/sdl/SDLJNI.cpp" />
</section>

View File

@@ -0,0 +1,22 @@
#ifndef LIME_UTILS_JNI_H
#define LIME_UTILS_JNI_H
namespace lime {
class JNI {
public:
static void *GetEnv ();
};
}
#endif

View File

@@ -30,6 +30,7 @@
#include <ui/TouchEvent.h>
#include <ui/Window.h>
#include <ui/WindowEvent.h>
#include <utils/JNI.h>
#include <vm/NekoVM.h>
@@ -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);

View File

@@ -0,0 +1,21 @@
#ifdef ANDROID
#include <utils/JNI.h>
#include <SDL_system.h>
namespace lime {
void *JNI::GetEnv () {
return SDL_AndroidGetJNIEnv ();
}
}
#endif