1 /* guile-irrlicht --- GNU Guile bindings for Irrlicht Engine
3 Copyright (C) 2020 Javier Sancho <jsf@jsancho.org>
5 This file is part of guile-irrlicht.
7 guile-irrlicht is free software; you can redistribute it and/or modify
8 it under the terms of the GNU Lesser General Public License as
9 published by the Free Software Foundation; either version 3 of the
10 License, or (at your option) any later version.
12 guile-irrlicht is distributed in the hope that it will be useful, but
13 WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with guile-irrlicht. If not, see
19 <http://www.gnu.org/licenses/>.
22 #include <irrlicht/irrlicht.h>
26 #include "file-archive.h"
27 #include "file-system.h"
28 #include "gui-environment.h"
29 #include "scene-manager.h"
34 init_file_system (void)
36 init_file_system_type ();
37 scm_c_define_gsubr ("add-file-archive!", 2, 0, 1, (scm_t_subr)irr_io_addFileArchive);
38 scm_c_define_gsubr ("get-file-system", 1, 0, 0, (scm_t_subr)irr_getFileSystem);
39 scm_c_export ("add-file-archive!", "get-file-system", NULL);
42 DEFINE_WRAPPED_TYPE (irr::io::IFileSystem*, "file-system",
43 init_file_system_type, file_system_p,
44 wrap_file_system, unwrap_file_system);
47 irr_io_addFileArchive (SCM wrapped_file_system,
51 SCM ignore_case = scm_from_bool (1);
52 SCM ignore_paths = scm_from_bool (1);
53 SCM archive_type = scm_from_utf8_symbol ("unknown");
54 SCM password = scm_from_utf8_string ("");
55 SCM ret_archive = scm_from_bool (0);
57 scm_c_bind_keyword_arguments ("add-file-archive!", rest, (scm_t_keyword_arguments_flags)0,
58 scm_from_utf8_keyword ("ignore-case"), &ignore_case,
59 scm_from_utf8_keyword ("ignore-paths"), &ignore_paths,
60 scm_from_utf8_keyword ("archive-type"), &archive_type,
61 scm_from_utf8_keyword ("password"), &password,
62 scm_from_utf8_keyword ("ret-archive"), &ret_archive,
65 irr::io::IFileArchive** retArchiveReference = 0;
66 if (!scm_is_false (ret_archive))
68 irr::io::IFileArchive* retArchive = unwrap_file_archive (ret_archive);
69 retArchiveReference = &retArchive;
71 irr::io::IFileSystem* file_system = unwrap_file_system (wrapped_file_system);
73 (file_system->addFileArchive (scm_to_utf8_stringn (filename, NULL),
74 scm_to_bool (ignore_case),
75 scm_to_bool (ignore_paths),
76 scm_to_file_archive_type (archive_type),
77 scm_to_utf8_stringn (password, NULL),
78 retArchiveReference));
82 irr_getFileSystem (SCM wrapped_obj)
84 irr::io::IFileSystem* file_system;
85 if (gui_environment_p (wrapped_obj))
87 file_system = unwrap_gui_environment (wrapped_obj)->getFileSystem ();
89 else if (device_p (wrapped_obj))
91 file_system = unwrap_device (wrapped_obj)->getFileSystem ();
93 else if (scene_manager_p (wrapped_obj))
95 file_system = unwrap_scene_manager (wrapped_obj)->getFileSystem ();
99 scm_error (scm_arg_type_key, NULL, "Cannot get file system from object: ~S",
100 scm_list_1 (wrapped_obj), scm_list_1 (wrapped_obj));
102 return wrap_file_system (file_system);