From: Javier Sancho Date: Thu, 19 Mar 2020 19:05:16 +0000 (+0100) Subject: get-name X-Git-Url: https://git.jsancho.org/?a=commitdiff_plain;h=f215da151462c3d0fe9bacc535083529ba43e716;p=guile-irrlicht.git get-name --- diff --git a/Makefile.am b/Makefile.am index 08a5f1d..576c75e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -36,6 +36,7 @@ libguile_irrlicht_la_SOURCES = \ src/gui-static-text.cpp \ src/guile-irrlicht.cpp \ src/material-flags.cpp \ + src/misc.cpp \ src/rect.cpp \ src/reference-counted.cpp \ src/scene-manager.cpp \ diff --git a/examples/02.Quake3Map.scm b/examples/02.Quake3Map.scm index 45249ac..1407f29 100644 --- a/examples/02.Quake3Map.scm +++ b/examples/02.Quake3Map.scm @@ -59,7 +59,7 @@ ;; instances for doing things (define driver (get-video-driver device)) (define scene-manager (get-scene-manager device)) -(define driver-name (get-video-driver-name driver)) +(define driver-name (get-name driver)) ;; load Quake3 map (add-file-archive! (get-file-system device) "media/map-20kdm2.pk3") diff --git a/src/guile-irrlicht.cpp b/src/guile-irrlicht.cpp index 991f26a..fd4515f 100644 --- a/src/guile-irrlicht.cpp +++ b/src/guile-irrlicht.cpp @@ -29,6 +29,7 @@ #include "gui-environment.h" #include "gui-static-text.h" #include "material-flags.h" +#include "misc.h" #include "reference-counted.h" #include "scene-manager.h" #include "scene-node.h" @@ -48,6 +49,7 @@ extern "C" { init_gui_environment (); init_gui_static_text (); init_material_flag (); + init_misc (); init_reference_counted (); init_scene_manager (); init_scene_node (); diff --git a/src/misc.cpp b/src/misc.cpp new file mode 100644 index 0000000..e030979 --- /dev/null +++ b/src/misc.cpp @@ -0,0 +1,51 @@ +/* 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 + . +*/ + +#include +#include +#include "misc.h" +#include "video-driver.h" +#include "wchar.h" + +extern "C" { + + void + init_misc (void) + { + scm_c_define_gsubr ("get-name", 1, 0, 0, (scm_t_subr)irr_getName); + scm_c_export ("get-name", NULL); + } + + SCM + irr_getName (SCM wrapped_obj) + { + if (video_driver_p (wrapped_obj)) + { + return scm_from_wide_char_string (unwrap_video_driver (wrapped_obj)->getName ()); + } + else + { + scm_error (scm_arg_type_key, NULL, "Cannot get name from object: ~S", + scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj)); + } + } + +} diff --git a/src/misc.h b/src/misc.h new file mode 100644 index 0000000..b81fd9b --- /dev/null +++ b/src/misc.h @@ -0,0 +1,38 @@ +/* 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_MISC_H_INCLUDED__ +#define __GUILE_IRRLICHT_MISC_H_INCLUDED__ + +#include +#include + +extern "C" { + + void + init_misc (void); + + SCM + irr_getName (SCM wrapped_obj); + +} + +#endif diff --git a/src/video-driver.cpp b/src/video-driver.cpp index c811c18..43ada62 100644 --- a/src/video-driver.cpp +++ b/src/video-driver.cpp @@ -38,7 +38,7 @@ extern "C" { { init_video_driver_type (); scm_c_define_gsubr ("begin-scene", 1, 0, 1, (scm_t_subr)irr_video_beginScene); - scm_c_define_gsubr ("draw-all", 1, 0, 0, (scm_t_subr)irr_guiscene_drawAll); + scm_c_define_gsubr ("draw-all", 1, 0, 0, (scm_t_subr)irr_drawAll); scm_c_define_gsubr ("end-scene", 1, 0, 0, (scm_t_subr)irr_video_endScene); 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); @@ -86,7 +86,7 @@ extern "C" { } SCM - irr_guiscene_drawAll (SCM wrapped_obj) + irr_drawAll (SCM wrapped_obj) { if (gui_environment_p (wrapped_obj)) { diff --git a/src/video-driver.h b/src/video-driver.h index 0957836..d8cd754 100644 --- a/src/video-driver.h +++ b/src/video-driver.h @@ -39,7 +39,7 @@ extern "C" { SCM rest); SCM - irr_guiscene_drawAll (SCM wrapped_obj); + irr_drawAll (SCM wrapped_obj); SCM irr_video_endScene (SCM wrapped_video_driver); diff --git a/src/wchar.cpp b/src/wchar.cpp index 872c87a..a41a003 100644 --- a/src/wchar.cpp +++ b/src/wchar.cpp @@ -23,7 +23,16 @@ #include #include "wchar.h" -wchar_t* +SCM +scm_from_wide_char_string (const wchar_t* wtext) +{ + size_t nbytes = wcslen (wtext) + 1; + char* ctext = (char*)malloc (nbytes); + wcstombs (ctext, wtext, nbytes); + return scm_from_utf8_string (ctext); +} + +const wchar_t* scm_to_wide_char_string (SCM text) { char* ctext = scm_to_utf8_stringn (text, NULL); diff --git a/src/wchar.h b/src/wchar.h index 7b6119a..0e086be 100644 --- a/src/wchar.h +++ b/src/wchar.h @@ -25,7 +25,10 @@ #include #include -wchar_t* +SCM +scm_from_wide_char_string (const wchar_t* wtext); + +const wchar_t* scm_to_wide_char_string (SCM text); #endif