1 // $Id: lisp_reader.cxx,v 1.5 2002/12/28 00:19:53 grumbel Exp $
3 // Construo - A wire-frame construction game
4 // Copyright (C) 2002 Ingo Ruhnke <grumbel@gmx.de>
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "construo_error.hxx"
21 #include "lisp_reader.hxx"
24 LispReader::LispReader (lisp_object_t
* l
)
27 //std::cout << "LispReader: " << std::flush;
28 //lisp_dump(lst, stdout);
29 //std::cout << std::endl;
33 LispReader::search_for(const char* name
)
35 //std::cout << "LispReader::search_for(" << name << ")" << std::endl;
36 lisp_object_t
* cursor
= lst
;
38 while(!lisp_nil_p(cursor
))
40 lisp_object_t
* cur
= lisp_car(cursor
);
42 if (!lisp_cons_p(cur
) || !lisp_symbol_p (lisp_car(cur
)))
44 lisp_dump(cur
, stdout
);
45 throw ConstruoError (std::string("LispReader: Read error in search_for ") + name
);
49 if (strcmp(lisp_symbol(lisp_car(cur
)), name
) == 0)
55 cursor
= lisp_cdr (cursor
);
61 LispReader::read_vector (const char* name
, Vector2d
* vec
)
63 lisp_object_t
* obj
= search_for (name
);
66 vec
->x
= lisp_real(lisp_car(obj
));
67 vec
->y
= lisp_real(lisp_car(lisp_cdr(obj
)));
74 LispReader::read_int (const char* name
, int* i
)
76 lisp_object_t
* obj
= search_for (name
);
79 *i
= lisp_integer(lisp_car(obj
));
86 LispReader::read_float (const char* name
, float* f
)
88 lisp_object_t
* obj
= search_for (name
);
91 *f
= lisp_real(lisp_car(obj
));
98 LispReader::read_bool (const char* name
, bool* b
)
100 lisp_object_t
* obj
= search_for (name
);
103 *b
= lisp_boolean(lisp_car(obj
));