From f5c4671bfbad96bf346bd7e9a21fc4317b4959df Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Sat, 3 Dec 2022 17:00:20 +0530 Subject: Adds most of the tools --- v_windows/v/old/vlib/darwin/darwin.m | 9 ++++++ v_windows/v/old/vlib/darwin/darwin.v | 57 ++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) create mode 100644 v_windows/v/old/vlib/darwin/darwin.m create mode 100644 v_windows/v/old/vlib/darwin/darwin.v (limited to 'v_windows/v/old/vlib/darwin') diff --git a/v_windows/v/old/vlib/darwin/darwin.m b/v_windows/v/old/vlib/darwin/darwin.m new file mode 100644 index 0000000..5cab83a --- /dev/null +++ b/v_windows/v/old/vlib/darwin/darwin.m @@ -0,0 +1,9 @@ + +///void NSLog(id x); + +#include + +NSString* nsstring2(string s) { + return [ [ NSString alloc ] initWithBytesNoCopy:s.str length:s.len + encoding:NSUTF8StringEncoding freeWhenDone: false]; +} diff --git a/v_windows/v/old/vlib/darwin/darwin.v b/v_windows/v/old/vlib/darwin/darwin.v new file mode 100644 index 0000000..b86636e --- /dev/null +++ b/v_windows/v/old/vlib/darwin/darwin.v @@ -0,0 +1,57 @@ +module darwin + +#include +#include + +#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 +} -- cgit v1.2.3