#run { set_build_options_dc(.{ do_output = false, write_added_strings = false }); print(".. generating bindings (platform: %)\n\n", OS); opts: Generate_Bindings_Options; opts.visitor = rl_enum_visitor; opts.generate_library_declarations = false; LIBRARY_NAME :: "raylib"; #if OS == .WINDOWS { array_add(*opts.libpaths, "win"); } else #if OS == .LINUX { array_add(*opts.libpaths, "linux"); } else #if OS == .MACOS { array_add(*opts.libpaths, "mac"); array_add(*opts.system_include_paths, "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include"); } else { assert(false, "unsupported OS: %", OS); } array_add(*opts.libnames, LIBRARY_NAME); array_add(*opts.source_files, "lib/raylib.h", "lib/raymath.h"); array_add(*opts.extra_clang_arguments, "-x", "c"); array_add(*opts.system_include_paths, GENERATOR_DEFAULT_SYSTEM_INCLUDE_PATH); assert(generate_bindings(opts, "raylib.jai"), "unable to generate bindings for raylib!"); libpaths := opts.libpaths; opts = .{}; opts.generate_library_declarations = false; opts.libpaths = libpaths; array_add(*opts.strip_prefixes, "rl", "RL"); array_add(*opts.libnames, LIBRARY_NAME); array_add(*opts.source_files, "lib/rlgl.h"); array_add(*opts.extra_clang_arguments, "-x", "c"); array_add(*opts.system_include_paths, GENERATOR_DEFAULT_SYSTEM_INCLUDE_PATH); assert(generate_bindings(opts, "./rlgl/rlgl.jai"), "unable to generate bindings for raylib!"); } rl_enum_visitor :: (decl: *Declaration, parent: *Declaration) -> Declaration_Visit_Result { replace_type :: (args: []*Declaration, arg_name: string, hardcoded_type: string) { for args if it.name == arg_name { change_type_to_enum(it, hardcoded_type); return; } } if decl.kind == { case .TYPEDEF; td := decl.(*Typedef); if td.name == { case "TraceLogCallback"; ptr := td.type.pointer_to; replace_type(ptr.type_of_function.arguments, "logLevel", "TraceLogLevel"); } case .FUNCTION; func := decl.(*Function); ftype := func.type.type_of_function; if func.name == { case "IsWindowState"; #through; case "SetWindowState"; #through; case "ClearWindowState"; replace_type(ftype.arguments, "flags", "ConfigFlags"); case "IsKeyPressed"; #through; case "IsKeyPressedRepeat"; #through; case "IsKeyDown"; #through; case "IsKeyReleased"; #through; case "IsKeyUp"; #through; case "SetExitKey"; replace_type(ftype.arguments, "key", "KeyboardKey"); case "IsGamepadButtonPressed"; #through; case "IsGamepadButtonDown"; #through; case "IsGamepadButtonReleased"; #through; case "IsGamepadButtonUp"; replace_type(ftype.arguments, "button", "GamepadButton"); case "GetGamepadAxisMovement"; replace_type(ftype.arguments, "axis", "GamepadAxis"); case "IsMouseButtonPressed"; #through; case "IsMouseButtonDown"; #through; case "IsMouseButtonReleased"; #through; case "IsMouseButtonUp"; replace_type(ftype.arguments, "button", "MouseButton"); case "IsGestureDetected"; replace_type(ftype.arguments, "gesture", "Gesture"); case "SetGesturesEnabled"; replace_type(ftype.arguments, "flags", "Gesture"); case "GetGestureDetected"; real := New(CType); real.hardcoded_jai_string = "Gesture"; ftype.return_type = real; case "UpdateCamera"; replace_type(ftype.arguments, "mode", "CameraMode"); case "LoadImageRaw"; #through; case "GetPixelColor"; #through; case "GetPixelDataSize"; #through; case "SetPixelColor"; replace_type(ftype.arguments, "format", "PixelFormat"); case "ImageFormat"; replace_type(ftype.arguments, "newFormat", "PixelFormat"); case "LoadTextureCubemap"; replace_type(ftype.arguments, "layout", "CubemapLayout"); case "SetTextureFilter"; replace_type(ftype.arguments, "filter", "TextureFilter"); case "SetTextureWrap"; replace_type(ftype.arguments, "wrap", "TextureWrap"); case "SetMaterialTexture"; replace_type(ftype.arguments, "mapType", "MaterialMapIndex"); } } return .STOP; }; #import "File"; #import "Basic"; #import "String"; #import "Compiler"; #import "Hash_Table"; #import "Bindings_Generator";