#include "runtime.h"
#import <Foundation/Foundation.h>

std::string Runtime::getResourcePath(std::string_view filename) {
  CFStringRef fileNameRef = CFStringCreateWithCString(kCFAllocatorDefault, filename.data(), kCFStringEncodingUTF8);
  CFURLRef appUrlRef = CFBundleCopyResourceURL(CFBundleGetMainBundle(), fileNameRef, NULL, NULL);
  CFStringRef filePathRef = CFURLCopyPath(appUrlRef);
  const char* filePath = CFStringGetCStringPtr(filePathRef, kCFStringEncodingUTF8);
  std::string result(filePath);

  CFRelease(filePathRef);
  CFRelease(appUrlRef);
  CFRelease(fileNameRef);

  return result;
}