-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathmkraylib.bas
More file actions
510 lines (474 loc) · 15.9 KB
/
mkraylib.bas
File metadata and controls
510 lines (474 loc) · 15.9 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
rem
rem generate a skelton main.cpp from json input
rem
tload "raylib/parser/raylib_api.json", s, 1
api = array(s)
func comparator(l, r)
local f1 = lower(l.name)
local f2 = lower(r.name)
return iff(f1 == f2, 0, iff(f1 > f2, 1, -1))
end
sort api("functions") use comparator(x, y)
func get_param_name(byref param)
local result
select case lower(trim(param.type))
case "alpha": result = "get_param_num"
case "audiostream": result = "get_audiostream_id"
case "boundingbox": result = "get_param_bounding_box"
case "bounds": result = "get_param_rect"
case "bool": result = "get_param_int"
case "camera": result = "get_camera_3d"
case "camera2d": result = "get_camera_2d"
case "camera3d": result = "get_camera_3d"
case "char *": result = "(char *)get_param_str"
case "color": result = "get_param_color"
case "const char *": result = "get_param_str"
case "const unsigned char *": result = "(const unsigned char *)get_param_str"
case "float": result = "get_param_num"
case "double": result = "get_param_num"
case "font": result = "get_font_id"
case "image": result = "get_image_id"
case "int": result = "get_param_int"
case "label": result = "get_param_str"
case "matrix": result = "get_matrix_id"
case "mesh": result = "get_mesh_id"
case "model": result = "get_model_id"
case "modelanimation": result = "get_model_animation_id"
case "music": result = "get_music_id"
case "npatchinfo": result = "get_param_npatch"
case "physicsbody": result = "get_physics_body_id"
case "ray": result = "get_param_ray"
case "rectangle": result = "get_param_rect"
case "rendertexture2d": result = "get_render_texture_id"
case "shader": result = "get_param_shader"
case "sound": result = "get_sound_id"
case "text": result = "get_param_str"
case "texture2d": result = "get_texture_id"
case "unsigned char *": result = "(unsigned char *)get_param_str"
case "unsigned int": result = "get_param_int"
case "vector2": result = "get_param_vec2"
case "vector3": result = "get_param_vec3"
case "vector4": result = "get_param_vec4"
case "wave": result = "get_wave_id"
case "camera *": result = "(Camera *)get_param_int_t"
case "color *": result = "(Color *)get_param_int_t"
case "image *": result = "get_image_id"
case "mesh *": result = "(Mesh *)get_param_int_t"
case "model *": result = "(Model *)get_param_int_t"
case "modelanimation *": result = "(ModelAnimation *)get_param_int_t"
case "modelanimation*": result = "(ModelAnimation *)get_param_int_t"
case "texture2d *": result = "(Texture2D *)get_param_int_t"
case "const vector2 *": result = "(Vector2 *)get_param_vec2_array"
case "const vector3 *": result = "(Vector3 *)get_param_vec3_array"
case "vector2 *": result = "(Vector2 *)get_param_vec2_array"
case "vector3 *": result = "(Vector3 *)get_param_vec3_array"
case "wave *": result = "(Wave *)get_param_int_t"
case "const void *": result = "(const void *)get_param_int_t"
case "float *": result = "(float *)get_param_int_t"
case "unsigned int *": result = "(unsigned int *)get_param_int_t"
case "int *": result = "(int *)0"
case "void *": result = "(void *)get_param_int_t"
case "const int *": result = "(const int *)get_param_int_t"
case "filepathlist": result = "get_param_filepathlist"
case "automationevent": result = "get_param_automationevent"
case "automationeventlist": result = "get_automationeventlist_id"
case "automationeventlist *": result = "get_automationeventlist_id"
case else: throw "unknown param [" + param.type + "]"
end select
return result
end
func has_default_param(byref param)
local name = get_param_name(param)
return instr(name, "get_param_int") > 0 || &
instr(name, "get_param_num") > 0 || &
instr(name, "get_param_str") > 0
end
func get_map_name(byref param)
local result
select case lower(trim(param.type))
case "audiostream": result = "_audioStream"
case "font": result = "_fontMap"
case "image": result = "_imageMap"
case "image *": result = "&_imageMap"
case "matrix": result = "_matrixMap"
case "mesh": result = "_meshMap"
case "model": result = "_modelMap"
case "modelanimation": result = "_modelAnimationMap"
case "music": result = "_musicMap"
case "physicsbody": result = "_physicsMap"
case "rendertexture2d": result = "_renderMap"
case "sound": result = "_soundMap"
case "texture2d": result = "_textureMap"
case "wave": result = "_waveMap"
case "automationeventlist": result = "_automationEventListMap"
case "automationeventlist *": result = "&_automationEventListMap"
case else: throw "unknown map [_" + param.type + "Map]"
end select
return result
end
func get_v_set_name(byref fun)
local result
select case lower(trim(fun.returnType))
case "audiostream": result = "v_setaudiostream"
case "bool": result = "v_setint"
case "boundingbox": result = "v_setboundingbox"
case "char *": result = "v_setstr"
case "color": result = "v_setcolor"
case "const char *": result = "v_setstr"
case "double": result = "v_setreal"
case "float": result = "v_setreal"
case "font": result = "v_setfont"
case "image": result = "v_setimage"
case "int": result = "v_setint"
case "long": result = "v_setint"
case "matrix": result = "v_setmatrix"
case "mesh": result = "v_setmesh"
case "model": result = "v_setmodel"
case "music": result = "v_setmusic"
case "physicsbody": result = "v_setphysics"
case "ray": result = "v_setray"
case "raycollision": result = "v_setraycollision"
case "rectangle": result = "v_setrect"
case "rendertexture2d": result = "v_setrendertexture2d"
case "shader": result = "v_setshader"
case "shader": result = "v_setshader"
case "sound": result = "v_setsound"
case "texturecubemap": result = "v_settexture2d"
case "texture2d": result = "v_settexture2d"
case "unsigned char *": result = "v_setstr"
case "unsigned int": result = "v_setint"
case "vector2": result = "v_setvec2"
case "vector3": result = "v_setvec3"
case "vector4": result = "v_setvec4"
case "wave": result = "v_setwave"
case "camera *": result = "v_setint"
case "color *": result = "v_setint"
case "image *": result = "v_setint"
case "mesh *": result = "v_setint"
case "model *": result = "v_setint"
case "modelanimation *": result = "v_setint"
case "modelanimation*": result = "v_setint"
case "texture2d *": result = "v_setint"
case "vector2 *": result = "v_setint"
case "vector3 *": result = "v_setint"
case "wave *": result = "v_setint"
case "const void *": result = "v_setint"
case "float *": result = "v_setint"
case "unsigned int *": result = "v_setint"
case "int *": result = "v_setint"
case "void *": result = "v_setint"
case "filepathlist": result = "v_setfilepathlist"
case "automationeventlist": result = "v_setautomationeventlist"
case "automationeventlist *": result = "v_setautomationeventlist"
case else: throw "unknown return [" + fun.returnType + "] "
end select
return result
end
func get_result_cast(byref fun)
local result
select case lower(trim(fun.returnType))
case "char *": result = "(const char *)"
case "const char *": result = "(const char *)"
case "unsigned char *": result = "(const char *)"
case "camera *": result = "(var_int_t)"
case "color *": result = "(var_int_t)"
case "image *": result = "(var_int_t)"
case "mesh *": result = "(var_int_t)"
case "model *": result = "(var_int_t)"
case "modelanimation *": result = "(var_int_t)"
case "modelanimation*": result = "(var_int_t)"
case "texture2d *": result = "(var_int_t)"
case "vector2 *": result = "(var_int_t)"
case "vector3 *": result = "(var_int_t)"
case "wave *": result = "(var_int_t)"
case "const void *": result = "(var_int_t)"
case "float *": result = "(var_int_t)"
case "unsigned int *": result = "(var_int_t)"
case "int *": result = "(var_int_t)"
case "void *": result = "(var_int_t)"
case else: result = ""
end select
return result
end
'
' When the result is returned in a map and fnResult value should be cleared
'
func get_cleanup_fn(byref fun)
local result = ""
select case lower(trim(fun.name))
case "loaddroppedfiles": result = " UnloadDroppedFiles(fnResult);"
end select
return result
end
'
' returns whether the function returns a string
'
func is_str_return(byref fun)
return fun.returnType != "void" and get_v_set_name(fun) == "v_setstr"
end
'
' returns the parameter argument for the RAYLIB call
'
func get_param_arg(byref param, byref fun)
local result
if (lower(trim(param.type)) == "int *" && is_str_return(fun)) then
result = "&" + param.name
else
result = param.name
end if
return result
end
'
' returns the arguments to the method that marshalls the input for one of the fields
'
func get_arg_arg(byref param, i)
local def_arg = iff(has_default_param(param), ", 0", "")
return "(argc, params, " + i + def_arg + ");"
end
func is_map_param(type)
return type == "AudioStream" || &
type == "Font" || &
type == "Image" || &
type == "Image *" || &
type == "Matrix" || &
type == "Mesh" || &
type == "Model" || &
type == "ModelAnimation" || &
type == "AutomationEventList" || &
type == "AutomationEventList *" || &
type == "Music" || &
type == "RenderTexture2D" || &
type == "Sound" || &
type == "Texture2D" || &
type == "Wave"
end
func has_map_param(byref fun)
local result = false
local param
for param in fun.params
if (is_map_param(param.type)) then
result = true
exit for
endif
next
return result
end
func is_unsupported_type(type)
return type == "const GlyphInfo *" || &
type == "AudioCallback" || &
type == "GlyphInfo *" || &
type == "GlyphInfo" || &
type == "LoadFileDataCallback" || &
type == "LoadFileTextCallback" || &
type == "Material *" || &
type == "Material" || &
type == "SaveFileDataCallback" || &
type == "SaveFileTextCallback" || &
type == "TraceLogCallback" || &
type == "VrStereoConfig" || &
type == "char **" || &
type == "const char **" || &
type == ""
end
'
' non-generated version in main.cpp
'
func is_internal(name)
return (name == "GetMeshBoundingBox" || &
name == "LoadModelAnimations" || &
name == "LoadRenderTexture" || &
name == "LoadShader" || &
name == "SetShaderValue" || &
name == "ImageKernelConvolution" || &
name == "TextFormat" || &
name == "TraceLog" || &
name == "UnloadDroppedFiles" || &
name == "UpdateCameraPro" || &
name == "UpdateCamera" || &
name == "UpdateTexture")
end
func is_unsupported(byref fun)
local result = false
local i = 0
local param
for param in fun.params
if (is_unsupported_type(param.type) || (instr(param.type, "*") > 0 and not param.type == "const char *")) then
rem print " // not generated: " + fun.name + " " + param.type
result = true
exit for
endif
next
if (is_unsupported_type(fun.returnType) || is_internal(fun.name)) then
result = true
endif
return result
end
sub print_description
print "//"
print "// " + fun.description
print "//"
end
sub print_var(indent, byref param, byref fun)
if (lower(trim(param.type)) == "int *") then
if (is_str_return(fun)) then
print indent + " auto " + param.name + " = 0;"
else
print indent + " auto " + param.name + " = (int *)0;"
endif
else
print indent + " auto " + param.name + " = " + get_param_name(param) + get_arg_arg(param, i)
endif
end
sub print_func_map(byref fun)
print_description
print "static int cmd_" + lower(fun.name) + "(int argc, slib_par_t *params, var_t *retval) {"
print " int result;"
local ifStatement = " if ("
local andClause = ""
local i = 0
local param
for param in fun.params
if (is_map_param(param.type)) then
print " int " + lower(param.name) + "_id = " + get_param_name(param) + "(argc, params, " + i + ", retval);"
ifStatement += andClause + lower(param.name) + "_id != -1"
andClause = " && "
endif
i++
next
print ifStatement + ") {"
i = 0
local args = ""
local strlenArg = 0
for param in fun.params
if (i > 0) then args += ", "
if (!is_map_param(param.type)) then
print_var(" ", param, fun)
args += get_param_arg(param, fun)
if (lower(trim(param.type)) == "int *") then
i--
if (is_str_return(fun)) then strlenArg = param.name
endif
else
args += get_map_name(param) + ".at(" + lower(param.name) + "_id)"
endif
i++
next
if (fun.returnType == "void") then
print " " + fun.name + "(" + args + ");"
if (instr(fun.name, "Unload") == 1) then
local map_name = get_map_name(fun.params[0])
if (left(map_name, 1) == "&") then map_name = mid(map_name, 2)
print " " + map_name + ".erase(" + lower(fun.params[0].name) + "_id);"
endif
else
print " auto fnResult = " + get_result_cast(fun) + fun.name + "(" + args + ");"
if (strlenArg) then
print " v_setstrn(retval, fnResult, " + strlenArg + ");"
print " MemFree((void *)fnResult);"
else
print " " + get_v_set_name(fun) + "(retval, " + "fnResult);"
endif
endif
print " result = 1;"
print " } else {"
print " result = 0;"
print " }"
print " return result;"
print "}"
print
end
sub print_func(byref fun)
print_description
print "static int cmd_" + lower(fun.name) + "(int argc, slib_par_t *params, var_t *retval) {"
local i = 0
local args = ""
local param
local strlenArg = 0
for param in fun.params
print_var("", param, fun)
if (i > 0) then args += ", "
args += get_param_arg(param, fun)
if (lower(trim(param.type)) == "int *") then
i--
if (is_str_return(fun)) then strlenArg = param.name
endif
i++
next
if (fun.returnType == "void") then
print " " + fun.name + "(" + args + ");"
else
print " auto fnResult = " + get_result_cast(fun) + fun.name + "(" + args + ");"
if (strlenArg) then
print " v_setstrn(retval, fnResult, " + strlenArg + ");"
print " MemFree((void *)fnResult);"
else
print " " + get_v_set_name(fun) + "(retval, fnResult);"
endif
local cleanup_fn = get_cleanup_fn(fun)
if (len(cleanup_fn) > 0) then print cleanup_fn
endif
print " return 1;"
print "}"
print
end
sub print_proc_main
local fun
for fun in api("functions")
if (fun.returnType == "void" and not is_unsupported(fun)) then
if (has_map_param(fun)) then
print_func_map(fun)
else
print_func(fun)
endif
endif
next
end
sub print_func_main
local fun, map_param
for fun in api("functions")
if (fun.returnType != "void" and not is_unsupported(fun)) then
if (has_map_param(fun)) then
print_func_map(fun)
else
print_func(fun)
endif
endif
next
end
sub print_def(proc_def)
local fun, n, param
for fun in api("functions")
if (((fun.returnType == "void") == proc_def) and not is_unsupported(fun)) then
n = iff(isarray(fun.params), len(fun.params), 0)
for param in fun.params
if (lower(trim(param.type)) == "int *") then n--
next
print " {" + n + ", " + n + ", \"" + upper(fun.name) + "\", cmd_" + lower(fun.name) + "},"
endif
next
end
sub print_unsupported()
local fun, description
print "Unimplemented APIs"
print "----------------"
print ""
print "| Name | Description |"
print "|---------|---------------|"
for fun in api("functions")
if (is_unsupported(fun) && !is_internal(fun.name)) then
description = iff(fun.description == 0, "n/a", fun.description)
print "| " + fun.name + " | " + description + " |"
endif
next
end
if trim(command) == "proc.h" then
print_proc_main
else if trim(command) == "proc-def.h" then
print_def(true)
elseif trim(command) == "func.h" then
print_func_main
else if trim(command) == "func-def.h" then
print_def(false)
else if trim(command) == "unsupported" then
print_unsupported()
endif