Skip to content

Commit

Permalink
Preliminary support for Mac without rsdl.
Browse files Browse the repository at this point in the history
This allows the normal ruby interpreter to create a window on
Mac OS X. No special interpreter (i.e. rsdl) is needed.
However, some SDL functions have memory leaks, so we should wrap
those functions in NS{Push,Pop}AutoreleasePool.

Eternal thanks to erisdiscord for pointing the way!
  • Loading branch information
jacius committed Jun 29, 2010
1 parent deede40 commit ef1d643
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/ruby-sdl-ffi/sdl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def self.sdl_func( name, args, ret )
# because event and mouse depend on them, respectively.

%w{
mac
core
keyboard
video
Expand Down
48 changes: 48 additions & 0 deletions lib/ruby-sdl-ffi/sdl/mac.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#--
#
# This file is one part of:
#
# Ruby-SDL-FFI - Ruby-FFI bindings to SDL
#
# Copyright (c) 2010 John Croisant
#
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
# without limitation the rights to use, copy, modify, merge, publish,
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
#
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#
#++

# A few bindings to Mac OS X's Cocoa framework to allow Ruby-SDL-FFI
# to create a window on Mac without a special Ruby interpreter (rsdl).
#
# Eternal thanks to erisdiscord for pointing the way!

if FFI::Platform.mac?
module SDL::Cocoa
extend NiceFFI::Library
load_library '/System/Library/Frameworks/Cocoa.framework/Cocoa'

func :NSApplicationLoad, [], :char

func :NSPushAutoreleasePool, [], :void
func :NSPopAutoreleasePool, [], :void

NSApplicationLoad()
NSPushAutoreleasePool()
end
end

0 comments on commit ef1d643

Please sign in to comment.