This repository was archived by the owner on Aug 31, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 226
Expand file tree
/
Copy pathfoundation-objc-dummy.cpp
More file actions
385 lines (312 loc) · 10.8 KB
/
foundation-objc-dummy.cpp
File metadata and controls
385 lines (312 loc) · 10.8 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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
/* Copyright (C) 2003-2015 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/>. */
#include <foundation.h>
#include <foundation-auto.h>
#include <foundation-objc.h>
////////////////////////////////////////////////////////////////////////////////
MC_DLLEXPORT_DEF MCTypeInfoRef kMCObjcObjectTypeInfo;
MC_DLLEXPORT_DEF MCTypeInfoRef MCObjcObjectTypeInfo() { return kMCObjcObjectTypeInfo; }
MC_DLLEXPORT_DEF MCTypeInfoRef kMCObjcIdTypeInfo;
MC_DLLEXPORT_DEF MCTypeInfoRef MCObjcIdTypeInfo() { return kMCObjcIdTypeInfo; }
MC_DLLEXPORT_DEF MCTypeInfoRef kMCObjcRetainedIdTypeInfo;
MC_DLLEXPORT_DEF MCTypeInfoRef MCObjcRetainedIdTypeInfo() { return kMCObjcRetainedIdTypeInfo; }
MC_DLLEXPORT_DEF MCTypeInfoRef kMCObjcAutoreleasedIdTypeInfo;
MC_DLLEXPORT_DEF MCTypeInfoRef MCObjcAutoreleasedIdTypeInfo() { return kMCObjcAutoreleasedIdTypeInfo; }
struct __MCObjcObjectImpl
{
void *object;
};
static __MCObjcObjectImpl *__MCObjcObjectGet(MCValueRef p_obj)
{
return static_cast<__MCObjcObjectImpl *>(MCValueGetExtraBytesPtr(p_obj));
}
static void __MCObjcObjectDestroy(MCValueRef p_value)
{
}
static bool __MCObjcObjectCopy(MCValueRef p_value, bool p_release, MCValueRef &r_copy)
{
if (p_release)
r_copy = p_value;
else
r_copy = MCValueRetain(p_value);
return true;
}
static bool __MCObjcObjectEqual(MCValueRef p_left, MCValueRef p_right)
{
if (p_left == p_right)
return true;
__MCObjcObjectImpl *t_left_impl = __MCObjcObjectGet(p_left);
__MCObjcObjectImpl *t_right_impl = __MCObjcObjectGet(p_right);
return t_left_impl->object == t_right_impl->object;
}
static hash_t __MCObjcObjectHash(MCValueRef p_value)
{
__MCObjcObjectImpl *t_impl = __MCObjcObjectGet(p_value);
return MCHashPointer(t_impl->object);
}
bool __MCObjcObjectDescribe(MCValueRef p_value, MCStringRef &r_desc)
{
__MCObjcObjectImpl *t_impl = __MCObjcObjectGet(p_value);
return MCStringFormat(r_desc, "<objc object %p>", t_impl->object);
}
static MCValueCustomCallbacks kMCObjcObjectCustomValueCallbacks =
{
false,
__MCObjcObjectDestroy,
__MCObjcObjectCopy,
__MCObjcObjectEqual,
__MCObjcObjectHash,
__MCObjcObjectDescribe,
nullptr,
nullptr,
};
////////////////////////////////////////////////////////////////////////////////
/* The Id foreign value is a unmanaged wrapper around 'id' - basically like
* Pointer but with a bridge to ObjcObject which explicitly retains its value. */
static void
objc_id_finalize(void *contents)
{
}
static bool
objc_id_move(const MCForeignTypeDescriptor*, void *from, void *to)
{
*static_cast<void **>(to) = *static_cast<void **>(from);
return true;
}
static bool
objc_id_copy(const MCForeignTypeDescriptor*, void *from, void *to)
{
*static_cast<void **>(to) = *static_cast<void **>(from);
return true;
}
static bool
objc_id_equal(const MCForeignTypeDescriptor*, void *from, void *to, bool& r_equal)
{
r_equal = *static_cast<void **>(to) == *static_cast<void **>(to);
return true;
}
static bool
objc_id_hash(const MCForeignTypeDescriptor*, void *value, hash_t& r_hash)
{
r_hash = MCHashPointer(*static_cast<void **>(value));
return true;
}
static bool
objc_id_describe(const MCForeignTypeDescriptor*, void *value, MCStringRef& r_string)
{
return MCStringFormat(r_string, "<objc id %p>", *static_cast<void **>(value));
}
static bool
objc_retained_id_describe(const MCForeignTypeDescriptor*, void *value, MCStringRef& r_string)
{
return MCStringFormat(r_string, "<objc retained id %p>", *static_cast<void **>(value));
}
static bool
objc_autoreleased_id_describe(const MCForeignTypeDescriptor*, void *value, MCStringRef& r_string)
{
return MCStringFormat(r_string, "<objc autoreleased id %p>", *static_cast<void **>(value));
}
static bool
objc_id_import(const MCForeignTypeDescriptor*, void *contents, bool p_release, MCValueRef& r_value)
{
MCAssert(!p_release);
return MCObjcObjectCreateWithId(*(void **)contents, (MCObjcObjectRef&)r_value);
}
static bool
objc_id_export(const MCForeignTypeDescriptor*, MCValueRef p_value, bool p_release, void *contents)
{
MCAssert(!p_release);
*(void **)contents = MCObjcObjectGetId((MCObjcObjectRef)p_value);
return true;
}
static bool
objc_retained_id_import(const MCForeignTypeDescriptor*, void *contents, bool p_release, MCValueRef& r_value)
{
MCAssert(!p_release);
return MCObjcObjectCreateWithRetainedId(*(void **)contents, (MCObjcObjectRef&)r_value);
}
static bool
objc_retained_id_export(const MCForeignTypeDescriptor*, MCValueRef p_value, bool p_release, void *contents)
{
MCAssert(!p_release);
*(void **)contents = MCObjcObjectGetRetainedId((MCObjcObjectRef)p_value);
return true;
}
static bool
objc_autoreleased_id_import(const MCForeignTypeDescriptor*, void *contents, bool p_release, MCValueRef& r_value)
{
MCAssert(!p_release);
return MCObjcObjectCreateWithAutoreleasedId(*(void **)contents, (MCObjcObjectRef&)r_value);
}
static bool
objc_autoreleased_id_export(const MCForeignTypeDescriptor*, MCValueRef p_value, bool p_release, void *contents)
{
MCAssert(!p_release);
*(void **)contents = MCObjcObjectGetAutoreleasedId((MCObjcObjectRef)p_value);
return true;
}
////////////////////////////////////////////////////////////////////////////////
MC_DLLEXPORT_DEF bool MCObjcObjectCreateWithId(void *p_object, MCObjcObjectRef &r_object)
{
MCObjcObjectRef t_obj;
if (!MCValueCreateCustom(kMCObjcObjectTypeInfo,
sizeof(__MCObjcObjectImpl),
t_obj))
{
return false;
}
__MCObjcObjectImpl *t_impl = __MCObjcObjectGet(t_obj);
t_impl->object = nullptr;
r_object = t_obj;
return true;
}
MC_DLLEXPORT_DEF bool MCObjcObjectCreateWithRetainedId(void *p_object, MCObjcObjectRef &r_object)
{
MCObjcObjectRef t_obj;
if (!MCValueCreateCustom(kMCObjcObjectTypeInfo,
sizeof(__MCObjcObjectImpl),
t_obj))
{
return false;
}
__MCObjcObjectImpl *t_impl = __MCObjcObjectGet(t_obj);
t_impl->object = nullptr;
r_object = t_obj;
return true;
}
MC_DLLEXPORT_DEF bool MCObjcObjectCreateWithAutoreleasedId(void *p_object, MCObjcObjectRef &r_object)
{
return MCObjcObjectCreateWithId(p_object, r_object);
}
////////////////////////////////////////////////////////////////////////////////
MC_DLLEXPORT_DEF void *MCObjcObjectGetId(const MCObjcObjectRef p_obj)
{
__MCObjcObjectImpl *t_impl = __MCObjcObjectGet(p_obj);
return t_impl->object;
}
MC_DLLEXPORT_DEF void *MCObjcObjectGetRetainedId(const MCObjcObjectRef p_obj)
{
return nullptr;
}
MC_DLLEXPORT_DEF void *MCObjcObjectGetAutoreleasedId(const MCObjcObjectRef p_obj)
{
return nullptr;
}
////////////////////////////////////////////////////////////////////////////////
extern "C"
MC_DLLEXPORT_DEF MCObjcObjectRef MCObjcObjectCreateActionProxy(MCHandlerRef p_handler, MCValueRef p_context)
{
MCObjcObjectRef t_proxy_object = nullptr;
if (!MCObjcObjectCreateWithRetainedId(nullptr, t_proxy_object))
{
return nullptr;
}
return t_proxy_object;
}
extern "C"
MC_DLLEXPORT_DEF uintptr_t MCObjcObjectGetActionProxySelector(void)
{
return 0;
}
////////////////////////////////////////////////////////////////////////////////
extern "C" MC_DLLEXPORT_DEF
bool MCObjcCreateDelegateWithContext(MCStringRef p_protocol_name, MCArrayRef p_handler_mapping, MCValueRef p_context, MCObjcObjectRef& r_object)
{
return false;
}
extern "C" MC_DLLEXPORT_DEF
bool MCObjcCreateDelegate(MCStringRef p_protocol_name, MCArrayRef p_handler_mapping, MCObjcObjectRef& r_object)
{
return false;
}
extern "C" MC_DLLEXPORT_DEF
bool MCObjcCreateInformalDelegateWithContext(MCProperListRef p_foreign_handlers, MCArrayRef p_handler_mapping, MCValueRef p_context, MCObjcObjectRef& r_object)
{
return false;
}
extern "C" MC_DLLEXPORT_DEF
bool MCObjcCreateInformalDelegate(MCProperListRef p_foreign_handlers, MCArrayRef p_handler_mapping, MCObjcObjectRef& r_object)
{
return false;
}
////////////////////////////////////////////////////////////////////////////////
bool __MCObjcInitialize(void)
{
if (!MCNamedCustomTypeInfoCreate(MCNAME("com.livecode.objc.ObjcObject"),
kMCNullTypeInfo,
&kMCObjcObjectCustomValueCallbacks,
kMCObjcObjectTypeInfo))
{
return false;
}
MCForeignPrimitiveType p = kMCForeignPrimitiveTypePointer;
MCForeignTypeDescriptor d =
{
sizeof(void*),
kMCNullTypeInfo,
kMCObjcObjectTypeInfo,
&p,
1,
nullptr, /* initialize */
objc_id_finalize, /* finalize */
nullptr, /* defined */
objc_id_move,
objc_id_copy,
objc_id_equal,
objc_id_hash,
objc_id_import,
objc_id_export,
objc_id_describe,
kMCNullTypeInfo,
nullptr, /* promote */
};
if (!MCNamedForeignTypeInfoCreate(MCNAME("com.livecode.objc.Id"),
&d,
kMCObjcIdTypeInfo))
{
return false;
}
d.doimport = objc_retained_id_import;
d.doexport = objc_retained_id_export;
d.describe = objc_retained_id_describe;
if (!MCNamedForeignTypeInfoCreate(MCNAME("com.livecode.objc.RetainedId"),
&d,
kMCObjcRetainedIdTypeInfo))
{
return false;
}
d.doimport = objc_autoreleased_id_import;
d.doexport = objc_autoreleased_id_export;
d.describe = objc_autoreleased_id_describe;
if (!MCNamedForeignTypeInfoCreate(MCNAME("com.livecode.objc.AutoreleasedId"),
&d,
kMCObjcAutoreleasedIdTypeInfo))
{
return false;
}
return true;
}
void __MCObjcFinalize(void)
{
MCValueRelease(kMCObjcIdTypeInfo);
MCValueRelease(kMCObjcRetainedIdTypeInfo);
MCValueRelease(kMCObjcAutoreleasedIdTypeInfo);
MCValueRelease(kMCObjcObjectTypeInfo);
}
extern "C" bool com_livecode_objc_Initialize(void)
{
return true;
}
extern "C" void com_livecode_objc_Finalize(void)
{
}
////////////////////////////////////////////////////////////////////////////////