forked from livecode/livecode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjc.lcb
More file actions
207 lines (152 loc) · 5.43 KB
/
Copy pathobjc.lcb
File metadata and controls
207 lines (152 loc) · 5.43 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
/* Copyright (C) 2017 LiveCode Ltd.
This file is part of LiveCode.
LiveCode is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License v3 as published by the Free
Software Foundation.
LiveCode is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
/**
This module provides utility handlers for converting to and from Obj-C types.
*/
module com.livecode.objc
use com.livecode.foreign
/****/
public foreign type ObjcObject binds to "MCObjcObjectTypeInfo"
public foreign type ObjcId binds to "MCObjcIdTypeInfo"
public foreign type ObjcRetainedId binds to "MCObjcRetainedIdTypeInfo"
public foreign type ObjcAutoreleasedId binds to "MCObjcAutoreleasedIdTypeInfo"
/****/
private foreign handler MCStringCreateWithCFString(in pNSString as ObjcId, out rString as String) returns CBool binds to "MCStringCreateWithCFString"
private foreign handler MCStringConvertToCFStringRef(in pString as String, out rNSString as ObjcRetainedId) returns CBool binds to "MCStringConvertToCFStringRef"
/**/
/**
Summary: Convert a String into an Objective-C string
Parameters:
pString: The String to convert
Returns:
A Objective-C object of type NSString
Description
Use <StringToNSString> to convert a variable of type String to an Objective-C
string object (NSString).
*/
public handler StringToNSString(in pString as String) returns ObjcObject
variable tNSString as ObjcRetainedId
unsafe
MCStringConvertToCFStringRef(pString, tNSString)
end unsafe
return tNSString
end handler
/**
Summary: Convert a Objective-C string into a String
Parameters:
pObjcString: The NSString to convert
Returns:
A String value
Description
Use <StringFromNSString> to convert an Objective-C string object (NSString) to
a variable of type String.
*/
public handler StringFromNSString(in pObjcString as ObjcObject) returns String
variable tString as String
unsafe
MCStringCreateWithCFString(pObjcString, tString)
end unsafe
return tString
end handler
/****/
private foreign handler MCDataCreateWithCFData(in pNSData as ObjcId, out rString as Data) returns CBool binds to "MCDataCreateWithCFData"
private foreign handler MCDataConvertToCFDataRef(in pNSData as Data, out rNSData as ObjcRetainedId) returns CBool binds to "MCDataConvertToCFDataRef"
/**/
/**
Summary: Convert a Data into an Objective-C data
Parameters:
pData: The Data to convert
Returns:
A Objective-C object of type NSData
Description
Use <DataToNSData> to convert a variable of type Data to an Objective-C
string object (NSData).
*/
public handler DataToNSData(in pData as Data) returns ObjcObject
variable tNSData as ObjcRetainedId
unsafe
MCDataConvertToCFDataRef(pData, tNSData)
end unsafe
return tNSData
end handler
/**
Summary: Convert a Objective-C data into a Data
Parameters:
pObjcData: The NSData to convert
Returns:
A String value
Description
Use <DataFromNSData> to convert an Objective-C data object (NSData) to
a variable of type Data.
*/
public handler DataFromNSData(in pObjcData as ObjcObject) returns String
variable tData as Data
unsafe
MCDataCreateWithCFData(pObjcData, tData)
end unsafe
return tData
end handler
/****/
public handler type ObjcActionProxyHandler(in pSender as ObjcObject, in pContext as optional any) returns nothing
private foreign handler MCObjcObjectCreateActionProxy(in pHandler as optional any, in pValue as optional any) returns ObjcObject binds to "MCObjcObjectCreateActionProxy"
private foreign handler MCObjcObjectGetActionProxySelector() returns UIntPtr binds to "MCObjcObjectGetActionProxySelector"
public handler ObjcProxyGetTarget(in pHandler as ObjcActionProxyHandler, in pContext as optional any) returns ObjcObject
unsafe
return MCObjcObjectCreateActionProxy(pHandler, pContext)
end unsafe
end handler
public handler ObjcProxyGetAction() returns UIntPtr
unsafe
return MCObjcObjectGetActionProxySelector()
end unsafe
end handler
/**/
/****/
private foreign handler _MCObjcObjectCreateWithId_AsPointer(in pPointer as optional Pointer) returns ObjcObject binds to "MCObjcObjectCreateWithId"
private foreign handler _MCObjcObjectGetId_AsPointer(in pObject as ObjcObject) returns optional Pointer binds to "MCObjcObjectGetId"
/**/
/**
Summary: Convert a Pointer into an ObjcObject
Parameters:
pPointer: The Pointer to convert
Returns:
An ObjcObject wrapping the Pointer
Description:
Use <PointerToObjcObject> to convert a variable of type Pointer to one of type
ObjcObject.
*/
public handler PointerToObjcObject(in pPointer as optional Pointer) returns ObjcObject
variable tObject as ObjcObject
unsafe
put _MCObjcObjectCreateWithId_AsPointer(pPointer) into tObject
end unsafe
return tObject
end handler
/**
Summary: Convert an ObjcObject into a Pointer
Parameters:
pObjcObject: The ObjcObject to convert
Returns:
The Pointer wrapped by the ObjcObject
Description:
Use <PointerFromObjcObject> to convert a variable of type ObjcObject to one of
type Pointer.
*/
public handler PointerFromObjcObject(in pObjcObject as ObjcObject) returns optional Pointer
variable tPointer as Pointer
unsafe
put _MCObjcObjectGetId_AsPointer(pObjcObject) into tPointer
end unsafe
return tPointer
end handler
/****/
end module