mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-04 22:15:33 +02:00
use MiniFFI in Ruby >1.8
This commit is contained in:
parent
b10e806ba1
commit
079e878e12
3 changed files with 19 additions and 9 deletions
|
@ -38,6 +38,8 @@ DECL_TYPE(Viewport);
|
||||||
DECL_TYPE(Tilemap);
|
DECL_TYPE(Tilemap);
|
||||||
DECL_TYPE(Window);
|
DECL_TYPE(Window);
|
||||||
|
|
||||||
|
DECL_TYPE(MiniFFI);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
#define TableType "Table"
|
#define TableType "Table"
|
||||||
#define RectType "Rect"
|
#define RectType "Rect"
|
||||||
|
@ -51,6 +53,8 @@ DECL_TYPE(Window);
|
||||||
#define ViewportType "Viewport"
|
#define ViewportType "Viewport"
|
||||||
#define TilemapType "Tilemap"
|
#define TilemapType "Tilemap"
|
||||||
#define WindowType "Window"
|
#define WindowType "Window"
|
||||||
|
|
||||||
|
#define MiniFFIType "MiniFFI"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_DISCORDSDK
|
#ifdef HAVE_DISCORDSDK
|
||||||
|
|
|
@ -42,12 +42,9 @@ binding_source = [files(
|
||||||
'filesystem-binding.cpp',
|
'filesystem-binding.cpp',
|
||||||
'windowvx-binding.cpp',
|
'windowvx-binding.cpp',
|
||||||
'tilemapvx-binding.cpp',
|
'tilemapvx-binding.cpp',
|
||||||
|
'miniffi-binding.cpp'
|
||||||
)]
|
)]
|
||||||
|
|
||||||
if ver.version_compare('<=1.8') == true
|
|
||||||
binding_source += files('miniffi-binding.cpp')
|
|
||||||
endif
|
|
||||||
|
|
||||||
if discord == true
|
if discord == true
|
||||||
binding_source += files('discord-binding.cpp')
|
binding_source += files('discord-binding.cpp')
|
||||||
endif
|
endif
|
||||||
|
|
|
@ -36,6 +36,12 @@ typedef void* (*MINIFFI_FUNC)(unsigned long,unsigned long,unsigned long,unsigned
|
||||||
// MiniFFI class, also named Win32API on Windows
|
// MiniFFI class, also named Win32API on Windows
|
||||||
// Uses LoadLibrary/GetProcAddress on Windows, dlopen/dlsym everywhere else
|
// Uses LoadLibrary/GetProcAddress on Windows, dlopen/dlsym everywhere else
|
||||||
|
|
||||||
|
#ifndef OLD_RUBY
|
||||||
|
DEF_TYPE_CUSTOMFREE(MiniFFI, SDL_UnloadObject);
|
||||||
|
#else
|
||||||
|
DEF_ALLOCFUNC_CUSTOMFREE(MiniFFI, SDL_UnloadObject);
|
||||||
|
#endif
|
||||||
|
|
||||||
static VALUE
|
static VALUE
|
||||||
MiniFFI_alloc(VALUE self)
|
MiniFFI_alloc(VALUE self)
|
||||||
{
|
{
|
||||||
|
@ -91,7 +97,7 @@ RB_METHOD(MiniFFI_initialize)
|
||||||
SafeStringValue(libname);
|
SafeStringValue(libname);
|
||||||
SafeStringValue(func);
|
SafeStringValue(func);
|
||||||
void *hlib = SDL_LoadObject(RSTRING_PTR(libname));
|
void *hlib = SDL_LoadObject(RSTRING_PTR(libname));
|
||||||
DATA_PTR(self) = hlib;
|
setPrivateData(self, hlib);
|
||||||
void *hfunc = MiniFFI_GetFunctionHandle(hlib, RSTRING_PTR(func));
|
void *hfunc = MiniFFI_GetFunctionHandle(hlib, RSTRING_PTR(func));
|
||||||
#ifdef __WIN32__
|
#ifdef __WIN32__
|
||||||
if (hlib && !hfunc)
|
if (hlib && !hfunc)
|
||||||
|
@ -269,7 +275,7 @@ RB_METHOD(MiniFFI_call)
|
||||||
return ULONG2NUM(ret);
|
return ULONG2NUM(ret);
|
||||||
|
|
||||||
case _T_POINTER:
|
case _T_POINTER:
|
||||||
return rb_str_new2((char*)ret);
|
return rb_str_new_cstr((char*)ret);
|
||||||
|
|
||||||
case _T_BOOL:
|
case _T_BOOL:
|
||||||
return rb_bool_new(ret);
|
return rb_bool_new(ret);
|
||||||
|
@ -284,13 +290,16 @@ void
|
||||||
MiniFFIBindingInit()
|
MiniFFIBindingInit()
|
||||||
{
|
{
|
||||||
VALUE cMiniFFI = rb_define_class("MiniFFI", rb_cObject);
|
VALUE cMiniFFI = rb_define_class("MiniFFI", rb_cObject);
|
||||||
|
#ifndef OLD_RUBY
|
||||||
|
rb_define_alloc_func(cMiniFFI, classAllocate<&MiniFFIType>);
|
||||||
|
#else
|
||||||
rb_define_alloc_func(cMiniFFI, MiniFFI_alloc);
|
rb_define_alloc_func(cMiniFFI, MiniFFI_alloc);
|
||||||
|
#endif
|
||||||
_rb_define_method(cMiniFFI, "initialize", MiniFFI_initialize);
|
_rb_define_method(cMiniFFI, "initialize", MiniFFI_initialize);
|
||||||
_rb_define_method(cMiniFFI, "call", MiniFFI_call);
|
_rb_define_method(cMiniFFI, "call", MiniFFI_call);
|
||||||
rb_define_alias(cMiniFFI, "Call", "call");
|
rb_define_alias(cMiniFFI, "Call", "call");
|
||||||
|
|
||||||
// Preferably use MiniFFI, the name Win32API makes no sense
|
#if defined(__WIN32__) || defined(USE_FAKEAPI)
|
||||||
// on things that aren't Windows but I'm leaving it here
|
|
||||||
// for compatibility
|
|
||||||
rb_define_const(rb_cObject, "Win32API", cMiniFFI);
|
rb_define_const(rb_cObject, "Win32API", cMiniFFI);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue