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"
23 LispReader::LispReader (lisp_object_t
* l
)
26 //std::cout << "LispReader: " << std::flush;
27 //lisp_dump(lst, stdout);
28 //std::cout << std::endl;
32 LispReader::search_for(const char* name
)
34 //std::cout << "LispReader::search_for(" << name << ")" << std::endl;
35 lisp_object_t
* cursor
= lst
;
37 while(!lisp_nil_p(cursor
))
39 lisp_object_t
* cur
= lisp_car(cursor
);
41 if (!lisp_cons_p(cur
) || !lisp_symbol_p (lisp_car(cur
)))
43 lisp_dump(cur
, stdout
);
44 throw ConstruoError (std::string("LispReader: Read error in search_for ") + name
);
48 if (strcmp(lisp_symbol(lisp_car(cur
)), name
) == 0)
54 cursor
= lisp_cdr (cursor
);
60 LispReader::read_vector (const char* name
, Vector2d
* vec
)
62 lisp_object_t
* obj
= search_for (name
);
65 vec
->x
= lisp_real(lisp_car(obj
));
66 vec
->y
= lisp_real(lisp_car(lisp_cdr(obj
)));
73 LispReader::read_int (const char* name
, int* i
)
75 lisp_object_t
* obj
= search_for (name
);
78 *i
= lisp_integer(lisp_car(obj
));
85 LispReader::read_float (const char* name
, float* f
)
87 lisp_object_t
* obj
= search_for (name
);
90 *f
= lisp_real(lisp_car(obj
));
97 LispReader::read_bool (const char* name
, bool* b
)
99 lisp_object_t
* obj
= search_for (name
);
102 *b
= lisp_boolean(lisp_car(obj
));