blob: b86636e1017e7ff2c57c0f452ae142c0ee212234 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
module darwin
#include <Cocoa/Cocoa.h>
#include <CoreFoundation/CoreFoundation.h>
#flag -framework Cocoa
#flag -framework Carbon
struct C.NSString {}
#include "@VEXEROOT/vlib/darwin/darwin.m"
fn C.nsstring2(s string) voidptr
// macOS and iOS helpers
// pub fn nsstring(s string) *C.NSString {
pub fn nsstring(s string) voidptr {
return C.nsstring2(s)
// println('ns $s len=$s.len')
//# return [ [ NSString alloc ] initWithBytesNoCopy:s.str length:s.len
//# encoding:NSUTF8StringEncoding freeWhenDone: false];
// return 0
// ns := C.alloc_NSString()
// return ns.initWithBytesNoCopy(s.str, length: s.len,
// encoding: NSUTF8StringEncoding, freeWhenDone: false)
}
// returns absolute path to folder where your resources should / will reside
// for .app packages: .../my.app/Contents/Resources
// for cli: .../parent_folder/Resources
fn C.CFBundleCopyResourcesDirectoryURL(bundle voidptr) &byte
fn C.CFBundleGetMainBundle() voidptr
fn C.CFURLGetFileSystemRepresentation(url &byte, resolve_against_base bool, buffer &byte, buffer_size int) int
fn C.CFRelease(url &byte)
pub fn resource_path() string {
main_bundle := C.CFBundleGetMainBundle()
resource_dir_url := C.CFBundleCopyResourcesDirectoryURL(main_bundle)
if isnil(resource_dir_url) {
panic('CFBundleCopyResourcesDirectoryURL failed')
}
buffer_size := 4096
mut buffer := unsafe { malloc_noscan(buffer_size) }
unsafe {
buffer[0] = 0
}
conv_result := C.CFURLGetFileSystemRepresentation(resource_dir_url, true, buffer,
buffer_size)
if conv_result == 0 {
panic('CFURLGetFileSystemRepresentation failed')
}
result := unsafe { buffer.vstring() }
C.CFRelease(resource_dir_url)
return result
}
|