forked from parmanoir/jscocoa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path18 structure args.js
42 lines (24 loc) · 956 Bytes
/
18 structure args.js
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
// Split call disabled by default since ObjJ syntax
var useSplitCall = __jsc__.useSplitCall
__jsc__.useSplitCall = true
// JSCocoaController.sharedController.evalJSFile(NSBundle.mainBundle.bundlePath + '/Contents/Resources/class.js')
/*
Use struct as method args
method('float', 'struct:rect', 'float') returns rect
*/
defineClass('StructureArgsTester < NSObject',
{
'testWithX:struct:Y:' :
['struct NSPoint', 'float', 'struct NSPoint', 'float', function (x, rect, y)
{
var rect = NSMakePoint(rect.x+x, rect.y+y)
return rect
}]
})
var o = StructureArgsTester.instance
var r = o.testWith({x:1.23, struct:NSMakePoint(10, 20), y:4.56})
if (Math.abs( (10+1.23) - r.x ) > 0.001) throw 'structure args failed (1)'
if (Math.abs( (20+4.56) - r.y ) > 0.001) throw 'structure args failed (2)'
// JSCocoaController.log('x=' + r.x + ' y=' + r.y)
o = null
__jsc__.useSplitCall = useSplitCall