Add lime.system.CFFIPointer
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
#include <graphics/ImageBuffer.h>
|
||||
#include <graphics/Renderer.h>
|
||||
#include <graphics/RenderEvent.h>
|
||||
#include <system/CFFIPointer.h>
|
||||
#include <system/Clipboard.h>
|
||||
#include <system/JNI.h>
|
||||
#include <system/SensorEvent.h>
|
||||
@@ -94,9 +95,7 @@ namespace lime {
|
||||
|
||||
Application* application = CreateApplication ();
|
||||
Application::callback = new AutoGCRoot (callback);
|
||||
value handle = cffi::alloc_pointer (application);
|
||||
val_gc (handle, gc_application);
|
||||
return handle;
|
||||
return CFFIPointer (application, gc_application);
|
||||
|
||||
}
|
||||
|
||||
@@ -216,6 +215,13 @@ namespace lime {
|
||||
}
|
||||
|
||||
|
||||
double lime_cffi_get_native_pointer (value handle) {
|
||||
|
||||
return (intptr_t)val_data (handle);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void lime_cffi_finalizer (value abstract) {
|
||||
|
||||
val_call0 ((value)val_data (abstract));
|
||||
@@ -457,9 +463,7 @@ namespace lime {
|
||||
|
||||
if (font->face) {
|
||||
|
||||
value handle = cffi::alloc_pointer (font);
|
||||
val_gc (handle, gc_font);
|
||||
return handle;
|
||||
return CFFIPointer (font, gc_font);
|
||||
|
||||
} else {
|
||||
|
||||
@@ -966,9 +970,7 @@ namespace lime {
|
||||
value lime_renderer_create (value window) {
|
||||
|
||||
Renderer* renderer = CreateRenderer ((Window*)val_data (window));
|
||||
value handle = cffi::alloc_pointer (renderer);
|
||||
val_gc (handle, gc_renderer);
|
||||
return handle;
|
||||
return CFFIPointer (renderer, gc_renderer);
|
||||
|
||||
}
|
||||
|
||||
@@ -1068,9 +1070,7 @@ namespace lime {
|
||||
#if defined(LIME_FREETYPE) && defined(LIME_HARFBUZZ)
|
||||
|
||||
TextLayout *text = new TextLayout (direction, script.__s, language.__s);
|
||||
value handle = cffi::alloc_pointer (text);
|
||||
val_gc (handle, gc_text_layout);
|
||||
return handle;
|
||||
return CFFIPointer (text, gc_text_layout);
|
||||
|
||||
#else
|
||||
|
||||
@@ -1155,9 +1155,7 @@ namespace lime {
|
||||
value lime_window_create (value application, int width, int height, int flags, HxString title) {
|
||||
|
||||
Window* window = CreateWindow ((Application*)val_data (application), width, height, flags, title.__s);
|
||||
value handle = cffi::alloc_pointer (window);
|
||||
val_gc (handle, gc_window);
|
||||
return handle;
|
||||
return CFFIPointer (window, gc_window);
|
||||
|
||||
}
|
||||
|
||||
@@ -1295,6 +1293,7 @@ namespace lime {
|
||||
DEFINE_PRIME2 (lime_bytes_from_data_pointer);
|
||||
DEFINE_PRIME1 (lime_bytes_get_data_pointer);
|
||||
DEFINE_PRIME1 (lime_bytes_read_file);
|
||||
DEFINE_PRIME1 (lime_cffi_get_native_pointer);
|
||||
DEFINE_PRIME1 (lime_cffi_set_finalizer);
|
||||
DEFINE_PRIME0 (lime_clipboard_get_text);
|
||||
DEFINE_PRIME1v (lime_clipboard_set_text);
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#endif
|
||||
|
||||
#include <hx/CFFIPrime.h>
|
||||
#include <system/CFFIPointer.h>
|
||||
#include <utils/Bytes.h>
|
||||
|
||||
|
||||
@@ -890,16 +891,7 @@ namespace lime {
|
||||
int* list = val_array_int (attrlist);
|
||||
|
||||
ALCcontext* alcContext = alcCreateContext (alcDevice, list);
|
||||
|
||||
if (alcContext) {
|
||||
|
||||
return cffi::alloc_pointer (alcContext);
|
||||
|
||||
} else {
|
||||
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
return CFFIPointer (alcContext);
|
||||
|
||||
}
|
||||
|
||||
@@ -916,16 +908,7 @@ namespace lime {
|
||||
|
||||
ALCcontext* alcContext = (ALCcontext*)val_data (context);
|
||||
ALCdevice* alcDevice = alcGetContextsDevice (alcContext);
|
||||
|
||||
if (alcDevice) {
|
||||
|
||||
return cffi::alloc_pointer (alcDevice);
|
||||
|
||||
} else {
|
||||
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
return CFFIPointer (alcDevice);
|
||||
|
||||
}
|
||||
|
||||
@@ -933,16 +916,7 @@ namespace lime {
|
||||
value lime_alc_get_current_context () {
|
||||
|
||||
ALCcontext* alcContext = alcGetCurrentContext ();
|
||||
|
||||
if (alcContext) {
|
||||
|
||||
return cffi::alloc_pointer (alcContext);
|
||||
|
||||
} else {
|
||||
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
return CFFIPointer (alcContext);
|
||||
|
||||
}
|
||||
|
||||
@@ -997,16 +971,7 @@ namespace lime {
|
||||
|
||||
ALCdevice* alcDevice = alcOpenDevice (devicename.__s);
|
||||
atexit (lime_al_cleanup);
|
||||
|
||||
if (alcDevice) {
|
||||
|
||||
return cffi::alloc_pointer (alcDevice);
|
||||
|
||||
} else {
|
||||
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
return CFFIPointer (alcDevice);
|
||||
|
||||
}
|
||||
|
||||
|
||||
30
project/src/system/CFFIPointer.cpp
Normal file
30
project/src/system/CFFIPointer.cpp
Normal file
@@ -0,0 +1,30 @@
|
||||
#include <system/CFFIPointer.h>
|
||||
|
||||
|
||||
namespace lime {
|
||||
|
||||
|
||||
value CFFIPointer (void* ptr, hx::finalizer finalizer) {
|
||||
|
||||
if (ptr) {
|
||||
|
||||
value handle = cffi::alloc_pointer (ptr);
|
||||
|
||||
if (finalizer) {
|
||||
|
||||
val_gc (handle, finalizer);
|
||||
|
||||
}
|
||||
|
||||
return handle;
|
||||
|
||||
} else {
|
||||
|
||||
return alloc_null ();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user