Removes the objective C file, replacing it with the C api.

This commit is contained in:
Adam Harrison 2021-10-02 15:52:35 -04:00
parent eb79381c89
commit 4c52b1dea4
2 changed files with 17 additions and 24 deletions

View File

@ -1,20 +0,0 @@
#import <Foundation/Foundation.h>
#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"];
}

View File

@ -12,6 +12,9 @@
#include <signal.h> #include <signal.h>
#elif __APPLE__ #elif __APPLE__
#include <mach-o/dyld.h> #include <mach-o/dyld.h>
#include <CoreFoundation/CoreFoundation.h>
#include <objc/runtime.h>
#include <objc/message.h>
#endif #endif
@ -77,9 +80,19 @@ static void init_window_icon(void) {
#endif #endif
#ifdef __APPLE__ #ifdef __APPLE__
void enable_momentum_scroll(); 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 #ifdef MACOS_USE_BUNDLE
void set_macos_bundle_resources(lua_State *L); 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
#endif #endif