From: Javier Sancho Date: Thu, 9 Apr 2020 07:10:50 +0000 (+0200) Subject: Macro for defining guile procedures X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=69ed7f57e6295034fa64ab2bf6d10da6882860ef;p=guile-irrlicht.git Macro for defining guile procedures --- diff --git a/src/animated-mesh-scene-node.cpp b/src/animated-mesh-scene-node.cpp index dc46e80..f19f0aa 100644 --- a/src/animated-mesh-scene-node.cpp +++ b/src/animated-mesh-scene-node.cpp @@ -24,6 +24,7 @@ #include "animated-mesh-md2.h" #include "animated-mesh-scene-node.h" +#include "gsubr.h" #include "wrapped.h" extern "C" { @@ -32,8 +33,7 @@ extern "C" { init_animated_mesh_scene_node (void) { init_animated_mesh_scene_node_type (); - scm_c_define_gsubr ("set-md2-animation!", 2, 0, 0, (scm_t_subr)irr_scene_setMD2Animation); - scm_c_export ("set-md2-animation!", NULL); + DEFINE_GSUBR ("set-md2-animation!", 2, 0, 0, irr_scene_setMD2Animation); } DEFINE_WRAPPED_TYPE (irr::scene::IAnimatedMeshSceneNode*, "animated-mesh-scene-node", diff --git a/src/box3d.cpp b/src/box3d.cpp index 7185c0b..9b78836 100644 --- a/src/box3d.cpp +++ b/src/box3d.cpp @@ -22,6 +22,7 @@ #include #include #include "box3d.h" +#include "gsubr.h" #include "vector3d.h" #include "wrapped.h" @@ -31,10 +32,9 @@ extern "C" { init_box3d (void) { init_box3d_type (); - scm_c_define_gsubr ("box3d-add-internal-point!", 2, 0, 0, (scm_t_subr)box3d_add_internal_point); - scm_c_define_gsubr ("box3d-reset!", 2, 0, 0, (scm_t_subr)box3d_reset); - scm_c_define_gsubr ("make-box3d", 0, 0, 0, (scm_t_subr)make_box3d); - scm_c_export ("box3d-add-internal-point!", "box3d-reset!", "make-box3d", NULL); + DEFINE_GSUBR ("box3d-add-internal-point!", 2, 0, 0, box3d_add_internal_point); + DEFINE_GSUBR ("box3d-reset!", 2, 0, 0, box3d_reset); + DEFINE_GSUBR ("make-box3d", 0, 0, 0, make_box3d); } DEFINE_WRAPPED_TYPE (irr::core::aabbox3df*, "box3d", diff --git a/src/cursor-control.cpp b/src/cursor-control.cpp index ada992f..5ff6540 100644 --- a/src/cursor-control.cpp +++ b/src/cursor-control.cpp @@ -24,6 +24,7 @@ #include "cursor-control.h" #include "device.h" +#include "gsubr.h" #include "position2d.h" #include "wrapped.h" @@ -33,8 +34,7 @@ extern "C" { init_cursor_control (void) { init_cursor_control_type (); - scm_c_define_gsubr ("get-cursor-control", 1, 0, 0, (scm_t_subr)irr_getCursorControl); - scm_c_export ("get-cursor-control", NULL); + DEFINE_GSUBR ("get-cursor-control", 1, 0, 0, irr_getCursorControl); } DEFINE_WRAPPED_TYPE (irr::gui::ICursorControl*, "cursor-control", diff --git a/src/device.cpp b/src/device.cpp index 0a4d2c6..b60ec44 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -26,6 +26,7 @@ #include "dimension2d.h" #include "driver-types.h" #include "event-receiver.h" +#include "gsubr.h" #include "wchar.h" #include "wrapped.h" @@ -35,13 +36,11 @@ extern "C" { init_device (void) { init_device_type (); - scm_c_define_gsubr ("create-device", 0, 0, 1, (scm_t_subr)irr_createDevice); - scm_c_define_gsubr ("is-window-active?", 1, 0, 0, (scm_t_subr)irr_isWindowActive); - scm_c_define_gsubr ("run", 1, 0, 0, (scm_t_subr)irr_run); - scm_c_define_gsubr ("set-window-caption!", 2, 0, 0, (scm_t_subr)irr_setWindowCaption); - scm_c_define_gsubr ("yield", 1, 0, 0, (scm_t_subr)irr_yield); - scm_c_export ("create-device", "is-window-active?", "run", - "set-window-caption!", "yield", NULL); + DEFINE_GSUBR ("create-device", 0, 0, 1, irr_createDevice); + DEFINE_GSUBR ("is-window-active?", 1, 0, 0, irr_isWindowActive); + DEFINE_GSUBR ("run", 1, 0, 0, irr_run); + DEFINE_GSUBR ("set-window-caption!", 2, 0, 0, irr_setWindowCaption); + DEFINE_GSUBR ("yield", 1, 0, 0, irr_yield); } DEFINE_WRAPPED_TYPE (irr::IrrlichtDevice*, "device", diff --git a/src/event-receiver.cpp b/src/event-receiver.cpp index f5d673b..64b3851 100644 --- a/src/event-receiver.cpp +++ b/src/event-receiver.cpp @@ -22,6 +22,7 @@ #include #include #include "event-receiver.h" +#include "gsubr.h" #include "wrapped.h" extern "C" { @@ -31,9 +32,8 @@ extern "C" { { init_event_receiver_type (); init_event_type (); - scm_c_define_gsubr ("event-type", 1, 0, 0, (scm_t_subr)event_type); - scm_c_define_gsubr ("make-event-receiver", 1, 0, 0, (scm_t_subr)make_event_receiver); - scm_c_export ("event-type", "make-event-receiver", NULL); + DEFINE_GSUBR ("event-type", 1, 0, 0, event_type); + DEFINE_GSUBR ("make-event-receiver", 1, 0, 0, make_event_receiver); } DEFINE_WRAPPED_TYPE (irr::IEventReceiver*, "event-receiver", diff --git a/src/file-system.cpp b/src/file-system.cpp index da856f4..a421fd3 100644 --- a/src/file-system.cpp +++ b/src/file-system.cpp @@ -25,6 +25,7 @@ #include "device.h" #include "file-archive.h" #include "file-system.h" +#include "gsubr.h" #include "gui-environment.h" #include "scene-manager.h" @@ -34,9 +35,8 @@ extern "C" { init_file_system (void) { init_file_system_type (); - scm_c_define_gsubr ("add-file-archive!", 2, 0, 1, (scm_t_subr)irr_io_addFileArchive); - scm_c_define_gsubr ("get-file-system", 1, 0, 0, (scm_t_subr)irr_getFileSystem); - scm_c_export ("add-file-archive!", "get-file-system", NULL); + DEFINE_GSUBR ("add-file-archive!", 2, 0, 1, irr_io_addFileArchive); + DEFINE_GSUBR ("get-file-system", 1, 0, 0, irr_getFileSystem); } DEFINE_WRAPPED_TYPE (irr::io::IFileSystem*, "file-system", diff --git a/src/gsubr.h b/src/gsubr.h new file mode 100644 index 0000000..5db534d --- /dev/null +++ b/src/gsubr.h @@ -0,0 +1,31 @@ +/* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine + + Copyright (C) 2020 Javier Sancho + + 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 + . +*/ + +#ifndef __GUILE_IRRLICHT_GSUBR_H_INCLUDED__ +#define __GUILE_IRRLICHT_GSUBR_H_INCLUDED__ + +#include + +#define DEFINE_GSUBR(NAME, REQ, OPT, REST, FUNC) \ + scm_c_define_gsubr (NAME, REQ, OPT, REST, (scm_t_subr)FUNC); \ + scm_c_export (NAME, NULL); + +#endif diff --git a/src/gui-environment.cpp b/src/gui-environment.cpp index fb13f53..dfe3a0a 100644 --- a/src/gui-environment.cpp +++ b/src/gui-environment.cpp @@ -23,6 +23,7 @@ #include #include "device.h" +#include "gsubr.h" #include "gui-element.h" #include "gui-environment.h" #include "gui-static-text.h" @@ -36,9 +37,8 @@ extern "C" { init_gui_environment (void) { init_gui_environment_type (); - scm_c_define_gsubr ("add-static-text!", 3, 0, 1, (scm_t_subr)irr_gui_addStaticText); - scm_c_define_gsubr ("get-gui-environment", 1, 0, 0, (scm_t_subr)irr_getGUIEnvironment); - scm_c_export ("add-static-text!", "get-gui-environment", NULL); + DEFINE_GSUBR ("add-static-text!", 3, 0, 1, irr_gui_addStaticText); + DEFINE_GSUBR ("get-gui-environment", 1, 0, 0, irr_getGUIEnvironment); } DEFINE_WRAPPED_TYPE (irr::gui::IGUIEnvironment*, "gui-environment", diff --git a/src/guile-irrlicht.cpp b/src/guile-irrlicht.cpp index a1e8411..db77dab 100644 --- a/src/guile-irrlicht.cpp +++ b/src/guile-irrlicht.cpp @@ -30,6 +30,7 @@ #include "event-receiver.h" #include "file-archive.h" #include "file-system.h" +#include "gsubr.h" #include "gui-element.h" #include "gui-environment.h" #include "gui-static-text.h" @@ -78,14 +79,12 @@ extern "C" { init_video_driver (); // Shared procedures (used by two or more objects) - scm_c_define_gsubr ("draw-all", 1, 0, 0, (scm_t_subr)irr_drawAll); - scm_c_define_gsubr ("get-name", 1, 0, 0, (scm_t_subr)irr_getName); - scm_c_define_gsubr ("set-material!", 2, 0, 0, (scm_t_subr)irr_setMaterial); - scm_c_define_gsubr ("set-material-flag!", 3, 0, 0, (scm_t_subr)irr_setMaterialFlag); - scm_c_define_gsubr ("set-position!", 2, 0, 0, (scm_t_subr)irr_setPosition); - scm_c_define_gsubr ("set-visible!", 2, 0, 0, (scm_t_subr)irr_setVisible); - scm_c_export ("draw-all", "get-name", "set-material!", "set-material-flag!", - "set-position!", "set-visible!", NULL); + DEFINE_GSUBR ("draw-all", 1, 0, 0, irr_drawAll); + DEFINE_GSUBR ("get-name", 1, 0, 0, irr_getName); + DEFINE_GSUBR ("set-material!", 2, 0, 0, irr_setMaterial); + DEFINE_GSUBR ("set-material-flag!", 3, 0, 0, irr_setMaterialFlag); + DEFINE_GSUBR ("set-position!", 2, 0, 0, irr_setPosition); + DEFINE_GSUBR ("set-visible!", 2, 0, 0, irr_setVisible); } SCM diff --git a/src/material.cpp b/src/material.cpp index 3d32f21..1d4e92a 100644 --- a/src/material.cpp +++ b/src/material.cpp @@ -23,6 +23,7 @@ #include #include "color.h" +#include "gsubr.h" #include "material.h" #include "material-types.h" #include "wrapped.h" @@ -33,8 +34,7 @@ extern "C" { init_material (void) { init_material_type (); - scm_c_define_gsubr ("make-material", 0, 0, 1, (scm_t_subr)make_material); - scm_c_export ("make-material", NULL); + DEFINE_GSUBR ("make-material", 0, 0, 1, make_material); } DEFINE_WRAPPED_TYPE (irr::video::SMaterial*, "material", diff --git a/src/reference-counted.cpp b/src/reference-counted.cpp index 9b858cc..1060df4 100644 --- a/src/reference-counted.cpp +++ b/src/reference-counted.cpp @@ -23,6 +23,7 @@ #include #include "device.h" +#include "gsubr.h" #include "reference-counted.h" #include "scene-node-animator.h" @@ -31,8 +32,7 @@ extern "C" { void init_reference_counted (void) { - scm_c_define_gsubr ("drop!", 1, 0, 0, (scm_t_subr)irr_drop); - scm_c_export ("drop!", NULL); + DEFINE_GSUBR ("drop!", 1, 0, 0, irr_drop); } SCM diff --git a/src/scene-manager.cpp b/src/scene-manager.cpp index 9ef592f..0d4caeb 100644 --- a/src/scene-manager.cpp +++ b/src/scene-manager.cpp @@ -27,6 +27,7 @@ #include "box3d.h" #include "camera-scene-node.h" #include "device.h" +#include "gsubr.h" #include "keymap.h" #include "material.h" #include "mesh.h" @@ -43,34 +44,19 @@ extern "C" { init_scene_manager (void) { init_scene_manager_type (); - scm_c_define_gsubr ("add-animated-mesh-scene-node!", 2, 0, 1, - (scm_t_subr)irr_scene_addAnimatedMeshSceneNode); - scm_c_define_gsubr ("add-camera-scene-node!", 1, 0, 1, - (scm_t_subr)irr_scene_addCameraSceneNode); - scm_c_define_gsubr ("add-camera-scene-node-fps!", 1, 0, 1, - (scm_t_subr)irr_scene_addCameraSceneNodeFPS); - scm_c_define_gsubr ("add-cube-scene-node!", 1, 0, 1, - (scm_t_subr)irr_scene_addCubeSceneNode); - scm_c_define_gsubr ("add-custom-scene-node!", 5, 0, 1, - (scm_t_subr)irr_scene_addCustomSceneNode); - scm_c_define_gsubr ("add-octree-scene-node!", 2, 0, 1, - (scm_t_subr)irr_scene_addOctreeSceneNode); - scm_c_define_gsubr ("add-sphere-scene-node!", 1, 0, 1, - (scm_t_subr)irr_scene_addSphereSceneNode); - scm_c_define_gsubr ("create-fly-circle-animator", 1, 0, 1, - (scm_t_subr)irr_scene_createFlyCircleAnimator); - scm_c_define_gsubr ("create-fly-straight-animator", 4, 0, 1, - (scm_t_subr)irr_scene_createFlyStraightAnimator); - scm_c_define_gsubr ("create-rotation-animator", 2, 0, 0, - (scm_t_subr)irr_scene_createRotationAnimator); - scm_c_define_gsubr ("get-mesh", 2, 0, 0, (scm_t_subr)irr_scene_getMesh); - scm_c_define_gsubr ("get-root-scene-node", 1, 0, 0, (scm_t_subr)irr_scene_getRootSceneNode); - scm_c_define_gsubr ("get-scene-manager", 1, 0, 0, (scm_t_subr)irr_getSceneManager); - scm_c_export ("add-animated-mesh-scene-node!", "add-camera-scene-node!", - "add-camera-scene-node-fps!", "add-custom-scene-node!", "add-cube-scene-node!", - "add-octree-scene-node!", "add-sphere-scene-node!", "create-fly-circle-animator", - "create-fly-straight-animator", "create-rotation-animator", "get-mesh", - "get-root-scene-node", "get-scene-manager", NULL); + DEFINE_GSUBR ("add-animated-mesh-scene-node!", 2, 0, 1, irr_scene_addAnimatedMeshSceneNode); + DEFINE_GSUBR ("add-camera-scene-node!", 1, 0, 1, irr_scene_addCameraSceneNode); + DEFINE_GSUBR ("add-camera-scene-node-fps!", 1, 0, 1, irr_scene_addCameraSceneNodeFPS); + DEFINE_GSUBR ("add-cube-scene-node!", 1, 0, 1, irr_scene_addCubeSceneNode); + DEFINE_GSUBR ("add-custom-scene-node!", 5, 0, 1, irr_scene_addCustomSceneNode); + DEFINE_GSUBR ("add-octree-scene-node!", 2, 0, 1, irr_scene_addOctreeSceneNode); + DEFINE_GSUBR ("add-sphere-scene-node!", 1, 0, 1, irr_scene_addSphereSceneNode); + DEFINE_GSUBR ("create-fly-circle-animator", 1, 0, 1, irr_scene_createFlyCircleAnimator); + DEFINE_GSUBR ("create-fly-straight-animator", 4, 0, 1, irr_scene_createFlyStraightAnimator); + DEFINE_GSUBR ("create-rotation-animator", 2, 0, 0, irr_scene_createRotationAnimator); + DEFINE_GSUBR ("get-mesh", 2, 0, 0, irr_scene_getMesh); + DEFINE_GSUBR ("get-root-scene-node", 1, 0, 0, irr_scene_getRootSceneNode); + DEFINE_GSUBR ("get-scene-manager", 1, 0, 0, irr_getSceneManager); } DEFINE_WRAPPED_TYPE (irr::scene::ISceneManager*, "scene-manager", diff --git a/src/scene-node.cpp b/src/scene-node.cpp index 1ec773c..695fd63 100644 --- a/src/scene-node.cpp +++ b/src/scene-node.cpp @@ -23,6 +23,7 @@ #include #include "animated-mesh-scene-node.h" +#include "gsubr.h" #include "material-flags.h" #include "matrix4.h" #include "mesh-scene-node.h" @@ -38,12 +39,9 @@ extern "C" { init_scene_node (void) { init_scene_node_type (); - scm_c_define_gsubr ("add-animator!", 2, 0, 0, (scm_t_subr)irr_scene_addAnimator); - scm_c_define_gsubr ("get-absolute-transformation", 1, 0, 0, - (scm_t_subr)irr_scene_getAbsoluteTransformation); - scm_c_define_gsubr ("set-material-texture!", 3, 0, 0, (scm_t_subr)irr_scene_setMaterialTexture); - scm_c_export ("add-animator!", "get-absolute-transformation", - "set-material-texture!", NULL); + DEFINE_GSUBR ("add-animator!", 2, 0, 0, irr_scene_addAnimator); + DEFINE_GSUBR ("get-absolute-transformation", 1, 0, 0, irr_scene_getAbsoluteTransformation); + DEFINE_GSUBR ("set-material-texture!", 3, 0, 0, irr_scene_setMaterialTexture); } DEFINE_WRAPPED_TYPE (irr::scene::ISceneNode*, "scene-node", diff --git a/src/vertex3d.cpp b/src/vertex3d.cpp index f6adab0..6ffc86d 100644 --- a/src/vertex3d.cpp +++ b/src/vertex3d.cpp @@ -21,7 +21,9 @@ #include #include + #include "color.h" +#include "gsubr.h" #include "vector2d.h" #include "vector3d.h" #include "vertex3d.h" @@ -33,9 +35,8 @@ extern "C" { init_vertex3d (void) { init_vertex3d_type (); - scm_c_define_gsubr ("make-vertex3d", 4, 0, 0, (scm_t_subr)make_vertex3d); - scm_c_define_gsubr ("vertex3d-position", 1, 0, 0, (scm_t_subr)vertex3d_position); - scm_c_export ("make-vertex3d", "vertex3d-position", NULL); + DEFINE_GSUBR ("make-vertex3d", 4, 0, 0, make_vertex3d); + DEFINE_GSUBR ("vertex3d-position", 1, 0, 0, vertex3d_position); } DEFINE_WRAPPED_TYPE (irr::video::S3DVertex*, "vertex3d", diff --git a/src/video-driver.cpp b/src/video-driver.cpp index 9c81120..ef7dd57 100644 --- a/src/video-driver.cpp +++ b/src/video-driver.cpp @@ -24,6 +24,7 @@ #include "color.h" #include "device.h" +#include "gsubr.h" #include "gui-environment.h" #include "material.h" #include "matrix4.h" @@ -41,16 +42,13 @@ extern "C" { init_video_driver (void) { init_video_driver_type (); - scm_c_define_gsubr ("begin-scene", 1, 0, 1, (scm_t_subr)irr_video_beginScene); - scm_c_define_gsubr ("draw-vertex-primitive-list", 3, 0, 1, - (scm_t_subr)irr_video_drawVertexPrimitiveList); - scm_c_define_gsubr ("end-scene", 1, 0, 0, (scm_t_subr)irr_video_endScene); - scm_c_define_gsubr ("get-fps", 1, 0, 0, (scm_t_subr)irr_video_getFPS); - scm_c_define_gsubr ("get-texture", 2, 0, 0, (scm_t_subr)irr_video_getTexture); - scm_c_define_gsubr ("get-video-driver", 1, 0, 0, (scm_t_subr)irr_getVideoDriver); - scm_c_define_gsubr ("set-transform!", 3, 0, 0, (scm_t_subr)irr_video_setTransform); - scm_c_export ("begin-scene", "draw-vertex-primitive-list", "end-scene", "get-fps", - "get-texture", "get-video-driver", "set-transform!", NULL); + DEFINE_GSUBR ("begin-scene", 1, 0, 1, irr_video_beginScene); + DEFINE_GSUBR ("draw-vertex-primitive-list", 3, 0, 1, irr_video_drawVertexPrimitiveList); + DEFINE_GSUBR ("end-scene", 1, 0, 0, irr_video_endScene); + DEFINE_GSUBR ("get-fps", 1, 0, 0, irr_video_getFPS); + DEFINE_GSUBR ("get-texture", 2, 0, 0, irr_video_getTexture); + DEFINE_GSUBR ("get-video-driver", 1, 0, 0, irr_getVideoDriver); + DEFINE_GSUBR ("set-transform!", 3, 0, 0, irr_video_setTransform); } DEFINE_WRAPPED_TYPE (irr::video::IVideoDriver*, "video-driver",