1 /* Gacela, a GNU Guile extension for fast games development
2 Copyright (C) 2009 by Javier Sancho Fernandez <jsf at jsancho dot org>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include <readline/readline.h>
21 #include <readline/history.h>
22 #include "gacela_SDL.h"
23 #include "gacela_GL.h"
24 #include "gacela_FTGL.h"
27 find_matching_paren(int k)
31 int end_parens_found = 0;
33 /* Choose the corresponding opening bracket. */
34 if (k == ')') c = '(';
35 else if (k == ']') c = '[';
36 else if (k == '}') c = '{';
38 for (i=rl_point-2; i>=0; i--)
40 /* Is the current character part of a character literal? */
42 && rl_line_buffer[i - 1] == '\\'
43 && rl_line_buffer[i - 2] == '#')
45 else if (rl_line_buffer[i] == k)
47 else if (rl_line_buffer[i] == '"')
49 /* Skip over a string literal. */
50 for (i--; i >= 0; i--)
51 if (rl_line_buffer[i] == '"'
53 && rl_line_buffer[i - 1] == '\\'))
56 else if (rl_line_buffer[i] == c)
58 if (end_parens_found==0) return i;
59 else --end_parens_found;
66 match_paren(int x, int k)
70 struct timeval timeout;
74 /* Did we just insert a quoted paren? If so, then don't bounce. */
76 && rl_line_buffer[rl_point - 2] == '\\')
80 timeout.tv_usec = 500000;
82 FD_SET(fileno(rl_instream), &readset);
86 rl_point = find_matching_paren(k);
89 // scm_internal_select(1, &readset, NULL, NULL, &timeout);
98 /* init bouncing parens */
99 rl_bind_key(')', match_paren);
100 rl_bind_key(']', match_paren);
101 rl_bind_key('}', match_paren);
109 init_gacela_client ();
112 line = readline ("gacela>");
113 printf ("%s\n", line);
121 init_gacela (void *data, int argc, char **argv)
123 // Guile configuration
124 scm_c_eval_string ("(set-repl-prompt! \"gacela>\")");
125 scm_c_eval_string ("(use-modules (ice-9 readline))");
126 scm_c_eval_string ("(activate-readline)");
127 scm_c_eval_string ("(use-modules (ice-9 optargs))");
128 scm_c_eval_string ("(use-modules (ice-9 receive))");
129 scm_c_eval_string ("(use-modules (ice-9 threads))");
130 scm_c_eval_string ("(read-enable 'case-insensitive)");
132 // Bindings for C functions and structs
133 SDL_register_functions (NULL);
134 GL_register_functions (NULL);
135 FTGL_register_functions (NULL);
141 load_scheme_files (char *path)
143 char load_path[strlen (path) + 1024];
145 sprintf (load_path, "(set! %%load-path (cons \"%s\" %%load-path))", path);
146 scm_c_eval_string (load_path);
147 scm_primitive_load_path (scm_from_locale_string ("gacela_loader.scm"));
151 main (int argc, char *argv[])
154 scm_with_guile (&init_gacela, NULL);
155 load_scheme_files (dirname (argv[0]));
156 scm_shell (argc, argv);