rbsdl3 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2ca77af0dc7dcc36ad74a55ba2004c4259e114b4ba7ac6d0101f1ea3b18e1007
4
+ data.tar.gz: f23967120fbe3f7b16c28f77ceecd334ad7514a26cbe06c4ac061dbb1e8735dc
5
+ SHA512:
6
+ metadata.gz: de75e9160dfeecbb13a7fe6381cf714af7e467fdaa4dafa3911a38c052f4915da88a48a5eab34f8c871abf831909aabfcdfd58403f5a0ee3d89e261a673d81cd
7
+ data.tar.gz: bc98624b5fc9540b64620179e4850425db7c7689ca2864805379c7e24ae0af2f84a7bcf622d3d9532b2a45de58d71d0332eae7ab1db59a1cf96ebc1b9a7dd8fb
data/CHANGELOG.md ADDED
@@ -0,0 +1,18 @@
1
+ # Changelog
2
+
3
+ ## [Unreleased]
4
+
5
+ ## [0.1.0] - 2025-12-31
6
+
7
+ ### Added
8
+ - Added SDL3 bindings built on `Fiddle::Importer`. Supports runtime linking via `dlload`, allowing the user to choose the target dynamic library at runtime.
9
+ - `require "rbsdl3"` makes the SDL3 core API available (functions, constants, structs, enums, etc.) by loading `rbsdl3/sdl` internally.
10
+ - Added optional extension entry points: `require "rbsdl3/image"` for SDL_image APIs and `require "rbsdl3/ttf"` for SDL_ttf APIs (both assume the SDL3 core is loaded).
11
+ - Added Ruby-side helpers that mirror a subset of SDL macros (C-style integer casts, FOURCC, version helpers, etc.).
12
+ - Added a stub/annotation mechanism for missing symbols and unsupported APIs: unresolved symbols raise `NotImplementedError`, and selected APIs can be explicitly marked as `unsupported:`.
13
+
14
+ ### Notes
15
+ - Dependencies: Ruby >= 3.1, fiddle ~> 1.1.7.
16
+ - Due to Fiddle limitations, some APIs raise `NotImplementedError`.
17
+ - SDL examples: `SDL_vsnprintf()` / `SDL_vasprintf()` / `SDL_SetErrorV()` / `SDL_LogMessageV()` / `SDL_IOvprintf()` / `SDL_GUIDToString()` / `SDL_StringToGUID()` / `SDL_SetGPUBlendConstants()`
18
+ - SDL_ttf examples: `TTF_RenderText_*` / `TTF_RenderGlyph_*`
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present shinokaro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # rbsdl3
2
+
3
+ rbsdl3 is a binding library for using SDL3 from Ruby. In addition to SDL3 itself, it also covers APIs from related libraries such as SDL_image and SDL_ttf. SDL dynamic libraries (DLL/so/dylib) are loaded explicitly by the user at runtime.
4
+
5
+ - SDL (official): https://www.libsdl.org/
6
+ - SDL3 Documentation (SDL Wiki): https://wiki.libsdl.org/SDL3/FrontPage
7
+
8
+ ## Features
9
+
10
+ - Built on Ruby’s standard library, Fiddle.
11
+ - Provides Ruby-side constants and struct definitions before any dynamic libraries are loaded.
12
+ - Once the dynamic libraries are loaded, SDL APIs are bound and can be called as methods.
13
+ - If an API symbol is not available at bind time, execution still continues; the corresponding method is defined as a stub that raises `NotImplementedError` when called.
14
+ - Bindings for related libraries can be added as needed, for example with `require "rbsdl3/image"`.
15
+
16
+ ## Scope
17
+
18
+ - Target: SDL3
19
+ - Related libraries: SDL_image / SDL_ttf (SDL_mixer will be supported after an official SDL_mixer release)
20
+
21
+ API coverage is not complete; some APIs may be unavailable.
22
+
23
+ Some SDL constants currently assume little-endian values. Inline functions are not included.
24
+
25
+ ## Requirements
26
+
27
+ rbsdl3 does not bundle SDL libraries. You must provide the SDL3 dynamic library (and, if you use them, the SDL_image / SDL_ttf dynamic libraries) separately.
28
+
29
+ SDL dynamic libraries are loaded explicitly at runtime via `SDL3.dlload` (for each library you intend to use). The library names passed to `dlload` are examples and may differ by platform.
30
+
31
+ ## Installation
32
+
33
+ Install the gem and add to the application's Gemfile by executing:
34
+
35
+ ```bash
36
+ bundle add rbsdl3
37
+ ```
38
+
39
+ If bundler is not being used to manage dependencies, install the gem by executing:
40
+
41
+ ```bash
42
+ gem install rbsdl3
43
+ ```
44
+
45
+ ## Usage
46
+
47
+ ### SDL3 (core)
48
+
49
+ With `require "rbsdl3"`, Ruby-side definitions such as constants and structs are available. Calling functions requires `SDL3.dlload`.
50
+
51
+ ```ruby
52
+ require "rbsdl3"
53
+ SDL3::SDL_MAJOR_VERSION
54
+
55
+ SDL3.SDL_GetVersion #=> raises NoMethodError (not bound yet)
56
+
57
+ SDL3.dlload("libSDL3") # e.g.
58
+ SDL3.SDL_GetVersion
59
+
60
+ include SDL3
61
+ SDL_GetVersion()
62
+ ```
63
+
64
+ ### Related libraries
65
+
66
+ Related library bindings are added by requiring them individually.
67
+
68
+ ```ruby
69
+ require "rbsdl3/image"
70
+ SDL3::SDL_IMAGE_MAJOR_VERSION
71
+ SDL3::SDL_MAJOR_VERSION
72
+
73
+ SDL3.dlload("libSDL3_image") # e.g.
74
+ SDL3.IMG_Version
75
+ SDL3.SDL_GetVersion
76
+
77
+ include SDL3
78
+ IMG_Version()
79
+ SDL_GetVersion()
80
+ ```
81
+
82
+ ### Callbacks / function pointers
83
+
84
+ ```ruby
85
+ require "rbsdl3"
86
+ SDL3.bind(SDL3::SDL_HitTest) { |win, area, data| 0 }
87
+ SDL3["SDL_HitTest"]
88
+ ```
89
+
90
+ ## Development
91
+
92
+ c2ffi (https://github.com/rpav/c2ffi) is used as the source of the AST output from which most bindings are mechanically generated. Macros are extracted from header files using a custom extraction tool, and macro functions are also automatically converted. Anything that cannot be handled by these methods is bound manually.
93
+
94
+ To fetch the latest SDL library releases used for generation, run:
95
+
96
+ - `rake sources:checkout:all`
97
+
98
+ The downloaded sources are stored under `tmp/` in the development directory.
99
+
100
+ To generate the binding code from the fetched sources, run:
101
+
102
+ - `rake bindings:generate:all`
103
+
104
+ ## Contributing
105
+
106
+ Bug reports are welcome on GitHub at https://github.com/shinokaro/rbsdl3.
107
+
108
+ If you find missing functions or macros, please open an issue with the corresponding SDL header/API details so they can be added.
109
+
110
+ ## License
111
+
112
+ rbsdl3 is licensed under the MIT License.
113
+
114
+ This project does not bundle SDL libraries. SDL3 and any related SDL_* libraries are separate projects and are distributed under their own licenses (zlib license).
@@ -0,0 +1,90 @@
1
+ # frozen_string_literal: true
2
+ require_relative "../rbsdl3"
3
+ require_relative "sdl"
4
+
5
+ module SDL3
6
+ using BindingsRefinement
7
+ SDL_image = proc {
8
+ # Ruby wrappers for SDL_image macros
9
+ #
10
+ const_set :SDL_IMAGE_MAJOR_VERSION, 3
11
+ const_set :SDL_IMAGE_MINOR_VERSION, 2
12
+ const_set :SDL_IMAGE_MICRO_VERSION, 4
13
+ const_set :SDL_IMAGE_VERSION, SDL_VERSIONNUM(SDL_IMAGE_MAJOR_VERSION, SDL_IMAGE_MINOR_VERSION, SDL_IMAGE_MICRO_VERSION)
14
+ module_function def SDL_IMAGE_VERSION_ATLEAST(x, y, z) = ((SDL_IMAGE_MAJOR_VERSION >= x) && (SDL_IMAGE_MAJOR_VERSION > x || SDL_IMAGE_MINOR_VERSION >= y) && (SDL_IMAGE_MAJOR_VERSION > x || SDL_IMAGE_MINOR_VERSION > y || SDL_IMAGE_MICRO_VERSION >= z))
15
+
16
+ # Fiddle declarations for SDL_image functions, structs, and enums
17
+ #
18
+ extern "int IMG_Version(void)"
19
+ extern "SDL_Surface * IMG_LoadTyped_IO(SDL_IOStream *, bool, char *)"
20
+ extern "SDL_Surface * IMG_Load(char *)"
21
+ extern "SDL_Surface * IMG_Load_IO(SDL_IOStream *, bool)"
22
+ extern "SDL_Texture * IMG_LoadTexture(SDL_Renderer *, char *)"
23
+ extern "SDL_Texture * IMG_LoadTexture_IO(SDL_Renderer *, SDL_IOStream *, bool)"
24
+ extern "SDL_Texture * IMG_LoadTextureTyped_IO(SDL_Renderer *, SDL_IOStream *, bool, char *)"
25
+ extern "bool IMG_isAVIF(SDL_IOStream *)"
26
+ extern "bool IMG_isICO(SDL_IOStream *)"
27
+ extern "bool IMG_isCUR(SDL_IOStream *)"
28
+ extern "bool IMG_isBMP(SDL_IOStream *)"
29
+ extern "bool IMG_isGIF(SDL_IOStream *)"
30
+ extern "bool IMG_isJPG(SDL_IOStream *)"
31
+ extern "bool IMG_isJXL(SDL_IOStream *)"
32
+ extern "bool IMG_isLBM(SDL_IOStream *)"
33
+ extern "bool IMG_isPCX(SDL_IOStream *)"
34
+ extern "bool IMG_isPNG(SDL_IOStream *)"
35
+ extern "bool IMG_isPNM(SDL_IOStream *)"
36
+ extern "bool IMG_isSVG(SDL_IOStream *)"
37
+ extern "bool IMG_isQOI(SDL_IOStream *)"
38
+ extern "bool IMG_isTIF(SDL_IOStream *)"
39
+ extern "bool IMG_isXCF(SDL_IOStream *)"
40
+ extern "bool IMG_isXPM(SDL_IOStream *)"
41
+ extern "bool IMG_isXV(SDL_IOStream *)"
42
+ extern "bool IMG_isWEBP(SDL_IOStream *)"
43
+ extern "SDL_Surface * IMG_LoadAVIF_IO(SDL_IOStream *)"
44
+ extern "SDL_Surface * IMG_LoadICO_IO(SDL_IOStream *)"
45
+ extern "SDL_Surface * IMG_LoadCUR_IO(SDL_IOStream *)"
46
+ extern "SDL_Surface * IMG_LoadBMP_IO(SDL_IOStream *)"
47
+ extern "SDL_Surface * IMG_LoadGIF_IO(SDL_IOStream *)"
48
+ extern "SDL_Surface * IMG_LoadJPG_IO(SDL_IOStream *)"
49
+ extern "SDL_Surface * IMG_LoadJXL_IO(SDL_IOStream *)"
50
+ extern "SDL_Surface * IMG_LoadLBM_IO(SDL_IOStream *)"
51
+ extern "SDL_Surface * IMG_LoadPCX_IO(SDL_IOStream *)"
52
+ extern "SDL_Surface * IMG_LoadPNG_IO(SDL_IOStream *)"
53
+ extern "SDL_Surface * IMG_LoadPNM_IO(SDL_IOStream *)"
54
+ extern "SDL_Surface * IMG_LoadSVG_IO(SDL_IOStream *)"
55
+ extern "SDL_Surface * IMG_LoadQOI_IO(SDL_IOStream *)"
56
+ extern "SDL_Surface * IMG_LoadTGA_IO(SDL_IOStream *)"
57
+ extern "SDL_Surface * IMG_LoadTIF_IO(SDL_IOStream *)"
58
+ extern "SDL_Surface * IMG_LoadXCF_IO(SDL_IOStream *)"
59
+ extern "SDL_Surface * IMG_LoadXPM_IO(SDL_IOStream *)"
60
+ extern "SDL_Surface * IMG_LoadXV_IO(SDL_IOStream *)"
61
+ extern "SDL_Surface * IMG_LoadWEBP_IO(SDL_IOStream *)"
62
+ extern "SDL_Surface * IMG_LoadSizedSVG_IO(SDL_IOStream *, int, int)"
63
+ extern "SDL_Surface * IMG_ReadXPMFromArray(char **)"
64
+ extern "SDL_Surface * IMG_ReadXPMFromArrayToRGB888(char **)"
65
+ extern "bool IMG_SaveAVIF(SDL_Surface *, char *, int)"
66
+ extern "bool IMG_SaveAVIF_IO(SDL_Surface *, SDL_IOStream *, bool, int)"
67
+ extern "bool IMG_SavePNG(SDL_Surface *, char *)"
68
+ extern "bool IMG_SavePNG_IO(SDL_Surface *, SDL_IOStream *, bool)"
69
+ extern "bool IMG_SaveJPG(SDL_Surface *, char *, int)"
70
+ extern "bool IMG_SaveJPG_IO(SDL_Surface *, SDL_IOStream *, bool, int)"
71
+ const_set :IMG_Animation, struct(
72
+ [
73
+ "int w",
74
+ "int h",
75
+ "int count",
76
+ "SDL_Surface **frames",
77
+ "int *delays",
78
+ ]
79
+ )
80
+ extern "IMG_Animation * IMG_LoadAnimation(char *)"
81
+ extern "IMG_Animation * IMG_LoadAnimation_IO(SDL_IOStream *, bool)"
82
+ extern "IMG_Animation * IMG_LoadAnimationTyped_IO(SDL_IOStream *, bool, char *)"
83
+ extern "void IMG_FreeAnimation(IMG_Animation *)"
84
+ extern "IMG_Animation * IMG_LoadGIFAnimation_IO(SDL_IOStream *)"
85
+ extern "IMG_Animation * IMG_LoadWEBPAnimation_IO(SDL_IOStream *)"
86
+ }
87
+ private_constant :SDL_image
88
+
89
+ SDL_image.call
90
+ end