X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fscripting%2Fserialize.cpp;h=ff3c859bcd3de8b08ce9f4085177ad11e0a4e255;hb=0b73428a8a9e9563cb196e4b13167de3ec5f6b02;hp=98341e29c191704a4b3eead064a1771e33806e74;hpb=5254e223656d8a4f9c4c7f681f96f9a92b0b5799;p=supertux.git diff --git a/src/scripting/serialize.cpp b/src/scripting/serialize.cpp index 98341e29c..ff3c859bc 100644 --- a/src/scripting/serialize.cpp +++ b/src/scripting/serialize.cpp @@ -1,12 +1,10 @@ -// $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 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 3 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 @@ -14,30 +12,26 @@ // 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. +// along with this program. If not, see . -#include "serialize.hpp" +#include "scripting/serialize.hpp" + +#include -#include -#include -#include "lisp/lisp.hpp" -#include "lisp/list_iterator.hpp" -#include "lisp/parser.hpp" #include "lisp/writer.hpp" -#include "squirrel_error.hpp" +#include "lisp/list_iterator.hpp" +#include "scripting/squirrel_error.hpp" -namespace Scripting -{ +namespace scripting { -void load_squirrel_table(HSQUIRRELVM vm, SQInteger table_idx, const lisp::Lisp* lisp) +void load_squirrel_table(HSQUIRRELVM vm, SQInteger table_idx, const Reader& lisp) { using namespace lisp; if(table_idx < 0) - table_idx -= 2; - - lisp::ListIterator iter(lisp); + table_idx -= 2; + + lisp::ListIterator iter(&lisp); while(iter.next() && iter.lisp() != NULL) { const std::string& token = iter.item(); sq_pushstring(vm, token.c_str(), token.size()); @@ -46,7 +40,7 @@ void load_squirrel_table(HSQUIRRELVM vm, SQInteger table_idx, const lisp::Lisp* switch(value->get_type()) { case Lisp::TYPE_CONS: sq_newtable(vm); - load_squirrel_table(vm, sq_gettop(vm), iter.lisp()); + load_squirrel_table(vm, sq_gettop(vm), *iter.lisp()); break; case Lisp::TYPE_INTEGER: sq_pushinteger(vm, value->get_int()); @@ -70,16 +64,16 @@ void load_squirrel_table(HSQUIRRELVM vm, SQInteger table_idx, const lisp::Lisp* } if(SQ_FAILED(sq_createslot(vm, table_idx))) - throw Scripting::SquirrelError(vm, "Couldn't create new index"); + throw scripting::SquirrelError(vm, "Couldn't create new index"); } } -void save_squirrel_table(HSQUIRRELVM vm, SQInteger table_idx, lisp::Writer& writer) +void save_squirrel_table(HSQUIRRELVM vm, SQInteger table_idx, Writer& writer) { // offset because of sq_pushnull if(table_idx < 0) table_idx -= 1; - + //iterator table sq_pushnull(vm); while(SQ_SUCCEEDED(sq_next(vm, table_idx))) { @@ -94,25 +88,25 @@ void save_squirrel_table(HSQUIRRELVM vm, SQInteger table_idx, lisp::Writer& writ case OT_INTEGER: { SQInteger val; sq_getinteger(vm, -1, &val); - writer.write_int(key, static_cast (val)); + writer.write(key, static_cast (val)); break; } case OT_FLOAT: { SQFloat val; sq_getfloat(vm, -1, &val); - writer.write_float(key, static_cast (val)); + writer.write(key, static_cast (val)); break; } case OT_BOOL: { SQBool val; sq_getbool(vm, -1, &val); - writer.write_bool(key, val == SQTrue); + writer.write(key, val == SQTrue); break; } case OT_STRING: { const SQChar* str; sq_getstring(vm, -1, &str); - writer.write_string(key, reinterpret_cast (str)); + writer.write(key, reinterpret_cast (str)); break; } case OT_TABLE: { @@ -134,5 +128,6 @@ void save_squirrel_table(HSQUIRRELVM vm, SQInteger table_idx, lisp::Writer& writ sq_pop(vm, 1); } -} +} // namespace scripting +/* EOF */