mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-08-03 21:45:32 +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(Window);
|
||||
|
||||
DECL_TYPE(MiniFFI);
|
||||
|
||||
#else
|
||||
#define TableType "Table"
|
||||
#define RectType "Rect"
|
||||
|
@ -51,6 +53,8 @@ DECL_TYPE(Window);
|
|||
#define ViewportType "Viewport"
|
||||
#define TilemapType "Tilemap"
|
||||
#define WindowType "Window"
|
||||
|
||||
#define MiniFFIType "MiniFFI"
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_DISCORDSDK
|
||||
|
|
|
@ -42,12 +42,9 @@ binding_source = [files(
|
|||
'filesystem-binding.cpp',
|
||||
'windowvx-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
|
||||
binding_source += files('discord-binding.cpp')
|
||||
endif
|
||||
|
|
|
@ -36,6 +36,12 @@ typedef void* (*MINIFFI_FUNC)(unsigned long,unsigned long,unsigned long,unsigned
|
|||
// MiniFFI class, also named Win32API on Windows
|
||||
// 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
|
||||
MiniFFI_alloc(VALUE self)
|
||||
{
|
||||
|
@ -91,7 +97,7 @@ RB_METHOD(MiniFFI_initialize)
|
|||
SafeStringValue(libname);
|
||||
SafeStringValue(func);
|
||||
void *hlib = SDL_LoadObject(RSTRING_PTR(libname));
|
||||
DATA_PTR(self) = hlib;
|
||||
setPrivateData(self, hlib);
|
||||
void *hfunc = MiniFFI_GetFunctionHandle(hlib, RSTRING_PTR(func));
|
||||
#ifdef __WIN32__
|
||||
if (hlib && !hfunc)
|
||||
|
@ -269,7 +275,7 @@ RB_METHOD(MiniFFI_call)
|
|||
return ULONG2NUM(ret);
|
||||
|
||||
case _T_POINTER:
|
||||
return rb_str_new2((char*)ret);
|
||||
return rb_str_new_cstr((char*)ret);
|
||||
|
||||
case _T_BOOL:
|
||||
return rb_bool_new(ret);
|
||||
|
@ -284,13 +290,16 @@ void
|
|||
MiniFFIBindingInit()
|
||||
{
|
||||
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);
|
||||
#endif
|
||||
_rb_define_method(cMiniFFI, "initialize", MiniFFI_initialize);
|
||||
_rb_define_method(cMiniFFI, "call", MiniFFI_call);
|
||||
rb_define_alias(cMiniFFI, "Call", "call");
|
||||
|
||||
// Preferably use MiniFFI, the name Win32API makes no sense
|
||||
// on things that aren't Windows but I'm leaving it here
|
||||
// for compatibility
|
||||
#if defined(__WIN32__) || defined(USE_FAKEAPI)
|
||||
rb_define_const(rb_cObject, "Win32API", cMiniFFI);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue