1 // $Id: lisp_writer.cxx,v 1.3 2003/07/24 10:10:02 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 "lisp_writer.hxx"
22 LispWriter::LispWriter (const char* name
)
24 lisp_objs
.push_back(lisp_make_symbol (name
));
28 LispWriter::append (lisp_object_t
* obj
)
30 lisp_objs
.push_back(obj
);
34 LispWriter::make_list3 (lisp_object_t
* a
, lisp_object_t
* b
, lisp_object_t
* c
)
36 return lisp_make_cons (a
, lisp_make_cons(b
, lisp_make_cons(c
, lisp_nil())));
40 LispWriter::make_list2 (lisp_object_t
* a
, lisp_object_t
* b
)
42 return lisp_make_cons (a
, lisp_make_cons(b
, lisp_nil()));
46 LispWriter::write_vector (const char* name
, const Vector2d
& pos
)
48 append(lisp_make_cons (lisp_make_symbol (name
),
49 make_list2(lisp_make_real(pos
.x
),
50 lisp_make_real(pos
.y
))));
54 LispWriter::write_float (const char* name
, float f
)
56 append(make_list2 (lisp_make_symbol (name
),
61 LispWriter::write_int (const char* name
, int i
)
63 append(make_list2 (lisp_make_symbol (name
),
64 lisp_make_integer(i
)));
68 LispWriter::write_string (const char* name
, const char* str
)
70 append(make_list2 (lisp_make_symbol (name
),
71 lisp_make_string(str
)));
75 LispWriter::write_symbol (const char* name
, const char* symname
)
77 append(make_list2 (lisp_make_symbol (name
),
78 lisp_make_symbol(symname
)));
82 LispWriter::write_lisp_obj(const char* name
, lisp_object_t
* lst
)
84 append(make_list2 (lisp_make_symbol (name
),
89 LispWriter::write_boolean (const char* name
, bool b
)
91 append(make_list2 (lisp_make_symbol (name
),
92 lisp_make_boolean(b
)));
96 LispWriter::create_lisp ()
98 lisp_object_t
* lisp_obj
= lisp_nil();
100 for(std::vector
<lisp_object_t
*>::reverse_iterator i
= lisp_objs
.rbegin ();
101 i
!= lisp_objs
.rend (); ++i
)
103 lisp_obj
= lisp_make_cons (*i
, lisp_obj
);