Complete conversion to pointer wrapped types. Update tests, fix
parameter handling for functions.
This commit is contained in:
@@ -22,10 +22,6 @@ func pb2() {
|
||||
|
||||
func didFinishLaunching(n *ns.NSNotification) {
|
||||
fmt.Println("Go: did finish launching")
|
||||
fmt.Printf("Notification n = %p\n",n)
|
||||
fmt.Printf("Notification n.Ptr() = %p\n",n.Ptr())
|
||||
fmt.Printf("Notification n.Name() = %p\n",n.Name())
|
||||
fmt.Printf("Notification n.Name().Ptr() = %p\n",n.Name().Ptr())
|
||||
fmt.Printf("Notification: %s\n", n.Name().UTF8String())
|
||||
//Set up an NSWindow
|
||||
win = ns.NSWindowAlloc().InitWithContentRectStyleMask(
|
||||
|
||||
+19
-19
@@ -8,7 +8,7 @@ import (
|
||||
"git.wow.st/gmp/nswrap/examples/bluetooth/ns"
|
||||
)
|
||||
|
||||
func updateState(c ns.CBCentralManager) {
|
||||
func updateState(c *ns.CBCentralManager) {
|
||||
fmt.Printf("Go: did update state\n")
|
||||
switch cm.CBManager.State() {
|
||||
case ns.CBManagerStateUnknown:
|
||||
@@ -23,11 +23,11 @@ func updateState(c ns.CBCentralManager) {
|
||||
fmt.Printf(" powered off\n")
|
||||
case ns.CBManagerStatePoweredOn:
|
||||
fmt.Printf(" powered on\n")
|
||||
cm.ScanForPeripheralsWithServices(ns.NSArrayWithObjects(hrm_uuid), ns.NSDictionary{})
|
||||
cm.ScanForPeripheralsWithServices(ns.NSArrayWithObjects(hrm_uuid), nil)
|
||||
}
|
||||
}
|
||||
|
||||
func discoverPeripheral(c ns.CBCentralManager, p ns.CBPeripheral, d ns.NSDictionary, rssi ns.NSNumber) {
|
||||
func discoverPeripheral(c *ns.CBCentralManager, p *ns.CBPeripheral, d *ns.NSDictionary, rssi *ns.NSNumber) {
|
||||
fmt.Printf("Did discover peripheral\n")
|
||||
c.StopScan()
|
||||
if peripheral.Ptr() != nil {
|
||||
@@ -35,26 +35,26 @@ func discoverPeripheral(c ns.CBCentralManager, p ns.CBPeripheral, d ns.NSDiction
|
||||
}
|
||||
peripheral = p
|
||||
peripheral.Retain()
|
||||
c.ConnectPeripheral(peripheral, ns.NSDictionary{})
|
||||
c.ConnectPeripheral(peripheral, nil)
|
||||
}
|
||||
|
||||
func connectPeripheral(c ns.CBCentralManager, p ns.CBPeripheral) {
|
||||
func connectPeripheral(c *ns.CBCentralManager, p *ns.CBPeripheral) {
|
||||
fmt.Printf("Did connect peripheral\n")
|
||||
p.SetDelegate(cd)
|
||||
p.DiscoverServices(ns.NSArray{})
|
||||
p.DiscoverServices(nil)
|
||||
}
|
||||
|
||||
func discoverServices(p ns.CBPeripheral, e ns.NSError) {
|
||||
func discoverServices(p *ns.CBPeripheral, e *ns.NSError) {
|
||||
fmt.Printf("Did discover services\n")
|
||||
p.Services().ObjectEnumerator().ForIn(func(o ns.Id) bool {
|
||||
p.Services().ObjectEnumerator().ForIn(func(o *ns.Id) bool {
|
||||
serv := o.CBService()
|
||||
switch {
|
||||
case serv.UUID().IsEqualTo(hrm_uuid):
|
||||
fmt.Printf("--heart rate monitor service\n")
|
||||
p.DiscoverCharacteristics(ns.NSArray{}, serv)
|
||||
p.DiscoverCharacteristics(nil, serv)
|
||||
case serv.UUID().IsEqualTo(ns.CBUUIDWithGoString("180A")):
|
||||
fmt.Printf("--device information service\n")
|
||||
p.DiscoverCharacteristics(ns.NSArray{}, serv)
|
||||
p.DiscoverCharacteristics(nil, serv)
|
||||
default:
|
||||
fmt.Printf("--unknown service\n")
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func discoverServices(p ns.CBPeripheral, e ns.NSError) {
|
||||
})
|
||||
}
|
||||
|
||||
func hr(d ns.NSData) int {
|
||||
func hr(d *ns.NSData) int {
|
||||
if l := int(d.Length()); l < 4 {
|
||||
return 0
|
||||
}
|
||||
@@ -75,11 +75,11 @@ func hr(d ns.NSData) int {
|
||||
}
|
||||
}
|
||||
|
||||
func discoverCharacteristics(p ns.CBPeripheral, s ns.CBService, e ns.NSError) {
|
||||
func discoverCharacteristics(p *ns.CBPeripheral, s *ns.CBService, e *ns.NSError) {
|
||||
fmt.Printf("Did discover characteristics\n")
|
||||
fmt.Printf("----%s\n", s.UUID().UUIDString().UTF8String())
|
||||
if s.UUID().IsEqualTo(hrm_uuid) {
|
||||
s.Characteristics().ObjectEnumerator().ForIn(func(o ns.Id) bool {
|
||||
s.Characteristics().ObjectEnumerator().ForIn(func(o *ns.Id) bool {
|
||||
chr := o.CBCharacteristic()
|
||||
fmt.Printf("------%s\n", chr.UUID().UUIDString().UTF8String())
|
||||
if chr.UUID().IsEqualTo(hrv_uuid) {
|
||||
@@ -92,7 +92,7 @@ func discoverCharacteristics(p ns.CBPeripheral, s ns.CBService, e ns.NSError) {
|
||||
}
|
||||
}
|
||||
|
||||
func updateValue(p ns.CBPeripheral, chr ns.CBCharacteristic, e ns.NSError) {
|
||||
func updateValue(p *ns.CBPeripheral, chr *ns.CBCharacteristic, e *ns.NSError) {
|
||||
if chr.UUID().IsEqualTo(hrv_uuid) {
|
||||
v := chr.Value()
|
||||
fmt.Printf("Heart rate: %d\n", hr(v))
|
||||
@@ -100,11 +100,11 @@ func updateValue(p ns.CBPeripheral, chr ns.CBCharacteristic, e ns.NSError) {
|
||||
}
|
||||
|
||||
var (
|
||||
hrm_uuid ns.CBUUID
|
||||
hrv_uuid ns.CBUUID
|
||||
cd ns.CBDelegate
|
||||
cm ns.CBCentralManager
|
||||
peripheral ns.CBPeripheral
|
||||
hrm_uuid *ns.CBUUID
|
||||
hrv_uuid *ns.CBUUID
|
||||
cd *ns.CBDelegate
|
||||
cm *ns.CBCentralManager
|
||||
peripheral *ns.CBPeripheral
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -38,4 +38,4 @@ delegates:
|
||||
- peripheralDidUpdateValueForCharacteristic
|
||||
|
||||
pragma: [ clang diagnostic ignored "-Wformat-security" ]
|
||||
gogc: true
|
||||
#gogc: true
|
||||
|
||||
@@ -8,6 +8,11 @@ import (
|
||||
"git.wow.st/gmp/nswrap/examples/foundation/ns"
|
||||
)
|
||||
|
||||
var (
|
||||
gs1 *ns.NSString
|
||||
gs2 *ns.NSString
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Printf("Creating some strings:\n")
|
||||
n1 := ns.NSStringWithUTF8String(ns.CharWithGoString("hi there"))
|
||||
@@ -64,6 +69,19 @@ func main() {
|
||||
}
|
||||
return true
|
||||
})
|
||||
fmt.Printf("\nNSArrayWithObjects() (length 1)\n")
|
||||
a2 = ns.NSArrayWithObjects(n1)
|
||||
a2.ObjectEnumerator().ForIn(func(o *ns.Id) bool {
|
||||
switch {
|
||||
case o.IsKindOfClass(ns.NSStringClass()):
|
||||
fmt.Println(o.NSString().UTF8String())
|
||||
return true // continue enumeration
|
||||
default:
|
||||
fmt.Println("Unknown class")
|
||||
return false // terminate enumeration
|
||||
}
|
||||
})
|
||||
|
||||
fmt.Printf("\nNSArrayWithObjects()\n")
|
||||
a2 = ns.NSArrayWithObjects(n1, n2, n3, s1)
|
||||
fmt.Printf("\nNSArray.ObjectEnumerator().ForIn():\n")
|
||||
@@ -101,4 +119,14 @@ func main() {
|
||||
fmt.Printf("\nNSStringWithFormat()\n")
|
||||
str := ns.NSStringWithFormat(nst("(%@) (%@)\n(%@)\n"), n2, n3, s1)
|
||||
fmt.Printf("%s\n", str)
|
||||
|
||||
fmt.Printf("\nGlobal strings\n")
|
||||
gs1 = ns.NSStringWithGoString("global string 1")
|
||||
gs2 = ns.NSStringWithGoString("global string 2")
|
||||
fmt.Printf("\nArrayWithObjects\n")
|
||||
a2 = ns.NSArrayWithObjects(gs1, gs2)
|
||||
a2.ObjectEnumerator().ForIn(func(o *ns.Id) bool {
|
||||
fmt.Printf("--%s\n",o.NSString())
|
||||
return true
|
||||
})
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
"git.wow.st/gmp/nswrap/examples/functions/ns"
|
||||
)
|
||||
|
||||
func main() {
|
||||
var s ns.Stat
|
||||
ns.Puts(ns.CharWithGoString("Hi there"))
|
||||
ret := ns.Fstat(3,&s)
|
||||
fmt.Printf("Fstat: %d\n",ret)
|
||||
|
||||
fmt.Printf("Opening file\n")
|
||||
f := ns.Fopen(ns.CharWithGoString("nswrap.yaml"),ns.CharWithGoString("r"))
|
||||
ret = ns.Fstat(3,&s)
|
||||
fmt.Printf("Fstat: %d\n",ret)
|
||||
chr := make([]byte,4096)
|
||||
i := ns.Fread(unsafe.Pointer(&chr[0]), 1, 4096, f)
|
||||
if i < 4096 {
|
||||
chr = chr[:i]
|
||||
}
|
||||
fmt.Printf("file contents:\n%s\n",string(chr))
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
inputfiles:
|
||||
- /usr/include/stdio.h
|
||||
- /usr/include/stdlib.h
|
||||
- /usr/include/sys/stat.h
|
||||
sysimports:
|
||||
- stdio.h
|
||||
- stdlib.h
|
||||
- sys/stat.h
|
||||
functions:
|
||||
- sranddev
|
||||
- cgetclose
|
||||
- cgetset
|
||||
- devname
|
||||
- puts
|
||||
- fstat
|
||||
- fopen
|
||||
- fread
|
||||
Reference in New Issue
Block a user