Moved the RetrieveSFMLClass function to the system module since several other modules will be using this function too.

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1678 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
groogy 2010-11-19 13:33:37 +00:00
parent 550289b6a8
commit f1cae1cfef
3 changed files with 22 additions and 23 deletions

View File

@ -27,6 +27,17 @@
VALUE globalSFMLNamespace; 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 ) void Init_system( void )
{ {
/* SFML namespace which contains the classes of this module. */ /* SFML namespace which contains the classes of this module. */

View File

@ -25,6 +25,8 @@
#include "ruby.h" #include "ruby.h"
VALUE RetrieveSFMLClass( const char * aName );
// Ruby initiation function // Ruby initiation function
extern "C" void Init_system( void ); extern "C" void Init_system( void );

View File

@ -19,7 +19,8 @@
* 3. This notice may not be removed or altered from any * 3. This notice may not be removed or altered from any
* source distribution. * source distribution.
*/ */
#include "../../sfml-system/system/main.hpp"
#include "main.hpp" #include "main.hpp"
#include "Context.hpp" #include "Context.hpp"
#include "ContextSettings.hpp" #include "ContextSettings.hpp"
@ -58,7 +59,7 @@ static const char * keyNamesMisc[] =
* *
* All SFML::Key constants exists, I just haven't written them all so Rdoc can interpret them yet. * All SFML::Key constants exists, I just haven't written them all so Rdoc can interpret them yet.
*/ */
void CreateKeyEnum( void ) static void CreateKeyEnum( void )
{ {
globalKeyNamespace = rb_define_module_under( globalSFMLNamespace, "Key" ); globalKeyNamespace = rb_define_module_under( globalSFMLNamespace, "Key" );
rb_define_const( globalKeyNamespace, "A", INT2FIX( sf::Key::A ) ); rb_define_const( globalKeyNamespace, "A", INT2FIX( sf::Key::A ) );
@ -105,7 +106,7 @@ void CreateKeyEnum( void )
} }
/* Definition of button codes for mouse events. */ /* Definition of button codes for mouse events. */
void CreateMouseEnum( void ) static void CreateMouseEnum( void )
{ {
globalMouseNamespace = rb_define_module_under( globalSFMLNamespace, "Mouse" ); globalMouseNamespace = rb_define_module_under( globalSFMLNamespace, "Mouse" );
rb_define_const( globalMouseNamespace, "Left", INT2FIX( sf::Mouse::Left ) ); rb_define_const( globalMouseNamespace, "Left", INT2FIX( sf::Mouse::Left ) );
@ -117,7 +118,7 @@ void CreateMouseEnum( void )
} }
/* Definition of joystick axis for joystick events. */ /* Definition of joystick axis for joystick events. */
void CreateJoyEnum( void ) static void CreateJoyEnum( void )
{ {
globalJoyNamespace = rb_define_module_under( globalSFMLNamespace, "Joy" ); globalJoyNamespace = rb_define_module_under( globalSFMLNamespace, "Joy" );
rb_define_const( globalJoyNamespace, "AxisX", INT2FIX( sf::Joy::AxisX ) ); rb_define_const( globalJoyNamespace, "AxisX", INT2FIX( sf::Joy::AxisX ) );
@ -131,7 +132,7 @@ void CreateJoyEnum( void )
} }
/* Enumeration of the window styles. */ /* Enumeration of the window styles. */
void CreateStyleEnum( void ) static void CreateStyleEnum( void )
{ {
globalStyleNamespace = rb_define_module_under( globalSFMLNamespace, "Style" ); globalStyleNamespace = rb_define_module_under( globalSFMLNamespace, "Style" );
rb_define_const( globalStyleNamespace, "None", INT2FIX( sf::Style::None ) ); rb_define_const( globalStyleNamespace, "None", INT2FIX( sf::Style::None ) );
@ -142,7 +143,7 @@ void CreateStyleEnum( void )
rb_define_const( globalStyleNamespace, "Default", INT2FIX( sf::Style::Default ) ); rb_define_const( globalStyleNamespace, "Default", INT2FIX( sf::Style::Default ) );
} }
bool CheckDependencies( void ) static bool CheckDependencies( void )
{ {
if( rb_cvar_defined( globalSFMLNamespace, rb_intern( "SystemLoaded" ) ) == Qtrue ) if( rb_cvar_defined( globalSFMLNamespace, rb_intern( "SystemLoaded" ) ) == Qtrue )
{ {
@ -152,22 +153,6 @@ bool CheckDependencies( void )
return false; return false;
} }
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 RetrieveVector2Class( void )
{
globalVector2Class = RetrieveSFMLClass( "Vector2" );
}
void Init_window( void ) void Init_window( void )
{ {
/* SFML namespace which contains the classes of this module. */ /* SFML namespace which contains the classes of this module. */
@ -177,7 +162,7 @@ void Init_window( void )
rb_raise( rb_eRuntimeError, "This module depends on sfml-system" ); rb_raise( rb_eRuntimeError, "This module depends on sfml-system" );
} }
RetrieveVector2Class(); globalVector2Class = RetrieveSFMLClass( "Vector2" );
rb_define_const( globalSFMLNamespace, "WindowLoaded", Qtrue ); rb_define_const( globalSFMLNamespace, "WindowLoaded", Qtrue );
@ -193,3 +178,4 @@ void Init_window( void )
Init_VideoMode(); Init_VideoMode();
Init_Window(); Init_Window();
} }