From e63a8fe4427058e4025194f9722665d3095d3f18 Mon Sep 17 00:00:00 2001 From: tricksterguy Date: Sun, 13 Feb 2011 05:26:14 +0000 Subject: [PATCH] new directory structure for ruby binding should compile and link fine under windows git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1797 4e206d99-4929-0410-ac5d-dfc041789085 --- bindings/ruby/Rakefile | 181 ++++++++++-------- bindings/ruby/sfml-audio/audio/main.cpp | 15 +- bindings/ruby/sfml-audio/audio/main.hpp | 2 +- .../ruby/sfml-graphics/graphics/Drawable.cpp | 2 +- bindings/ruby/sfml-graphics/graphics/main.cpp | 19 +- bindings/ruby/sfml-graphics/graphics/main.hpp | 2 +- bindings/ruby/sfml-system/system/main.cpp | 14 +- bindings/ruby/sfml-window/window/main.cpp | 14 +- bindings/ruby/sfml-window/window/main.hpp | 2 +- .../system => shared}/NonCopyable.cpp | 2 +- .../system => shared}/NonCopyable.hpp | 0 .../system => shared}/Vector2.cpp | 2 +- .../system => shared}/Vector2.hpp | 0 .../system => shared}/Vector3.cpp | 2 +- .../system => shared}/Vector3.hpp | 0 bindings/ruby/shared/global.cpp | 36 ++++ bindings/ruby/shared/global.hpp | 49 +++++ 17 files changed, 219 insertions(+), 123 deletions(-) rename bindings/ruby/{sfml-system/system => shared}/NonCopyable.cpp (99%) rename bindings/ruby/{sfml-system/system => shared}/NonCopyable.hpp (100%) rename bindings/ruby/{sfml-system/system => shared}/Vector2.cpp (99%) rename bindings/ruby/{sfml-system/system => shared}/Vector2.hpp (100%) rename bindings/ruby/{sfml-system/system => shared}/Vector3.cpp (99%) rename bindings/ruby/{sfml-system/system => shared}/Vector3.hpp (100%) create mode 100644 bindings/ruby/shared/global.cpp create mode 100644 bindings/ruby/shared/global.hpp diff --git a/bindings/ruby/Rakefile b/bindings/ruby/Rakefile index e21958653..cfd60eef4 100644 --- a/bindings/ruby/Rakefile +++ b/bindings/ruby/Rakefile @@ -11,54 +11,62 @@ include Rake # Configurable section RUBYSFML_VERSION = "2.0" SO_SRCS = {'audio' => FileList.new('sfml-audio/audio/*.cpp'), - 'graphics' => FileList.new('sfml-graphics/graphics/*.cpp'), - 'window' => FileList.new('sfml-window/window/*.cpp'), - 'system' => FileList.new('sfml-system/system/*.cpp'), - 'all' => FileList.new('sfml-all/all/*.cpp') } + 'graphics' => FileList.new('sfml-graphics/graphics/*.cpp'), + 'window' => FileList.new('sfml-window/window/*.cpp'), + 'system' => FileList.new('sfml-system/system/*.cpp'), + 'all' => FileList.new('sfml-all/all/*.cpp') } +OTHER_SRCS = FileList.new('shared/*.cpp') OBJDIR = 'obj' SODIR = 'sfml' spec = Gem::Specification.new do |s| - s.platform = Gem::Platform::CURRENT - s.name = "rbSFML" - s.version = RUBYSFML_VERSION - s.authors = ["Henrik Valter Vogelius Hansson", 'Brandon Whitehead'] - s.email = "groogy@groogy.se" - s.homepage = 'http://sfml-dev.org' - s.summary = "Ruby bindings for SFML 2.0" - s.has_rdoc = true - s.requirements << 'none' - s.require_path = '' - s.files = FileList.new do |fl| - fl.include("sfml-audio/audio/*.cpp", "sfml-audio/audio/*.hpp") - fl.include("sfml-graphics/graphics/*.cpp", "sfml-graphics/graphics/*.hpp") - fl.include("sfml-window/window/*.cpp", "sfml-window/window/*.hpp") - fl.include("sfml-system/system/*.cpp", "sfml-system/system/*.hpp") - fl.include("sfml-all/all/*.cpp", "sfml-all/all/*.hpp") - end - s.extensions = ["Rakefile"] - s.description = <<-EOF - rbSFML are bindings for the SFML library version 2.0 for Ruby. - SFML or Simple Fast Multimedia library is is a free multimedia C++ API - that provides you low and high level access to graphics, input, audio, etc. - EOF - s.extra_rdoc_files = FileList.new do |fl| - fl.include "doc/*.rdoc" - end + s.platform = Gem::Platform::CURRENT + s.name = "rbSFML" + s.version = RUBYSFML_VERSION + s.authors = ["Henrik Valter Vogelius Hansson", 'Brandon Whitehead'] + s.email = "groogy@groogy.se" + s.homepage = 'http://sfml-dev.org' + s.summary = "Ruby bindings for SFML 2.0" + s.has_rdoc = true + s.requirements << 'none' + s.require_path = '' + s.files = FileList.new do |fl| + fl.include("sfml-audio/audio/*.cpp", "sfml-audio/audio/*.hpp") + fl.include("sfml-graphics/graphics/*.cpp", "sfml-graphics/graphics/*.hpp") + fl.include("sfml-window/window/*.cpp", "sfml-window/window/*.hpp") + fl.include("sfml-system/system/*.cpp", "sfml-system/system/*.hpp") + fl.include("sfml-all/all/*.cpp", "sfml-all/all/*.hpp") + end + s.extensions = ["Rakefile"] + s.description = <<-EOF + rbSFML are bindings for the SFML library version 2.0 for Ruby. + SFML or Simple Fast Multimedia library is is a free multimedia C++ API + that provides you low and high level access to graphics, input, audio, etc. + EOF + s.extra_rdoc_files = FileList.new do |fl| + fl.include "doc/*.rdoc" + end end verbose(false) # Do not touch SO_OBJS = {} SO_SRCS.each do |file, list| - SO_OBJS[file] = list.collect { |fn| File.join("#{OBJDIR}/#{file}", File.basename(fn).ext('o')) } + SO_OBJS[file] = list.collect { |fn| File.join("#{OBJDIR}/#{file}", File.basename(fn).ext('o')) } end +OTHER_OBJS = OTHER_SRCS.collect {|fn| File.join("#{OBJDIR}/shared/#{file}", File.basename(fn).ext('o')) } + SO_LIBS = [] SO_SRCS.each_key {|file| SO_LIBS << "#{SODIR}/#{file}.so"} +SO_SRCS.each_key {|dir| CLEAN.include("#{OBJDIR}/#{dir}")} SO_OBJS.each_value {|list| CLEAN.include(list)} +CLEAN.include(OTHER_OBJS) +CLEAN.include("#{OBJDIR}/shared") +CLEAN.include(OBJDIR) + SO_LIBS.each {|so_file| CLOBBER.include(so_file)} -CLOBBER.include(OBJDIR, SODIR) +CLOBBER.include(SODIR) # Sets the default task to build @@ -74,11 +82,11 @@ desc "Uninstalls the generated files" task :uninstall task :clean do - puts "Cleaning out temporary generated files" + puts "Cleaning out temporary generated files" end task :clobber do - puts "Cleaning out all generated files" + puts "Cleaning out all generated files" end task :rebuild => [:clobber, :build] do @@ -89,18 +97,19 @@ Rake::GemPackageTask.new(spec) do |pkg| end RDoc::Task.new do |rd| - rd.title = "RSFML #{RUBYSFML_VERSION} Documentation" - rd.rdoc_files.include(SO_SRCS.values) - rd.options << '--line-numbers' << '--quiet' << '--all' - rd.rdoc_dir = "doc" + rd.title = "RSFML #{RUBYSFML_VERSION} Documentation" + rd.rdoc_files.include(SO_SRCS.values) + rd.options << '--line-numbers' << '--quiet' << '--all' + rd.rdoc_dir = "doc" end CFLAGS = CONFIG['CFLAGS'] CC = CONFIG['CC'] -INSTALL = CONFIG['INSTALL_PROGRAM'] +# CONFIG['INSTALL_PROGRAM'] +INSTALL = "install" LOCATION = CONFIG['sitearchdir'] + '/sfml' -RUBYSFML_INC = "sfml-system/system" +RUBYSFML_INC = "shared" SFML_INC = ENV.key?('SFML_INCLUDE') ? ENV['SFML_INCLUDE'] : '../../include' SFML_LIB = ENV.key?('SFML_LIB') ? ENV['SFML_LIB'] : '../../lib' SFML_LIBS = '-lsfml-audio -lsfml-graphics -lsfml-window -lsfml-system' @@ -108,60 +117,78 @@ RUBY_INC = CONFIG['rubyhdrdir'] RUBY_LIB = (CONFIG['ENABLE_SHARED'] == 'yes' ? CONFIG['LIBRUBYARG_SHARED'] : CONFIG['LIBRUBYARG_STATIC']) + ' ' + CONFIG['SOLIBS'] RUBY_LIB_PATH = CONFIG['libdir'] LINK = CONFIG['LDSHAREDXX'] +# Windows screws up this variable... LINK.sub!("$(if $(filter-out -g -g0,#{CONFIG["debugflags"]}),,-s)", '') LINK_FLAGS = CONFIG['DLDFLAGS'] + " " + CONFIG['LDFLAGS'] LINK_FLAGS.sub!("$(DEFFILE)", "") SO_SRCS.each_key {|dir| directory "#{OBJDIR}/#{dir}"} +directory "#{OBJDIR}/shared" directory SODIR directory LOCATION +OTHER_SRCS.each do |srcfile| + objdir = "#{OBJDIR}/shared" + objfile = File.join(objdir, File.basename(srcfile).ext('o')) + file objfile => [srcfile, objdir] do + puts "Compiling #{File.basename(srcfile)}" + sh "#{CC} #{CFLAGS} -c #{srcfile} -o #{objfile} -I#{SFML_INC} -I#{RUBY_INC} -I#{RUBY_INC}/#{CONFIG['arch']} -I#{RUBYSFML_INC}" + end +end + +task :shared => OTHER_OBJS + SO_SRCS.each do |so_file, list| - begin - list.each do |srcfile| - objdir = "#{OBJDIR}/#{so_file}" - objfile = File.join(objdir, File.basename(srcfile).ext('o')) - file objfile => [srcfile, objdir] do - puts "Compiling #{File.basename(srcfile)}" - sh "#{CC} #{CFLAGS} -c #{srcfile} -o #{objfile} -I#{SFML_INC} -I#{RUBY_INC} -I#{RUBY_INC}/#{CONFIG['arch']} -I#{RUBYSFML_INC}" - #p "#{CC} #{CFLAGS} -c #{srcfile} -o #{objfile} -I#{SFML_INC} -I#{RUBY_INC} -I#{RUBY_INC}/#{CONFIG['arch']} -I#{RUBYSFML_INC}" - end - end - rescue - end + begin + list.each do |srcfile| + objdir = "#{OBJDIR}/#{so_file}" + objfile = File.join(objdir, File.basename(srcfile).ext('o')) + file objfile => [srcfile, objdir] do + puts "Compiling #{File.basename(srcfile)}" + sh "#{CC} #{CFLAGS} -c #{srcfile} -o #{objfile} -I#{SFML_INC} -I#{RUBY_INC} -I#{RUBY_INC}/#{CONFIG['arch']} -I#{RUBYSFML_INC}" + #p "#{CC} #{CFLAGS} -c #{srcfile} -o #{objfile} -I#{SFML_INC} -I#{RUBY_INC} -I#{RUBY_INC}/#{CONFIG['arch']} -I#{RUBYSFML_INC}" + end + end + rescue + end end SO_OBJS.each do |so_file, objs| - begin - file "#{SODIR}/#{so_file}.so" => [*objs, SODIR] do - puts "Linking files to create #{so_file}.so" - #p "#{LINK} -o #{SODIR}/#{so_file}.so #{objs} -L. -L#{SFML_LIB} -L#{RUBY_LIB_PATH} #{LINK_FLAGS} #{RUBY_LIB} #{SFML_LIBS}" - sh "#{LINK} -o #{SODIR}/#{so_file}.so #{objs} -L. -L#{SFML_LIB} -L#{RUBY_LIB_PATH} #{LINK_FLAGS} #{RUBY_LIB} #{SFML_LIBS}" - end - rescue - end + begin + prestep = "pre#{so_file}".to_sym + task prestep do + puts "Creating #{so_file}.so" + end + file "#{SODIR}/#{so_file}.so" => [prestep, :shared, SODIR, *objs] do + puts "Linking files to create #{so_file}.so" + #p "#{LINK} -o #{SODIR}/#{so_file}.so #{objs} -L. -L#{SFML_LIB} -L#{RUBY_LIB_PATH} #{LINK_FLAGS} #{RUBY_LIB} #{SFML_LIBS}" + sh "#{LINK} -o #{SODIR}/#{so_file}.so #{objs} #{OTHER_OBJS} -L. -L#{SFML_LIB} -L#{RUBY_LIB_PATH} #{LINK_FLAGS} #{RUBY_LIB} #{SFML_LIBS}" + end + rescue + end end task :install => [:build, LOCATION] do - puts "Installing library" - begin - SO_SRCS.each_key do |so_file| - sh "#{INSTALL} #{SODIR}/#{so_file}.so #{LOCATION}" - end - rescue - end + puts "Installing library to #{LOCATION}" + begin + SO_SRCS.each_key do |so_file| + sh "#{INSTALL} #{SODIR}/#{so_file}.so #{LOCATION}" + end + rescue Exception=>e + p e + end end task :uninstall do - puts "Uninstalling library" - begin - SO_SRCS.each_key do |so_file| - sh "rm -f #{LOCATION}/#{so_file}.so" - end - sh "rm -rf #{LOCATION}" - rescue - end + puts "Uninstalling library to #{LOCATION}" + begin + SO_SRCS.each_key do |so_file| + sh "rm -f #{LOCATION}/#{so_file}.so" + end + sh "rm -rf #{LOCATION}" + rescue + end end - -task :build => SO_LIBS do + +task :build => [:shared, *SO_LIBS] do end diff --git a/bindings/ruby/sfml-audio/audio/main.cpp b/bindings/ruby/sfml-audio/audio/main.cpp index aa2aea923..1ff87e94c 100644 --- a/bindings/ruby/sfml-audio/audio/main.cpp +++ b/bindings/ruby/sfml-audio/audio/main.cpp @@ -21,13 +21,10 @@ */ #include "main.hpp" - -VALUE globalSFMLNamespace; - -/* External classes */ -VALUE globalVector2Class; -VALUE globalVector3Class; -VALUE globalNonCopyableModule; +#include "global.hpp" +#include "Vector2.hpp" +#include "Vector3.hpp" +#include "NonCopyable.hpp" static bool CheckDependencies( void ) { @@ -47,8 +44,8 @@ void Init_audio( void ) { rb_raise( rb_eRuntimeError, "This module depends on sfml-window" ); } - globalVector2Class = RetrieveSFMLClass( "Vector2" ); + /*globalVector2Class = RetrieveSFMLClass( "Vector2" ); globalVector3Class = RetrieveSFMLClass( "Vector3" ); - globalNonCopyableModule = RetrieveSFMLClass( "NonCopyable" ); + globalNonCopyableModule = RetrieveSFMLClass( "NonCopyable" );*/ rb_define_const(globalSFMLNamespace, "AudioLoaded", Qtrue); } diff --git a/bindings/ruby/sfml-audio/audio/main.hpp b/bindings/ruby/sfml-audio/audio/main.hpp index 9d21b46c7..73c672d46 100644 --- a/bindings/ruby/sfml-audio/audio/main.hpp +++ b/bindings/ruby/sfml-audio/audio/main.hpp @@ -24,7 +24,7 @@ #define SFML_RUBYEXT_AUDIO_MAIN_HEADER_ #include "ruby.h" -#include "../../sfml-system/system/main.hpp" +#include "global.hpp" // Ruby initiation function extern "C" void Init_audio( void ); diff --git a/bindings/ruby/sfml-graphics/graphics/Drawable.cpp b/bindings/ruby/sfml-graphics/graphics/Drawable.cpp index 05a0fcd5b..3633b5c9b 100644 --- a/bindings/ruby/sfml-graphics/graphics/Drawable.cpp +++ b/bindings/ruby/sfml-graphics/graphics/Drawable.cpp @@ -470,7 +470,7 @@ static VALUE Drawable_TransformToLocal( VALUE self, VALUE aPoint ) */ static VALUE Drawable_TransformToGlobal( VALUE self, VALUE aPoint ) { - VALUE point = Vector2_ForceType( point ); + VALUE point = Vector2_ForceType(point); rbDrawable *object = NULL; Data_Get_Struct( self, rbDrawable, object ); sf::Vector2f newPoint = object->TransformToGlobal( sf::Vector2f( NUM2DBL( Vector2_GetX( point ) ), diff --git a/bindings/ruby/sfml-graphics/graphics/main.cpp b/bindings/ruby/sfml-graphics/graphics/main.cpp index 28b53ff5a..9779ad254 100644 --- a/bindings/ruby/sfml-graphics/graphics/main.cpp +++ b/bindings/ruby/sfml-graphics/graphics/main.cpp @@ -21,6 +21,9 @@ */ #include "main.hpp" +#include "Vector2.hpp" +#include "Vector3.hpp" +#include "NonCopyable.hpp" #include "Color.hpp" #include "Rect.hpp" #include "Drawable.hpp" @@ -39,14 +42,10 @@ #include -VALUE globalSFMLNamespace; VALUE globalBlendNamespace; /* External classes */ -VALUE globalVector2Class; -VALUE globalVector3Class; VALUE globalWindowClass; -VALUE globalNonCopyableModule; static bool CheckDependencies( void ) { @@ -71,19 +70,19 @@ static void CreateBlendEnum( void ) void Init_graphics( void ) { /* SFML namespace which contains the classes of this module. */ - globalSFMLNamespace = rb_define_module( "SFML" ); + /*globalSFMLNamespace = rb_define_module( "SFML" );*/ if( CheckDependencies() == false ) { rb_raise( rb_eRuntimeError, "This module depends on sfml-window" ); } - globalVector2Class = RetrieveSFMLClass( "Vector2" ); - globalVector3Class = RetrieveSFMLClass( "Vector3" ); + /*globalVector2Class = RetrieveSFMLClass( "Vector2" ); + globalVector3Class = RetrieveSFMLClass( "Vector3" );*/ globalWindowClass = RetrieveSFMLClass( "Window" ); - globalNonCopyableModule = RetrieveSFMLClass( "NonCopyable" ); + /*globalNonCopyableModule = RetrieveSFMLClass( "NonCopyable" );*/ rb_define_const(globalSFMLNamespace, "GraphicsLoaded", Qtrue); - + CreateBlendEnum(); - + Init_Color(); Init_Rect(); Init_Drawable(); diff --git a/bindings/ruby/sfml-graphics/graphics/main.hpp b/bindings/ruby/sfml-graphics/graphics/main.hpp index c33fc1f2e..a9ade25cd 100644 --- a/bindings/ruby/sfml-graphics/graphics/main.hpp +++ b/bindings/ruby/sfml-graphics/graphics/main.hpp @@ -24,7 +24,7 @@ #define SFML_RUBYEXT_GRAPHICS_MAIN_HEADER_ #include "ruby.h" -#include "../../sfml-system/system/main.hpp" +#include "global.hpp" // Ruby initiation function extern "C" void Init_graphics( void ); diff --git a/bindings/ruby/sfml-system/system/main.cpp b/bindings/ruby/sfml-system/system/main.cpp index 6f12fadf7..489a158e4 100644 --- a/bindings/ruby/sfml-system/system/main.cpp +++ b/bindings/ruby/sfml-system/system/main.cpp @@ -21,24 +21,12 @@ */ #include "main.hpp" +#include "global.hpp" #include "Clock.hpp" #include "Vector2.hpp" #include "Vector3.hpp" #include "NonCopyable.hpp" -VALUE globalSFMLNamespace; - -VALUE RetrieveSFMLClass( const char * aName ) -{ - ID name = rb_intern( aName ); - if( rb_cvar_defined( globalSFMLNamespace, name ) == Qfalse ) - { - rb_raise( rb_eRuntimeError, "This module depends on SFML::%s", aName ); - } - - return rb_cvar_get( globalSFMLNamespace, name ); -} - void Init_system( void ) { /* SFML namespace which contains the classes of this module. */ diff --git a/bindings/ruby/sfml-window/window/main.cpp b/bindings/ruby/sfml-window/window/main.cpp index 81a880bd7..b238b1a46 100644 --- a/bindings/ruby/sfml-window/window/main.cpp +++ b/bindings/ruby/sfml-window/window/main.cpp @@ -21,6 +21,8 @@ */ #include "main.hpp" +#include "Vector2.hpp" +#include "NonCopyable.hpp" #include "Context.hpp" #include "ContextSettings.hpp" #include "Event.hpp" @@ -33,15 +35,12 @@ #include /* SFML Namespace which contains all classes in this module. */ -VALUE globalSFMLNamespace; VALUE globalKeyNamespace; VALUE globalMouseNamespace; VALUE globalJoyNamespace; VALUE globalStyleNamespace; - -/* External classes */ -VALUE globalVector2Class; -VALUE globalNonCopyableModule; +extern VALUE globalVector2Class; +extern VALUE globalNonCopyableModule; static const char * keyNamesMisc[] = { @@ -163,8 +162,9 @@ void Init_window( void ) rb_raise( rb_eRuntimeError, "This module depends on sfml-system" ); } - globalVector2Class = RetrieveSFMLClass( "Vector2" ); - globalNonCopyableModule = RetrieveSFMLClass( "NonCopyable" ); + + globalVector2Class = rb_define_class_under(globalSFMLNamespace, "Vector2", rb_cObject ); + globalNonCopyableModule = rb_define_module_under(globalSFMLNamespace, "NonCopyable"); rb_define_const( globalSFMLNamespace, "WindowLoaded", Qtrue ); diff --git a/bindings/ruby/sfml-window/window/main.hpp b/bindings/ruby/sfml-window/window/main.hpp index acf65fe46..342a2a310 100644 --- a/bindings/ruby/sfml-window/window/main.hpp +++ b/bindings/ruby/sfml-window/window/main.hpp @@ -24,7 +24,7 @@ #define SFML_RUBYEXT_WINDOW_MAIN_HEADER_ #include "ruby.h" -#include "../../sfml-system/system/main.hpp" +#include "global.hpp" // Ruby initiation function extern "C" void Init_window( void ); diff --git a/bindings/ruby/sfml-system/system/NonCopyable.cpp b/bindings/ruby/shared/NonCopyable.cpp similarity index 99% rename from bindings/ruby/sfml-system/system/NonCopyable.cpp rename to bindings/ruby/shared/NonCopyable.cpp index f1035f78b..243ce06af 100644 --- a/bindings/ruby/sfml-system/system/NonCopyable.cpp +++ b/bindings/ruby/shared/NonCopyable.cpp @@ -21,7 +21,7 @@ */ #include "NonCopyable.hpp" -#include "main.hpp" +#include "global.hpp" VALUE globalNonCopyableModule; diff --git a/bindings/ruby/sfml-system/system/NonCopyable.hpp b/bindings/ruby/shared/NonCopyable.hpp similarity index 100% rename from bindings/ruby/sfml-system/system/NonCopyable.hpp rename to bindings/ruby/shared/NonCopyable.hpp diff --git a/bindings/ruby/sfml-system/system/Vector2.cpp b/bindings/ruby/shared/Vector2.cpp similarity index 99% rename from bindings/ruby/sfml-system/system/Vector2.cpp rename to bindings/ruby/shared/Vector2.cpp index 3add5ea05..5f1b1e978 100644 --- a/bindings/ruby/sfml-system/system/Vector2.cpp +++ b/bindings/ruby/shared/Vector2.cpp @@ -21,7 +21,7 @@ */ #include "Vector2.hpp" -#include "main.hpp" +#include "global.hpp" VALUE globalVector2Class; diff --git a/bindings/ruby/sfml-system/system/Vector2.hpp b/bindings/ruby/shared/Vector2.hpp similarity index 100% rename from bindings/ruby/sfml-system/system/Vector2.hpp rename to bindings/ruby/shared/Vector2.hpp diff --git a/bindings/ruby/sfml-system/system/Vector3.cpp b/bindings/ruby/shared/Vector3.cpp similarity index 99% rename from bindings/ruby/sfml-system/system/Vector3.cpp rename to bindings/ruby/shared/Vector3.cpp index b17fde20d..911bdb11a 100644 --- a/bindings/ruby/sfml-system/system/Vector3.cpp +++ b/bindings/ruby/shared/Vector3.cpp @@ -21,7 +21,7 @@ */ #include "Vector3.hpp" -#include "main.hpp" +#include "global.hpp" VALUE globalVector3Class; diff --git a/bindings/ruby/sfml-system/system/Vector3.hpp b/bindings/ruby/shared/Vector3.hpp similarity index 100% rename from bindings/ruby/sfml-system/system/Vector3.hpp rename to bindings/ruby/shared/Vector3.hpp diff --git a/bindings/ruby/shared/global.cpp b/bindings/ruby/shared/global.cpp new file mode 100644 index 000000000..75a8768ae --- /dev/null +++ b/bindings/ruby/shared/global.cpp @@ -0,0 +1,36 @@ +/* rbSFML - Copyright (c) 2010 Henrik Valter Vogelius Hansson - groogy@groogy.se + * This software is provided 'as-is', without any express or + * implied warranty. In no event will the authors be held + * liable for any damages arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute + * it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; + * you must not claim that you wrote the original software. + * If you use this software in a product, an acknowledgment + * in the product documentation would be appreciated but + * is not required. + * + * 2. Altered source versions must be plainly marked as such, + * and must not be misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any + * source distribution. + */ + +#include "global.hpp" + +VALUE globalSFMLNamespace; + +VALUE RetrieveSFMLClass( const char * aName ) +{ + ID name = rb_intern( aName ); + if( rb_cvar_defined( globalSFMLNamespace, name ) == Qfalse ) + { + rb_raise( rb_eRuntimeError, "This module depends on SFML::%s", aName ); + } + + return rb_cvar_get( globalSFMLNamespace, name ); +} diff --git a/bindings/ruby/shared/global.hpp b/bindings/ruby/shared/global.hpp new file mode 100644 index 000000000..b38577b53 --- /dev/null +++ b/bindings/ruby/shared/global.hpp @@ -0,0 +1,49 @@ +/* rbSFML - Copyright (c) 2010 Henrik Valter Vogelius Hansson - groogy@groogy.se + * This software is provided 'as-is', without any express or + * implied warranty. In no event will the authors be held + * liable for any damages arising from the use of this software. + * + * Permission is granted to anyone to use this software for any purpose, + * including commercial applications, and to alter it and redistribute + * it freely, subject to the following restrictions: + * + * 1. The origin of this software must not be misrepresented; + * you must not claim that you wrote the original software. + * If you use this software in a product, an acknowledgment + * in the product documentation would be appreciated but + * is not required. + * + * 2. Altered source versions must be plainly marked as such, + * and must not be misrepresented as being the original software. + * + * 3. This notice may not be removed or altered from any + * source distribution. + */ + +#ifndef SFML_RUBYEXT_GLOBAL_HEADER_ +#define SFML_RUBYEXT_GLOBAL_HEADER_ + +#include "ruby.h" + +#define SFML_STATIC + +extern VALUE globalSFMLNamespace; + +VALUE RetrieveSFMLClass( const char * aName ); + +typedef VALUE ( *RubyFunctionPtr )( ... ); + +#define MAX( x, y ) ( ( x ) < ( y ) ? ( y ) : ( x ) ) +#define MIN( x, y ) ( ( x ) > ( y ) ? ( x ) : ( y ) ) + +#define VALIDATE_CLASS( variable, type, name ) \ +if( rb_obj_is_kind_of( variable, type ) != Qtrue ) \ +{ \ + rb_raise( rb_eTypeError, "%s argument must be instance of %s", name, rb_string_value_cstr ( &type ) ); \ +} + +#define rb_define_module_function( klass, name, func, argc, ... ) rb_define_module_function( klass, name, reinterpret_cast< RubyFunctionPtr >( func ), argc, ##__VA_ARGS__ ) +#define rb_define_singleton_method( klass, name, func, argc, ... ) rb_define_singleton_method( klass, name, reinterpret_cast< RubyFunctionPtr >( func ), argc, ##__VA_ARGS__ ) +#define rb_define_method( klass, name, func, argc, ... ) rb_define_method( klass, name, reinterpret_cast< RubyFunctionPtr >( func ), argc, ##__VA_ARGS__ ) + +#endif // SFML_RUBYEXT_SYSTEM_MAIN_HEADER_