Massive copyright update. I'm sorry if I'm crediting Matze for something he didn...
[supertux.git] / src / scripting / squirrel_error.cpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
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.
10 //
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.
15 //
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.
19
20 #include <config.h>
21
22 #include "squirrel_error.hpp"
23 #include <sstream>
24
25 namespace Scripting
26 {
27
28 SquirrelError::SquirrelError(HSQUIRRELVM v, const std::string& message) throw()
29 {
30   std::ostringstream msg;
31   msg << "Squirrel error: " << message << " (";
32   const char* lasterr;
33   sq_getlasterror(v);
34   if(sq_gettype(v, -1) != OT_STRING)
35   {
36     lasterr = "no error info";
37   }
38   else
39   {
40     sq_getstring(v, -1, &lasterr);
41   }
42   sq_pop(v, 1);
43   msg << lasterr << ")";
44   this->message = msg.str();
45 }
46
47 SquirrelError::~SquirrelError() throw()
48 {}
49
50 const char*
51 SquirrelError::what() const throw()
52 {
53   return message.c_str();
54 }
55
56 }