-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinclude-list-haiku.lua
More file actions
355 lines (298 loc) · 7.45 KB
/
include-list-haiku.lua
File metadata and controls
355 lines (298 loc) · 7.45 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
--[[
built with Termux, arm 32-bit
--]]
local table = require 'ext.table'
local string = require 'ext.string'
local util = require 'include.util'
local safegsub = util.safegsub
local removeEnum = util.removeEnum
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 };
]],
"]] require 'ffi.req' 'c.SEEK' ffi.cdef[[\n"
)
return code
end
return table{
----------------------- INTERNALLY REQUESTED: -----------------------
{
inc = '$notthere_1.h',
out = 'Haiku/c/SEEK.lua',
forcecode = [=[
local ffi = require 'ffi'
ffi.cdef[[
enum { SEEK_SET = 0 };
enum { SEEK_CUR = 1 };
enum { SEEK_END = 2 };
]]
]=],
},
-- used by a lot
{inc='<null.h>', out='Haiku/c/null.lua'},
-- used by <locale.h>
{inc='<locale_t.h>', out='Haiku/c/locale_t.lua'},
-- used by config/types.h
{inc='<config/HaikuConfig.h>', out='Haiku/c/config/HaikuConfig.lua'},
-- used by <sys/types.h>
{inc='<config/types.h>', out='Haiku/c/config/types.lua'},
-- used by string.h
{inc='<features.h>', out='Haiku/c/features.lua'},
----------------------- ISO/POSIX STANDARDS: -----------------------
------------ ISO/IEC 9899:1990 (C89, C90) ------------
{inc='<ctype.h>', out='Haiku/c/ctype.lua'},
-- used by <string.h>
{inc='<locale.h>', out='Haiku/c/locale.lua'},
-- used by sys/types.h
{
inc = '<stdint.h>',
out = 'Haiku/c/stdint.lua',
},
-- used by stdlib.h
-- used by sys/types.h
{inc='<stddef.h>', out='Haiku/c/stddef.lua'},
-- circular dependency with <time.h>
{
inc='<sys/types.h>',
out='Haiku/c/sys/types.lua',
},
{inc='<string.h>', out='Haiku/c/string.lua'},
{
inc='<limits.h>',
out='Haiku/c/limits.lua',
final = function(code)
code = removeEnum(code, 'DBL_MAX = .*')
code = removeEnum(code, 'LDBL_MAX = .*')
code = removeEnum(code, 'DBL_NORM_MAX = .*')
code = removeEnum(code, 'LDBL_NORM_MAX = .*')
code = 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.LLONG_MIN = wrapper.LONG_MIN
return wrapper
]]
return code
end,
},
-- used by sys/select.h
{
inc='<signal.h>',
out='Haiku/c/signal.lua',
},
-- circular dependency with sys/select.h
-- this uses time_t, but time.h defines it
{
--inc='<sys/time.h>',
inc='<sys/time.h>',
out='Haiku/c/sys/time.lua',
},
-- uses struct timespec and struct timeval
-- circular dependency with sys/time.h, but I'll put select first to be like include-list-android.lua
-- ISO/IEC 9045:2008 (POSIX 2008, Single Unix Specification)
{
-- use local to redirect to local sys/time.h, to redirect to local sys/types.h ...
inc='<sys/select.h>',
out='Haiku/c/sys/select.lua',
},
-- circular dependency with <sys/types.h>
{
-- use the local one which moved its typedefs into ./sys/types.h to prevent circular dependencies
inc='<time.h>',
out='Haiku/c/time.lua',
},
{
inc = '<errno.h>',
out = 'Haiku/c/errno.lua',
final = function(code)
-- manually add the 'errno' macro at the end:
code = code .. [[
local wrapper
wrapper = setmetatable({
errno = function()
return ffi.C.__errno()[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,
},
-- POSIX.1-2024 (IEEE Std 1003.1-2024, The Open Group Base Specifications Issue 8)
-- not in Haiku?
--{inc='<endian.h>', out='Haiku/c/endian.lua'},
{inc='<stdarg.h>', out='Haiku/c/stdarg.lua'},
{
inc = '<stdio.h>',
out = 'Haiku/c/stdio.lua',
final = function(code)
code = replace_SEEK(code)
-- for fopen overloading
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,
},
-- used by stdlib.h, uses signal.h
{inc='<sys/wait.h>', out='Haiku/c/sys/wait.lua'},
{inc='<stdlib.h>', out = 'Haiku/c/stdlib.lua'},
{inc='<setjmp.h>', out='Haiku/c/setjmp.lua'},
{
inc = '<math.h>',
out = 'Haiku/c/math.lua',
final = function(code)
code = code:gsub('enum { M_', '//%0')
return code
end,
},
------------ ISO/IEC 9899:1990/Amd.1:1995 ------------
-- I never needed it in Linux, until I got to SDL
{
inc = '<wchar.h>',
out = 'Haiku/c/wchar.lua',
},
------------ ISO/IEC 9899:1999 (C99) ------------
-- identical in windows linux osx ...
{
inc = '<stdbool.h>',
out = 'Haiku/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,
},
{inc='<inttypes.h>', out='Haiku/c/inttypes.lua'},
-- depends on bits/libc-header-start
-- '<identifier>' expected near '_Complex' at line 2
-- has to do with enum/define'ing the builtin word _Complex
{inc='<complex.h>', out='Haiku/c/complex.lua'},
------------ ISO/IEC 9045:2008 (POSIX 2008, Single Unix Specification) ------------
-- because lua.ext uses some ffi stuff, it says "attempt to redefine 'dirent' at line 2" for my load(path(...):read()) but not for require'results....'
{inc='<dirent.h>', out='Haiku/c/dirent.lua'},
-- used by fcntl.h
{
inc = '<sys/stat.h>',
out = 'Haiku/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,
},
-- used by fcntl.h
{
inc = '<unistd.h>',
out = 'Haiku/c/unistd.lua',
final = function(code)
code = replace_SEEK(code)
-- but for interchangeability with Windows ...
code = code .. [[
return ffi.C
]]
return code
end,
},
{
inc = '<fcntl.h>',
out = 'Haiku/c/fcntl.lua',
},
{
inc='<sched.h>',
out='Haiku/c/sched.lua',
},
{
inc='<bsd_pthread.h>',
out='Haiku/c/pthread.lua',
final = function(code)
code = code .. [[
return ffi.C
]]
return code
end,
},
{
inc = '<utime.h>',
out = 'Haiku/c/utime.lua',
final = function(code)
code = code .. [[
return setmetatable({
struct_utimbuf = 'struct utimbuf',
}, {
__index = ffi.C,
})
]]
return code
end,
},
{inc='<sys/mman.h>', out='Haiku/c/sys/mman.lua'},
----------------------- OS-SPECIFIC & EXTERNALLY REQUESTED BY 3RD PARTY LIBRARIES: -----------------------
{
inc = '<sys/socket.h>',
out = 'Haiku/c/sys/socket.lua',
},
{
inc = '<netinet/in.h>',
out = 'Haiku/c/netinet/in.lua',
},
{
inc = '<netdb.h>',
out = 'Haiku/c/netdb.lua',
},
{
inc = '<semaphore.h>',
out = 'Haiku/c/semaphore.lua',
final = function(code)
code = code .. [[
return ffi.C
]]
return code
end,
},
}:mapi(function(inc)
inc.os = 'Haiku'
local oldfinal = inc.final
inc.final = function(code)
-- do any final()'s to eveyrthing *here*
if oldfinal then code = oldfinal(code) end
return code
end
-- system includes want to save all macros
inc.saveAllMacros = true
return inc
end)