Class: SDL2::Struct
- Inherits:
-
FFI::Struct
- Object
- FFI::Struct
- SDL2::Struct
- Defined in:
- lib/sdl2.rb
Overview
FFI::Struct class with some useful additions.
Direct Known Subclasses
Audio::CVT, Audio::Spec, BlendModeStruct, Color, CommonEvent, ControllerAxisEvent, ControllerButtonEvent, ControllerDeviceEvent, Cursor, Display::Mode, DollarGestureEvent, DropEvent, EventFilterStruct, Finger, GameController, GameController::ButtonBind, Haptic, Haptic::Condition, Haptic::Constant, Haptic::Custom, Haptic::Direction, Haptic::LeftRight, Haptic::Periodic, Haptic::Ramp, JoyAxisEvent, JoyBallEvent, JoyButtonEvent, JoyDeviceEvent, JoyHatEvent, Joystick, JoystickGUID, KeyboardEvent, Keysym, MouseButtonEvent, MouseMotionEvent, MouseWheelEvent, MultiGestureEvent, OSEvent, Palette, QuitEvent, RWops, RWops::AndroidIO, RWops::Mem, RWops::STDIO, RWops::Unkown, RWops::WindowsIO, RWops::WindowsIO::Buffer, Renderer, RendererInfo, SDL2::SysWM::Info, SDL2::SysWM::Info::Cocoa, SDL2::SysWM::Info::DirectFB, SDL2::SysWM::Info::UIKit, SDL2::SysWM::Info::Win, SDL2::SysWM::Info::X11, SDL2::SysWM::Msg, SDL2::SysWM::Msg::Cocoa, SDL2::SysWM::Msg::DirectFB, SDL2::SysWM::Msg::UIKit, SDL2::SysWM::Msg::Win, SDL2::SysWM::Msg::X11, SysWMEvent, TTF::Font, TextEditingEvent, TextInputEvent, TouchFingerEvent, TypedPointer, UserEvent, Window, WindowEvent
Class Method Summary collapse
-
.release(pointer) ⇒ Object
A default release scheme is defined, but should be redefined where appropriate.
Instance Method Summary collapse
-
#==(other) ⇒ Object
Compare two structures by class and values.
-
#initialize(*args, &block) ⇒ Struct
constructor
Allows creation and use within block, automatically freeing pointer after block.
-
#inspect ⇒ Object
A human-readable representation of the struct and it’s values.
Constructor Details
#initialize(*args, &block) ⇒ Struct
Allows creation and use within block, automatically freeing pointer after block.
104 105 106 107 108 109 110 111 |
# File 'lib/sdl2.rb', line 104 def initialize(*args, &block) super(*args) if block_given? throw 'Release must be defined to use block' unless self.class.respond_to?(:release) yield self self.class.release(self.pointer) end end |
Class Method Details
.release(pointer) ⇒ Object
A default release scheme is defined, but should be redefined where appropriate.
114 115 116 |
# File 'lib/sdl2.rb', line 114 def self.release(pointer) pointer.free end |
Instance Method Details
#==(other) ⇒ Object
Compare two structures by class and values.
128 129 130 131 132 133 134 |
# File 'lib/sdl2.rb', line 128 def ==(other) return false unless self.class == other.class self.class.members.each do |field| return false unless self[field] == other[field] end true # return true if we get this far. end |
#inspect ⇒ Object
A human-readable representation of the struct and it’s values.
119 120 121 122 123 124 125 |
# File 'lib/sdl2.rb', line 119 def inspect report = "struct #{self.class.to_s}{" report += self.class.members.collect do |field| "#{field}->#{self[field].inspect}" end.join(' ') report += "}" end |