Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Preliminary support for Mac without rsdl.

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...
commit ef1d643a8324e22cafe0014a7611596948f9a65e 1 parent deede40
@jacius jacius authored
Showing with 49 additions and 0 deletions.
  1. +1 −0  lib/ruby-sdl-ffi/sdl.rb
  2. +48 −0 lib/ruby-sdl-ffi/sdl/mac.rb
View
1  lib/ruby-sdl-ffi/sdl.rb
@@ -59,6 +59,7 @@ def self.sdl_func( name, args, ret )
# because event and mouse depend on them, respectively.
%w{
+ mac
core
keyboard
video
View
48 lib/ruby-sdl-ffi/sdl/mac.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.