X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fscripting%2Fserialize.cpp;h=79be04c4b554ba4c129fd22b8ba71bb0ef705e4f;hb=7d3004fc6167b7fcd7495dd1ac278f2ac527cbec;hp=7d7992d3502bc3b16d7a10903a4825c270ff5696;hpb=ba598f2a1c377a42c76088cc7e234917ab25e693;p=supertux.git diff --git a/src/scripting/serialize.cpp b/src/scripting/serialize.cpp index 7d7992d35..79be04c4b 100644 --- a/src/scripting/serialize.cpp +++ b/src/scripting/serialize.cpp @@ -1,3 +1,23 @@ +// $Id$ +// +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +#include + #include "serialize.hpp" #include @@ -11,7 +31,7 @@ namespace Scripting { -void load_squirrel_table(HSQUIRRELVM vm, int table_idx, const lisp::Lisp* lisp) +void load_squirrel_table(HSQUIRRELVM vm, SQInteger table_idx, const lisp::Lisp* lisp) { using namespace lisp; @@ -19,7 +39,7 @@ void load_squirrel_table(HSQUIRRELVM vm, int table_idx, const lisp::Lisp* lisp) table_idx -= 2; lisp::ListIterator iter(lisp); - while(iter.next()) { + while(iter.next() && iter.lisp() != NULL) { const std::string& token = iter.item(); sq_pushstring(vm, token.c_str(), token.size()); @@ -55,7 +75,7 @@ void load_squirrel_table(HSQUIRRELVM vm, int table_idx, const lisp::Lisp* lisp) } } -void save_squirrel_table(HSQUIRRELVM vm, int table_idx, lisp::Writer& writer) +void save_squirrel_table(HSQUIRRELVM vm, SQInteger table_idx, lisp::Writer& writer) { // offset because of sq_pushnull if(table_idx < 0) @@ -68,32 +88,32 @@ void save_squirrel_table(HSQUIRRELVM vm, int table_idx, lisp::Writer& writer) std::cerr << "Table contains non-string key\n"; continue; } - const char* key; + const SQChar* key; sq_getstring(vm, -2, &key); switch(sq_gettype(vm, -1)) { case OT_INTEGER: { - int val; + SQInteger val; sq_getinteger(vm, -1, &val); - writer.write_int(key, val); + writer.write_int(key, static_cast (val)); break; } case OT_FLOAT: { - float val; + SQFloat val; sq_getfloat(vm, -1, &val); - writer.write_float(key, val); + writer.write_float(key, static_cast (val)); break; } case OT_BOOL: { SQBool val; sq_getbool(vm, -1, &val); - writer.write_bool(key, val); + writer.write_bool(key, val == SQTrue); break; } case OT_STRING: { - const char* str; + const SQChar* str; sq_getstring(vm, -1, &str); - writer.write_string(key, str); + writer.write_string(key, reinterpret_cast (str)); break; } case OT_TABLE: {