mirror of
https://github.com/mkxp-z/mkxp-z.git
synced 2025-04-29 19:44:49 +02:00
Use SDL functions with MiniDL/Win32API
This commit is contained in:
parent
b2b14abf2a
commit
5d8da3ec5d
5 changed files with 20 additions and 59 deletions
|
@ -5,13 +5,13 @@ if ver.version_compare('>1.8') == true
|
|||
binding_dependencies += dependency('ruby-' + ver)
|
||||
else
|
||||
lib = get_option('ruby_lib')
|
||||
binding_dependencies += meson.get_compiler('cpp').find_library(lib)
|
||||
binding_dependencies += compiler.find_library(lib)
|
||||
if host_system == 'windows'
|
||||
if lib.endswith('-static')
|
||||
binding_dependencies += meson.get_compiler('cpp').find_library('wsock32')
|
||||
binding_dependencies += compiler.find_library('wsock32')
|
||||
endif
|
||||
else
|
||||
binding_dependencies += meson.get_compiler('cpp').find_library('dl')
|
||||
binding_dependencies += compiler.find_library('dl')
|
||||
endif
|
||||
add_project_arguments('-DOLD_RUBY', language: 'cpp')
|
||||
endif
|
||||
|
|
|
@ -2,20 +2,7 @@
|
|||
// it's just as basic but should work fine for the moment
|
||||
|
||||
#include <ruby/ruby.h>
|
||||
|
||||
#ifdef __WIN32__
|
||||
|
||||
#include <windows.h>
|
||||
#define LIBHANDLE HINSTANCE
|
||||
#define FUNCHANDLE HANDLE
|
||||
|
||||
#else
|
||||
|
||||
#include <dlfcn.h>
|
||||
#define LIBHANDLE void*
|
||||
#define FUNCHANDLE void*
|
||||
|
||||
#endif
|
||||
#include <SDL.h>
|
||||
|
||||
#define _T_VOID 0
|
||||
#define _T_NUMBER 1
|
||||
|
@ -24,44 +11,10 @@
|
|||
|
||||
typedef void* (*MINIDL_FUNC)(...);
|
||||
|
||||
static void
|
||||
dl_freelib(LIBHANDLE lib)
|
||||
{
|
||||
#ifdef __WIN32__
|
||||
FreeLibrary(lib);
|
||||
#else
|
||||
dlclose(lib);
|
||||
#endif
|
||||
}
|
||||
|
||||
static LIBHANDLE
|
||||
dl_loadlib(const char *filename)
|
||||
{
|
||||
LIBHANDLE ret;
|
||||
#ifdef __WIN32__
|
||||
ret = LoadLibrary(filename);
|
||||
#else
|
||||
ret = dlopen(filename, RTLD_NOW);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
static FUNCHANDLE
|
||||
dl_getfunc(LIBHANDLE lib, const char *filename)
|
||||
{
|
||||
FUNCHANDLE ret;
|
||||
#ifdef __WIN32__
|
||||
ret = (FUNCHANDLE)GetProcAddress(lib, filename);
|
||||
#else
|
||||
ret = dlsym(lib, filename);
|
||||
#endif
|
||||
return ret;
|
||||
}
|
||||
|
||||
static VALUE
|
||||
MiniDL_alloc(VALUE self)
|
||||
{
|
||||
return Data_Wrap_Struct(self, 0, dl_freelib, 0);
|
||||
return Data_Wrap_Struct(self, 0, SDL_UnloadObject, 0);
|
||||
}
|
||||
|
||||
static VALUE
|
||||
|
@ -71,22 +24,22 @@ MiniDL_initialize(VALUE self, VALUE libname, VALUE func, VALUE imports, VALUE ex
|
|||
SafeStringValue(func);
|
||||
|
||||
|
||||
LIBHANDLE hlib = dl_loadlib(RSTRING_PTR(libname));
|
||||
void *hlib = SDL_LoadObject(RSTRING_PTR(libname));
|
||||
if (!hlib)
|
||||
rb_raise(rb_eRuntimeError, "Failed to load library %s", RSTRING_PTR(libname));
|
||||
rb_raise(rb_eRuntimeError, "Failed to load library %s: %s", RSTRING_PTR(libname), SDL_GetError());
|
||||
DATA_PTR(self) = hlib;
|
||||
|
||||
FUNCHANDLE hfunc = dl_getfunc(hlib, RSTRING_PTR(func));
|
||||
void *hfunc = SDL_LoadFunction(hlib, RSTRING_PTR(func));
|
||||
#ifdef __WIN32__
|
||||
if (!hfunc)
|
||||
{
|
||||
VALUE func_a = rb_str_new3(func);
|
||||
func_a = rb_str_cat(func_a, "A", 1);
|
||||
hfunc = dl_getfunc(hlib, RSTRING_PTR(func_a));
|
||||
hfunc = SDL_LoadFunction(hlib, RSTRING_PTR(func_a));
|
||||
}
|
||||
#endif
|
||||
if (!hfunc)
|
||||
rb_raise(rb_eRuntimeError, "Failed to find function %s within %s", RSTRING_PTR(func), RSTRING_PTR(libname));
|
||||
rb_raise(rb_eRuntimeError, "Failed to find function %s within %s: %s", RSTRING_PTR(func), RSTRING_PTR(libname), SDL_GetError());
|
||||
|
||||
|
||||
rb_iv_set(self, "_func", OFFT2NUM((unsigned long)hfunc));
|
||||
|
|
|
@ -2,6 +2,8 @@ project('mkxp-z', 'cpp', version: '1.0')
|
|||
|
||||
xxd = find_program('xxd')
|
||||
host_system = host_machine.system()
|
||||
compiler = meson.get_compiler('cpp')
|
||||
static = get_option('static')
|
||||
|
||||
if get_option('workdir_current') == true
|
||||
add_project_arguments('-DWORKDIR_CURRENT', language: 'cpp')
|
||||
|
@ -27,6 +29,10 @@ elif host_system == 'darwin'
|
|||
endif
|
||||
endif
|
||||
|
||||
if static == true and host_system != 'darwin'
|
||||
add_project_link_arguments('--static', 'cpp')
|
||||
endif
|
||||
|
||||
executable(meson.project_name(),
|
||||
sources: all_sources,
|
||||
dependencies: [main_dependencies, binding_dependencies],
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
option('shared_fluid', type: 'boolean', value: false, description: 'Dynamically link fluidsynth at build time')
|
||||
option('mri_version', type: 'string', value: '1.8', description: 'Version of MRI to link with')
|
||||
option('workdir_current', type: 'boolean', value: false, description: 'Keep current directory on startup')
|
||||
option('ruby_lib', type: 'string', value: 'ruby', description: 'Name of legacy Ruby library')
|
||||
option('ruby_lib', type: 'string', value: 'ruby', description: 'Name of legacy Ruby library')
|
||||
|
||||
option('static', type: 'boolean', value: 'false', description: 'Statically link as many libraries as possible')
|
|
@ -14,7 +14,7 @@ zlib = dependency('zlib')
|
|||
main_dependencies = [sigcxx, openal, boost, zlib, pixman, physfs, vorbisfile, sdl2, sdl2_ttf, sdl2_image, sdl_sound]
|
||||
|
||||
if host_system == 'darwin'
|
||||
main_dependencies += meson.get_compiler('cpp').find_library('iconv')
|
||||
main_dependencies += compiler.find_library('iconv')
|
||||
|
||||
if openal.type_name() != 'pkgconfig'
|
||||
add_project_arguments('-DUSE_MAC_OPENAL', language: 'cpp')
|
||||
|
|
Loading…
Add table
Reference in a new issue