-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinclude-list-osx.lua
More file actions
722 lines (608 loc) · 21.1 KB
/
include-list-osx.lua
File metadata and controls
722 lines (608 loc) · 21.1 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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
local table = require 'ext.table'
local string = require 'ext.string'
local util = require 'include.util'
local safegsub = util.safegsub
local removeEnum = util.removeEnum
local commentOutLine = util.commentOutLine
local fixEnumsAndDefineMacrosInterleaved = util.fixEnumsAndDefineMacrosInterleaved
local function removeAttrAvailability(code)
-- luajit can't handle these attributes ...
return safegsub(code, '__attribute__%(%(availability%b()%)%)', '')
:gsub('%s*\n%s*\n', '\n')
end
local function replace_SEEK(code)
-- unistd.h stdio.h fcntl.h all define SEEK_*, so ...
code = safegsub(code, [[
enum { SEEK_SET = 0 };
enum { SEEK_CUR = 1 };
enum { SEEK_END = 2 };
enum { SEEK_HOLE = 3 };
enum { SEEK_DATA = 4 };
]],
"]] require 'ffi.req' 'c.bits.types.SEEK' ffi.cdef[[\n"
)
return code
end
return table{
----------------------- INTERNALLY REQUESTED: -----------------------
-- They only exist to replace duplicate-generated ctypes
-- This process of duplication-detection can be automated:
-- 1) generate a binding file
-- 2) search through all previous generated binding files, search the pair of the new file + old file for like included files
-- 2b) if a like included file is found, then add that to our internally-requested list.
-- 2c) build a DAG while you go, keep them in order.
-- 3) once you're finished, any stored internally-requested files not requested this time around should be reported (out with the old).
-- fake file
-- SEEK_* is used by <stdio.h> <unistd.h> <fcntl.h>
-- they all hvae the same macros so they're going here:
{
inc = '$notthere.h',
out = 'OSX/c/bits/types/SEEK.lua',
forcecode = [=[
local ffi = require 'ffi'
ffi.cdef[[
enum { SEEK_SET = 0 };
enum { SEEK_CUR = 1 };
enum { SEEK_END = 2 };
]]
]=]
},
-- used by <time.h> <string.h>
{inc='<Availability.h>', out='OSX/c/Availability.lua'},
-- used by <_types.h> <machine/types.h>
{inc='<i386/_types.h>', out='OSX/c/i386/_types.lua'},
-- used by <_types.h> <machine/types.h>
{inc='<sys/cdefs.h>', out='OSX/c/sys/cdefs.lua'},
-- used by <machine/types.h> <_types.h>
{inc='<machine/_types.h>', out='OSX/c/machine/_types.lua'},
-- used by <sys/_pthread/_pthread_attr_t.h> <sys/_types.h>
{inc='<sys/_pthread/_pthread_types.h>', out='OSX/c/sys/_pthread/_pthread_types.lua'},
-- used by <sys/signal.h> <_types.h>
{inc='<sys/_types.h>', out='OSX/c/sys/_types.lua'},
-- used by <time.h> <string.h>
{inc='<_types.h>', out='OSX/c/_types.lua'},
-- used by <stdint.h> <machine/types.h>
{inc='<sys/_types/_int8_t.h>', out='OSX/c/sys/_types/_int8_t.lua'},
-- used by <stdint.h> <machine/types.h>
{inc='<sys/_types/_int16_t.h>', out='OSX/c/sys/_types/_int16_t.lua'},
-- used by <stdint.h> <machine/types.h>
{inc='<sys/_types/_int32_t.h>', out='OSX/c/sys/_types/_int32_t.lua'},
-- used by <stdint.h> <machine/types.h>
{inc='<sys/_types/_int64_t.h>', out='OSX/c/sys/_types/_int64_t.lua'},
-- used by <stdint.h> <machine/types.h>
{inc='<sys/_types/_intptr_t.h>', out='OSX/c/sys/_types/_intptr_t.lua'},
-- used by <stdint.h> <machine/types.h>
{inc='<sys/_types/_uintptr_t.h>', out='OSX/c/sys/_types/_uintptr_t.lua'},
-- used by <time.h> <string.h>
{inc='<machine/types.h>', out='OSX/c/machine/types.lua'},
-- used by <time.h> <string.h>
{inc='<sys/_types/_size_t.h>', out='OSX/c/sys/_types/_size_t.lua'},
-- used by <errno.h> <string.h>
{inc='<sys/_types/_errno_t.h>', out='OSX/c/sys/_types/_errno_t.lua'},
-- used by <stdio.h> <string.h>
{inc='<sys/_types/_ssize_t.h>', out='OSX/c/sys/_types/_ssize_t.lua'},
-- used by <stdlib.h> <sys/signal.h>
{inc='<sys/_types/_pid_t.h>', out='OSX/c/sys/_types/_pid_t.lua'},
-- used by <pthread.h> <sys/signal.h>
{inc='<sys/_pthread/_pthread_attr_t.h>', out='OSX/c/sys/_pthread/_pthread_attr_t.lua'},
-- used by <pthread.h> <sys/signal.h>
{inc='<sys/_types/_sigset_t.h>', out='OSX/c/sys/_types/_sigset_t.lua'},
-- used by <unistd.h> <sys/signal.h>
{inc='<sys/_types/_uid_t.h>', out='OSX/c/sys/_types/_uid_t.lua'},
-- used by <signal.h> <stdlib.h>
{inc='<sys/signal.h>', out='OSX/c/sys/signal.lua'},
-- used by <wchar.h> <stdlib.h>
{inc='<sys/_types/_ct_rune_t.h>', out='OSX/c/sys/_types/_ct_rune_t.lua'},
-- used by <wchar.h> <stdlib.h>
{inc='<sys/_types/_rune_t.h>', out='OSX/c/sys/_types/_rune_t.lua'},
-- used by <wchar.h> <stdlib.h>
{inc='<sys/_types/_wchar_t.h>', out='OSX/c/sys/_types/_wchar_t.lua'},
-- used by <stdint.h> <stdlib.h>
{inc='<_types/_uint8_t.h>', out='OSX/c/_types/_uint8_t.lua'},
-- used by <stdint.h> <stdlib.h>
{inc='<_types/_uint16_t.h>', out='OSX/c/_types/_uint16_t.lua'},
-- used by <stdint.h> <stdlib.h>
{inc='<_types/_uint32_t.h>', out='OSX/c/_types/_uint32_t.lua'},
-- used by <stdint.h> <stdlib.h>
{inc='<_types/_uint64_t.h>', out='OSX/c/_types/_uint64_t.lua'},
-- used by <stdint.h> <stdlib.h>
{inc='<_types/_intmax_t.h>', out='OSX/c/_types/_intmax_t.lua'},
-- used by <stdint.h> <stdlib.h>
{inc='<_types/_uintmax_t.h>', out='OSX/c/_types/_uintmax_t.lua'},
-- used by <fcntl.h> <stdlib.h>
{inc='<sys/_types/_mode_t.h>', out='OSX/c/sys/_types/_mode_t.lua'},
-- used by <fcntl.h> <stdio.h>
{inc='<sys/_types/_off_t.h>', out='OSX/c/sys/_types/_off_t.lua'},
-- used by <fcntl.h> <time.h>
{inc='<sys/_types/_timespec.h>', out='OSX/c/sys/_types/_timespec.lua'},
-- used by <unistd.h> <stdio.h>
{inc='<_ctermid.h>', out='OSX/c/_ctermid.lua'},
-- used by <unistd.h> <stdlib.h>
{inc='<sys/_types/_timeval.h>', out='OSX/c/sys/_types/_timeval.lua'},
-- used by <unistd.h> <time.h>
{inc='<sys/_types/_time_t.h>', out='OSX/c/sys/_types/_time_t.lua'},
-- used by <unistd.h> <stdlib.h>
{inc='<sys/_types/_dev_t.h>', out='OSX/c/sys/_types/_dev_t.lua'},
-- used by <sys/select.h> <unistd.h>
{inc='<sys/_types/_fd_def.h>', out='OSX/c/sys/_types/_fd_def.lua'},
-- used by <sys/select.h> <unistd.h>
{inc='<sys/_types/_suseconds_t.h>', out='OSX/c/sys/_types/_suseconds_t.lua'},
-- used by <sys/select.h> <unistd.h>
{inc='<sys/_select.h>', out='OSX/c/sys/_select.lua'},
-- used by <sys/stat.h> <dirent.h>
{inc='<sys/_types/_ino_t.h>', out='OSX/c/sys/_types/_ino_t.lua'},
-- used by <sys/stat.h> <unistd.h>
{inc='<sys/_types/_gid_t.h>', out='OSX/c/sys/_types/_gid_t.lua'},
-- used by <sys/stat.h> <fcntl.h>
{inc='<sys/_types/_filesec_t.h>', out='OSX/c/sys/_types/_filesec_t.lua'},
-- used by <sys/types.h> <stdlib.h>
{inc='<machine/endian.h>', out='OSX/c/machine/endian.lua'},
-- used by <sys/types.h> <sys/stat.h>
{inc='<sys/_types/_blkcnt_t.h>', out='OSX/c/sys/_types/_blkcnt_t.lua'},
-- used by <sys/types.h> <sys/stat.h>
{inc='<sys/_types/_blksize_t.h>', out='OSX/c/sys/_types/_blksize_t.lua'},
-- used by <sys/types.h> <sys/stat.h>
{inc='<sys/_types/_ino64_t.h>', out='OSX/c/sys/_types/_ino64_t.lua'},
-- used by <sys/types.h> <sys/stat.h>
{inc='<sys/_types/_nlink_t.h>', out='OSX/c/sys/_types/_nlink_t.lua'},
-- used by <sys/types.h> <stdlib.h>
{inc='<sys/_types/_id_t.h>', out='OSX/c/sys/_types/_id_t.lua'},
-- used by <sys/types.h> <time.h>
{inc='<sys/_types/_clock_t.h>', out='OSX/c/sys/_types/_clock_t.lua'},
-- used by <sys/types.h> <unistd.h>
{inc='<sys/_types/_useconds_t.h>', out='OSX/c/sys/_types/_useconds_t.lua'},
-- used by <sys/types.h> <string.h>
{inc='<sys/_types/_rsize_t.h>', out='OSX/c/sys/_types/_rsize_t.lua'},
-- used by <pthread.h> <signal.h>
{inc='<sys/_pthread/_pthread_t.h>', out='OSX/c/sys/_pthread/_pthread_t.lua'},
-- used by <sched.h> <pthread.h>
{inc='<pthread/pthread_impl.h>', out='OSX/c/pthread/pthread_impl.lua'},
-- used by <sys/types.h> <pthread.h>
{inc='<sys/_pthread/_pthread_cond_t.h>', out='OSX/c/sys/_pthread/_pthread_cond_t.lua'},
-- used by <sys/types.h> <pthread.h>
{inc='<sys/_pthread/_pthread_condattr_t.h>', out='OSX/c/sys/_pthread/_pthread_condattr_t.lua'},
-- used by <sys/types.h> <pthread.h>
{inc='<sys/_pthread/_pthread_mutex_t.h>', out='OSX/c/sys/_pthread/_pthread_mutex_t.lua'},
-- used by <sys/types.h> <pthread.h>
{inc='<sys/_pthread/_pthread_mutexattr_t.h>', out='OSX/c/sys/_pthread/_pthread_mutexattr_t.lua'},
-- used by <sys/types.h> <pthread.h>
{inc='<sys/_pthread/_pthread_once_t.h>', out='OSX/c/sys/_pthread/_pthread_once_t.lua'},
-- used by <sys/types.h> <pthread.h>
{inc='<sys/_pthread/_pthread_rwlock_t.h>', out='OSX/c/sys/_pthread/_pthread_rwlock_t.lua'},
-- used by <sys/types.h> <pthread.h>
{inc='<sys/_pthread/_pthread_rwlockattr_t.h>', out='OSX/c/sys/_pthread/_pthread_rwlockattr_t.lua'},
-- used by <sys/types.h> <pthread.h>
{inc='<sys/_pthread/_pthread_key_t.h>', out='OSX/c/sys/_pthread/_pthread_key_t.lua'},
-- used by <wchar.h> <ctype.h>
{inc='<sys/_types/_wint_t.h>', out='OSX/c/sys/_types/_wint_t.lua'},
----------------------- ISO/POSIX STANDARDS: -----------------------
------------ ISO/IEC 9899:1990 (C89, C90) ------------
-- in list: Linux OSX
-- included by SDL/SDL_stdinc.h
{inc='<ctype.h>', out='OSX/c/ctype.lua',
macros={
'_DONT_USE_CTYPE_INLINE_'
},
},
-- in list: Windows Linux OSX
{
inc='<stddef.h>',
out='OSX/c/stddef.lua',
},
-- in list: Windows Linux OSX
{
inc='<string.h>',
out='OSX/c/string.lua',
final = function(code)
code = removeEnum(code, '_USE_FORTIFY_LEVEL = 2')
return code
end,
},
-- in list: Windows Linux OSX
{
inc = '<time.h>',
out = 'OSX/c/time.lua',
final = function(code)
code = removeAttrAvailability(code)
return code
end,
},
-- in list: Windows Linux OSX
{
inc = '<errno.h>',
out = 'OSX/c/errno.lua',
final = function(code)
-- manually add the 'errno' macro at the end:
code = code .. [[
local wrapper = setmetatable({
errno = function()
return ffi.C.__error()[0]
end,
str = function()
require 'ffi.req' 'c.string' -- strerror
local sp = ffi.C.strerror(wrapper.errno())
if sp == nil then return '(null)' end
return ffi.string(sp)
end,
}, {
__index = ffi.C,
})
return wrapper
]]
return code
end,
},
-- ISO/IEC 9899:1999 (C99)
-- ... but it has to go above <stdlib.h>
-- in list: Windows Linux OSX
{
inc='<stdint.h>',
out='OSX/c/stdint.lua',
final = function(code)
-- also in wchar.h
code = removeEnum(code, 'WCHAR_MAX = 2147483647')
-- if you want these then they have to go in the end as a wrapper, like in limits.h
code = removeEnum(code, 'INT64_MAX = 9223372036854775807')
code = removeEnum(code, 'UINT64_MAX = 18446744073709551615')
code = removeEnum(code, 'INT_LEAST64_MAX = 9223372036854775807')
code = removeEnum(code, 'UINT_LEAST64_MAX = 18446744073709551615')
code = removeEnum(code, 'INT_FAST64_MAX = 9223372036854775807')
code = removeEnum(code, 'UINT_FAST64_MAX = 18446744073709551615')
code = removeEnum(code, 'INTPTR_MAX = 9223372036854775807')
code = removeEnum(code, 'UINTPTR_MAX = 18446744073709551615')
code = removeEnum(code, 'SIZE_MAX = 18446744073709551615')
return code
end,
},
-- in list: Windows Linux OSX
{
inc = '<stdlib.h>',
out = 'OSX/c/stdlib.lua',
final = function(code)
code = removeAttrAvailability(code)
return code
end,
},
-- in list: Windows Linux OSX
{inc='<limits.h>', out='OSX/c/limits.lua', final=function(code)
code = removeEnum(code, 'SSIZE_MAX = 9223372036854775807')
code = removeEnum(code, 'QUAD_MAX = 9223372036854775807')
code = removeEnum(code, 'LONG_MAX = 9223372036854775807')
code = removeEnum(code, 'LLONG_MAX = 9223372036854775807')
code = removeEnum(code, 'LONG_LONG_MAX = 9223372036854775807')
code = removeEnum(code, 'OFF_MAX = 9223372036854775807')
code = table{
code,
[[
-- add in values that can't be ffi.cdef enum'd
local wrapper = setmetatable({}, {__index=ffi.C})
wrapper.LONG_MAX = 0x7FFFFFFFFFFFFFFFLL
wrapper.LONG_MIN = -wrapper.LONG_MAX - 1LL
wrapper.ULONG_MAX = 0xFFFFFFFFFFFFFFFFULL
wrapper.LLONG_MAX = wrapper.LONG_MAX
wrapper.LONG_LONG_MIN = wrapper.LONG_MIN
wrapper.LONG_LONG_MAX = wrapper.LONG_MAX
wrapper.LLONG_MIN = wrapper.LONG_MIN
return wrapper
]],
}:concat'\n'
return code
end},
-- in list: Windows Linux OSX
{inc='<setjmp.h>', out='OSX/c/setjmp.lua'},
-- in list: Windows Linux OSX
{inc='<stdarg.h>', out='OSX/c/stdarg.lua'},
-- in list: Windows Linux OSX
{
inc = '<stdio.h>',
out = 'OSX/c/stdio.lua',
final = function(code)
code = replace_SEEK(code)
code = removeEnum(code, '_USE_FORTIFY_LEVEL = 2')
code = code .. [[
-- special case since in the browser app where I'm capturing fopen for remote requests and caching
-- feel free to not use the returend table and just use ffi.C for faster access
-- but know you'll be losing compatability with browser
return setmetatable({}, {
__index = ffi.C,
})
]]
return code
end,
},
-- in list: Linux OSX
{
inc = '<math.h>',
out = 'OSX/c/math.lua',
final = function(code)
-- idk how to handle luajit and _Float16 for now so ...
code = string.split(code, '\n'):filter(function(l)
return not l:find'_Float16'
end):concat'\n'
-- [[ remove defines of floats
code = removeEnum(code, string.patescape'M_E = 2.71828182845904523536028747135266250')
code = removeEnum(code, string.patescape'M_LOG2E = 1.44269504088896340735992468100189214')
code = removeEnum(code, string.patescape'M_LOG10E = 0.434294481903251827651128918916605082')
code = removeEnum(code, string.patescape'M_LN2 = 0.693147180559945309417232121458176568')
code = removeEnum(code, string.patescape'M_LN10 = 2.30258509299404568401799145468436421')
code = removeEnum(code, string.patescape'M_PI = 3.14159265358979323846264338327950288')
code = removeEnum(code, string.patescape'M_PI_2 = 1.57079632679489661923132169163975144')
code = removeEnum(code, string.patescape'M_PI_4 = 0.785398163397448309615660845819875721')
code = removeEnum(code, string.patescape'M_1_PI = 0.318309886183790671537767526745028724')
code = removeEnum(code, string.patescape'M_2_PI = 0.636619772367581343075535053490057448')
code = removeEnum(code, string.patescape'M_2_SQRTPI = 1.12837916709551257389615890312154517')
code = removeEnum(code, string.patescape'M_SQRT2 = 1.41421356237309504880168872420969808')
code = removeEnum(code, string.patescape'M_SQRT1_2 = 0.707106781186547524400844362104849039')
code = removeEnum(code, string.patescape'X_TLOSS = 1.41484755040568800000e+16')
code = table{
code,
[[
-- add in values that can't be ffi.cdef enum'd
local wrapper = setmetatable({}, {__index=ffi.C})
wrapper.M_E = 2.71828182845904523536028747135266250
wrapper.M_LOG2E = 1.44269504088896340735992468100189214
wrapper.M_LOG10E = 0.434294481903251827651128918916605082
wrapper.M_LN2 = 0.693147180559945309417232121458176568
wrapper.M_LN10 = 2.30258509299404568401799145468436421
wrapper.M_PI = 3.14159265358979323846264338327950288
wrapper.M_PI_2 = 1.57079632679489661923132169163975144
wrapper.M_PI_4 = 0.785398163397448309615660845819875721
wrapper.M_1_PI = 0.318309886183790671537767526745028724
wrapper.M_2_PI = 0.636619772367581343075535053490057448
wrapper.M_2_SQRTPI = 1.12837916709551257389615890312154517
wrapper.M_SQRT2 = 1.41421356237309504880168872420969808
wrapper.M_SQRT1_2 = 0.707106781186547524400844362104849039
wrapper.X_TLOSS = 1.41484755040568800000e+16
return wrapper
]],
}:concat'\n'
--]]
return code
end,
},
-- in list: Linux OSX
{
inc = '<signal.h>',
out = 'OSX/c/signal.lua',
final = function(code)
code = fixEnumsAndDefineMacrosInterleaved(code)
return code
end,
},
------------ ISO/IEC 9899:1990/Amd.1:1995 ------------
-- in list: Windows Linux OSX
-- depends on <stdio.h> <machine/_types.h>
{inc='<wchar.h>', out='OSX/c/wchar.lua'},
------------ ISO/IEC 9899:1999 (C99) ------------
-- in list: Windows Linux OSX
-- identical in windows linux osx ...
{
inc = '<stdbool.h>',
out = 'OSX/c/stdbool.lua',
final = function(code)
-- luajit has its own bools already defined
for _,k in ipairs{'true = 1', 'false = 0'} do
code = removeEnum(code, k)
end
return code
end,
},
-- in list: Linux OSX
-- depends on <machine/_types.h>
{inc='<inttypes.h>', out='OSX/c/inttypes.lua'},
-- in list: Windows Linux OSX
-- used by CBLAS
{
inc = '<complex.h>',
out = 'OSX/c/complex.lua',
final = function(code)
code = commentOutLine(code, 'enum { complex = 0 };')
return code
end,
},
------------ ISO/IEC 9045:2008 (POSIX 2008, Single Unix Specification) ------------
-- in list: Linux OSX
-- depends on <_types.h>
{
inc = '<dirent.h>',
out = 'OSX/c/dirent.lua',
final = function(code)
-- how come __BLOCKS__ is defined ...
-- TODO disable __BLOCKS__ to omit these:
code = string.split(code, '\n'):filter(function(l)
return not l:find'_b%('
end):concat'\n'
-- "invalid pack directive"
code = safegsub(code, [[
#pragma pack(4)
#pragma pack()
]], '')
return code
end,
},
-- depends on <_types.h> <sys/_types/_timespec.h> <machine/_types.h>
-- in list: Windows Linux OSX
{
inc = '<sys/stat.h>',
out = 'OSX/c/sys/stat.lua',
final = function(code)
code = code .. [[
local lib = ffi.C
local statlib = setmetatable({
struct_stat = 'struct stat',
}, {
__index = lib,
})
-- allow nils instead of errors if we access fields not present (for the sake of lfs_ffi)
ffi.metatype(statlib.struct_stat, {
__index = function(t,k)
return nil
end,
})
return statlib
]]
return code
end,
},
-- in list: Windows Linux OSX
{
inc='<fcntl.h>',
out='OSX/c/fcntl.lua',
final = function(code)
code = replace_SEEK(code)
-- these are in sys/stat and fcntl
code = safegsub(code, [[
enum { S_IFMT = 0170000 };
enum { S_IFIFO = 0010000 };
enum { S_IFCHR = 0020000 };
enum { S_IFDIR = 0040000 };
enum { S_IFBLK = 0060000 };
enum { S_IFREG = 0100000 };
enum { S_IFLNK = 0120000 };
enum { S_IFSOCK = 0140000 };
enum { S_IFWHT = 0160000 };
enum { S_IRWXU = 0000700 };
enum { S_IRUSR = 0000400 };
enum { S_IWUSR = 0000200 };
enum { S_IXUSR = 0000100 };
enum { S_IRWXG = 0000070 };
enum { S_IRGRP = 0000040 };
enum { S_IWGRP = 0000020 };
enum { S_IXGRP = 0000010 };
enum { S_IRWXO = 0000007 };
enum { S_IROTH = 0000004 };
enum { S_IWOTH = 0000002 };
enum { S_IXOTH = 0000001 };
enum { S_ISUID = 0004000 };
enum { S_ISGID = 0002000 };
enum { S_ISVTX = 0001000 };
enum { S_ISTXT = 0001000 };
enum { S_IREAD = 0000400 };
enum { S_IWRITE = 0000200 };
enum { S_IEXEC = 0000100 };
]],
"]] require 'ffi.req' 'c.sys.stat' ffi.cdef[[\n"
)
-- abstraction used by lfs_ffi
code = code .. [[
return ffi.C
]]
return code
end,
},
-- in list: Linux OSX
{inc='<sched.h>', out='OSX/c/sched.lua'},
-- in list: Linux OSX
{
inc = '<pthread.h>',
out = 'OSX/c/pthread.lua',
final = function(code)
code = removeAttrAvailability(code)
code = fixEnumsAndDefineMacrosInterleaved(code)
-- idk why this is duplicated ...
code = safegsub(code, string.patescape[[
struct sched_param { int sched_priority; char __opaque[4]; };
extern int sched_yield(void);
extern int sched_get_priority_min(int);
extern int sched_get_priority_max(int);
]],
"]] require 'ffi.req' 'c.sched' ffi.cdef[[\n"
)
return code
end,
},
-- in list: Linux OSX
{
inc = '<utime.h>',
out = 'OSX/c/utime.lua',
final = function(code)
code = code .. [[
return setmetatable({
struct_utimbuf = 'struct utimbuf',
}, {
__index = ffi.C,
})
]]
return code
end,
},
-- in list: Windows Linux OSX
{inc='<sys/mman.h>', out='OSX/c/sys/mman.lua'},
-- in list: Linux OSX
-- has to go above <unistd.h>
{
inc='<sys/select.h>',
out='OSX/c/sys/select.lua',
final = function(code)
-- also in sys/time.h
code = removeEnum(code, 'FD_SETSIZE = 1024')
return code
end,
},
-- in list: Windows Linux OSX
{
inc = '<unistd.h>',
out = 'OSX/c/unistd.lua',
final = function(code)
code = replace_SEEK(code)
code = removeEnum(code, '_POSIX_THREAD_KEYS_MAX = 128')
-- for interchangeability with Windows ...
code = code .. [[
return ffi.C
]]
return code
end,
},
-- in list: Linux OSX
-- depends on <sys/_types/_timespec.h> <sys/_types/_fd_def.h> <machine/_types.h>
{
inc = '<sys/time.h>',
out = 'OSX/c/sys/time.lua',
final = function(code)
code = fixEnumsAndDefineMacrosInterleaved(code)
return code
end,
},
-- in list: Windows Linux OSX
-- depends on <_types.h> <sys/_types/_fd_def.h> <machine/_types.h> <machine/endian.h>
{
inc='<sys/types.h>',
out='OSX/c/sys/types.lua',
final = function(code)
-- also in sys/time.h and sys/types.h and sys/select.h
code = removeEnum(code, 'FD_SETSIZE = 1024')
return code
end,
},
----------------------- OS-SPECIFIC & EXTERNALLY REQUESTED BY 3RD PARTY LIBRARIES: -----------------------
}:mapi(function(inc)
inc.os = 'OSX'
-- same as linux
local oldfinal = inc.final
inc.final = function(code)
--code = removeEnum(code, '__[_%w]* = [01]')
code = removeEnum(code, '__has_[_%w]* = [01]')
code = removeEnum(code, '__single = 1')
code = removeEnum(code, '__unsafe_indexable = 1')
code = removeEnum(code, '__null_terminated = 1')
code = removeEnum(code, '_[_%w]*_H = 1')
code = removeEnum(code, '_[_%w]*_H_ = 1')
code = removeEnum(code, '_[_%w]*_H__ = 1')
code = removeEnum(code, '_[_%w]*_T = 1') -- tempting ...
code = removeEnum(code, '__APPLE_[_%w]* = 1')
-- this is everywhere
code = safegsub(code,
'__asm%b()', function(s)
return (
s
:gsub('"_"', '') -- get rid of the first underscore I guess?
:gsub('" "', '')
)
end)
if oldfinal then code = oldfinal(code) end
return code
end
-- system includes want to save all macros
inc.saveAllMacros = true
return inc
end)