#include <irrlicht/irrlicht.h>
#include <libguile.h>
#include "IGUIEnvironment.h"
+#include "util.h"
extern "C" {
init_gui_environment_type ();
}
- static SCM gui_environment_type;
-
- void
- init_gui_environment_type (void)
- {
- SCM name, slots;
- scm_t_struct_finalize finalizer;
-
- name = scm_from_utf8_symbol ("gui_environment");
- slots = scm_list_1 (scm_from_utf8_symbol ("data"));
- finalizer = NULL;
-
- gui_environment_type =
- scm_make_foreign_object_type (name, slots, finalizer);
- }
-
- SCM
- wrap_gui_environment (irr::gui::IGUIEnvironment* gui_environment)
- {
- return scm_make_foreign_object_1 (gui_environment_type, gui_environment);
- }
-
- irr::gui::IGUIEnvironment*
- unwrap_gui_environment (SCM gui_environment_obj)
- {
- scm_assert_foreign_object_type (gui_environment_type, gui_environment_obj);
- return (irr::gui::IGUIEnvironment*)scm_foreign_object_ref (gui_environment_obj, 0);
- }
+ DEFINE_WRAPPED_TYPE (irr::gui::IGUIEnvironment*, "gui-environment",
+ init_gui_environment_type,
+ wrap_gui_environment, unwrap_gui_environment);
}
#include <irrlicht/irrlicht.h>
#include <libguile.h>
+#include "util.h"
extern "C" {
void
init_gui_environment (void);
- void
- init_gui_environment_type (void);
-
- SCM
- wrap_gui_environment (irr::gui::IGUIEnvironment* gui_environment);
-
- irr::gui::IGUIEnvironment*
- unwrap_gui_environment (SCM gui_environment_obj);
-
+ DECLARE_WRAPPED_TYPE (irr::gui::IGUIEnvironment*, init_gui_environment_type,
+ wrap_gui_environment, unwrap_gui_environment);
}
#endif
#include <irrlicht/irrlicht.h>
#include <libguile.h>
#include "ISceneManager.h"
+#include "util.h"
extern "C" {
init_scene_manager_type ();
}
- static SCM scene_manager_type;
-
- void
- init_scene_manager_type (void)
- {
- SCM name, slots;
- scm_t_struct_finalize finalizer;
-
- name = scm_from_utf8_symbol ("scene-manager");
- slots = scm_list_1 (scm_from_utf8_symbol ("data"));
- finalizer = NULL;
-
- scene_manager_type =
- scm_make_foreign_object_type (name, slots, finalizer);
- }
-
- SCM
- wrap_scene_manager (irr::scene::ISceneManager* scene_manager)
- {
- return scm_make_foreign_object_1 (scene_manager_type, scene_manager);
- }
-
- irr::scene::ISceneManager*
- unwrap_scene_manager (SCM scene_manager_obj)
- {
- scm_assert_foreign_object_type (scene_manager_type, scene_manager_obj);
- return (irr::scene::ISceneManager*)scm_foreign_object_ref (scene_manager_obj, 0);
- }
+ DEFINE_WRAPPED_TYPE (irr::scene::ISceneManager*, "scene-manager",
+ init_scene_manager_type,
+ wrap_scene_manager, unwrap_scene_manager);
}
#include <irrlicht/irrlicht.h>
#include <libguile.h>
+#include "util.h"
extern "C" {
void
init_scene_manager (void);
- void
- init_scene_manager_type (void);
-
- SCM
- wrap_scene_manager (irr::scene::ISceneManager* scene_manager);
-
- irr::scene::ISceneManager*
- unwrap_scene_manager (SCM scene_manager_obj);
+ DECLARE_WRAPPED_TYPE (irr::scene::ISceneManager*, init_scene_manager_type,
+ wrap_scene_manager, unwrap_scene_manager);
}
#include <irrlicht/irrlicht.h>
#include <libguile.h>
#include "IVideoDriver.h"
+#include "util.h"
extern "C" {
init_video_driver_type ();
}
- static SCM video_driver_type;
-
- void
- init_video_driver_type (void)
- {
- SCM name, slots;
- scm_t_struct_finalize finalizer;
-
- name = scm_from_utf8_symbol ("video-driver");
- slots = scm_list_1 (scm_from_utf8_symbol ("data"));
- finalizer = NULL;
-
- video_driver_type =
- scm_make_foreign_object_type (name, slots, finalizer);
- }
-
- SCM
- wrap_video_driver (irr::video::IVideoDriver* driver)
- {
- return scm_make_foreign_object_1 (video_driver_type, driver);
- }
-
- irr::video::IVideoDriver*
- unwrap_video_driver (SCM driver_obj)
- {
- scm_assert_foreign_object_type (video_driver_type, driver_obj);
- return (irr::video::IVideoDriver*)scm_foreign_object_ref (driver_obj, 0);
- }
+ DEFINE_WRAPPED_TYPE (irr::video::IVideoDriver*, "video-driver",
+ init_video_driver_type,
+ wrap_video_driver, unwrap_video_driver);
}
#include <irrlicht/irrlicht.h>
#include <libguile.h>
+#include "util.h"
extern "C" {
void
init_video_driver (void);
- void
- init_video_driver_type (void);
-
- SCM
- wrap_video_driver (irr::video::IVideoDriver* driver);
-
- irr::video::IVideoDriver*
- unwrap_video_driver (SCM driver_obj);
+ DECLARE_WRAPPED_TYPE (irr::video::IVideoDriver*, init_video_driver_type,
+ wrap_video_driver, unwrap_video_driver);
}
#include "IrrlichtDevice.h"
#include "ISceneManager.h"
#include "IVideoDriver.h"
+#include "util.h"
extern "C" {
scm_c_define_gsubr ("set-window-caption!", 2, 0, 0, (scm_t_subr)irr_setWindowCaption);
}
- static SCM device_type;
-
- void
- init_device_type (void)
- {
- SCM name, slots;
- scm_t_struct_finalize finalizer;
-
- name = scm_from_utf8_symbol ("device");
- slots = scm_list_1 (scm_from_utf8_symbol ("data"));
- finalizer = NULL;
-
- device_type =
- scm_make_foreign_object_type (name, slots, finalizer);
- }
-
- SCM
- wrap_device (irr::IrrlichtDevice* device)
- {
- return scm_make_foreign_object_1 (device_type, device);
- }
-
- irr::IrrlichtDevice*
- unwrap_device (SCM device_obj)
- {
- scm_assert_foreign_object_type (device_type, device_obj);
- return (irr::IrrlichtDevice*)scm_foreign_object_ref (device_obj, 0);
- }
+ DEFINE_WRAPPED_TYPE (irr::IrrlichtDevice*, "device",
+ init_device_type, wrap_device, unwrap_device);
SCM
irr_createDevice (SCM deviceType,
#include <irrlicht/irrlicht.h>
#include <libguile.h>
+#include "util.h"
extern "C" {
void
init_device (void);
- void
- init_device_type (void);
-
- SCM
- wrap_device (irr::IrrlichtDevice* device);
-
- irr::IrrlichtDevice*
- unwrap_device (SCM device_obj);
+ DECLARE_WRAPPED_TYPE (irr::IrrlichtDevice*, init_device_type,
+ wrap_device, unwrap_device);
SCM
irr_createDevice (SCM deviceType,
--- /dev/null
+/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
+
+ Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
+
+ This file is part of guile-irrlicht.
+
+ guile-irrlicht is free software; you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation; either version 3 of the
+ License, or (at your option) any later version.
+
+ guile-irrlicht is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with guile-irrlicht. If not, see
+ <http://www.gnu.org/licenses/>.
+*/
+
+
+#define DECLARE_WRAPPED_TYPE(TYPE, INIT, WRAP, UNWRAP) \
+ void \
+ INIT (void); \
+ \
+ SCM \
+ WRAP (TYPE foreign_obj); \
+ \
+ TYPE \
+ UNWRAP (SCM wrapped_obj);
+
+
+#define DEFINE_WRAPPED_TYPE(TYPE, PRINT_NAME, INIT, WRAP, UNWRAP) \
+ static SCM wrapped_type; \
+ \
+ void \
+ INIT (void) \
+ { \
+ SCM name, slots; \
+ scm_t_struct_finalize finalizer; \
+ \
+ name = scm_from_utf8_symbol (PRINT_NAME); \
+ slots = scm_list_1 (scm_from_utf8_symbol ("data")); \
+ finalizer = NULL; \
+ \
+ wrapped_type = \
+ scm_make_foreign_object_type (name, slots, finalizer); \
+ } \
+ \
+ SCM \
+ WRAP (TYPE foreign_obj) \
+ { \
+ return scm_make_foreign_object_1 (wrapped_type, foreign_obj); \
+ } \
+ \
+ TYPE \
+ UNWRAP (SCM wrapped_obj) \
+ { \
+ scm_assert_foreign_object_type (wrapped_type, wrapped_obj); \
+ return (TYPE)scm_foreign_object_ref (wrapped_obj, 0); \
+ }