From 4c52b1dea4e11371761f8a52a65052246c74d23a Mon Sep 17 00:00:00 2001 From: Adam Harrison Date: Sat, 2 Oct 2021 15:52:35 -0400 Subject: [PATCH] Removes the objective C file, replacing it with the C api. --- src/bundle_open.m | 20 -------------------- src/main.c | 21 +++++++++++++++++---- 2 files changed, 17 insertions(+), 24 deletions(-) delete mode 100644 src/bundle_open.m diff --git a/src/bundle_open.m b/src/bundle_open.m deleted file mode 100644 index 2ba10da7..00000000 --- a/src/bundle_open.m +++ /dev/null @@ -1,20 +0,0 @@ -#import -#include "lua.h" - -#ifdef MACOS_USE_BUNDLE -void set_macos_bundle_resources(lua_State *L) -{ @autoreleasepool -{ - NSString* resource_path = [[NSBundle mainBundle] resourcePath]; - lua_pushstring(L, [resource_path UTF8String]); - lua_setglobal(L, "MACOS_RESOURCES"); -}} -#endif - -/* Thanks to mathewmariani, taken from his lite-macos github repository. */ -void enable_momentum_scroll() { - [[NSUserDefaults standardUserDefaults] - setBool: YES - forKey: @"AppleMomentumScrollSupported"]; -} - diff --git a/src/main.c b/src/main.c index 182511d0..b85b2cb6 100644 --- a/src/main.c +++ b/src/main.c @@ -12,6 +12,9 @@ #include #elif __APPLE__ #include + #include + #include + #include #endif @@ -77,10 +80,20 @@ static void init_window_icon(void) { #endif #ifdef __APPLE__ -void enable_momentum_scroll(); -#ifdef MACOS_USE_BUNDLE -void set_macos_bundle_resources(lua_State *L); -#endif + static void enable_momentum_scroll() { + void* standardUserDefaults = objc_msgSend(objc_getClass("NSUserDefaults"), NSSelectorFromString(CFSTR("standardUserDefaults"))); + objc_msgSend(standardUserDefaults, "setBool", true, CFSTR("AppleMomentumScrollSupported")); + } + #ifdef MACOS_USE_BUNDLE + static void set_macos_bundle_resources(lua_State *L) { + id autoreleasePool = objc_msgSend(objc_msgSend(objc_getClass("NSAutoreleasePool"), sel_registerName("alloc")), sel_registerName("init")); + void* obj = objc_msgSend(objc_getClass("NSBundle"), NSSelectorFromString(CFSTR("mainBundle"))); + const char* utf8string = objc_msgSend(objc_msgSend(obj, NSSelectorFromString(CFSTR("resourcePath"))), NSSelectorFromString(CFSTR("UTF8String"))); + lua_pushstring(L, utf8string); + lua_setglobal(L, "MACOS_RESOURCES"); + objc_msgSend(autoreleasePool, sel_registerName("drain")); + } + #endif #endif int main(int argc, char **argv) {