X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fscripting%2Fsquirrel_util.hpp;h=aac6492f5e14670acaa904eff03780d9ea51ea82;hb=0b73428a8a9e9563cb196e4b13167de3ec5f6b02;hp=da61b26744b7e9438c70cb2e450eafb9243ed4be;hpb=4a308ce51f1300ad7c9c041272521f6df71036de;p=supertux.git diff --git a/src/scripting/squirrel_util.hpp b/src/scripting/squirrel_util.hpp index da61b2674..aac6492f5 100644 --- a/src/scripting/squirrel_util.hpp +++ b/src/scripting/squirrel_util.hpp @@ -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,94 +12,95 @@ // 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. -#ifndef __SQUIRREL_UTIL_HPP__ -#define __SQUIRREL_UTIL_HPP__ +// along with this program. If not, see . + +#ifndef HEADER_SUPERTUX_SCRIPTING_SQUIRREL_UTIL_HPP +#define HEADER_SUPERTUX_SCRIPTING_SQUIRREL_UTIL_HPP -#include #include -#include -#include -#include "wrapper.hpp" -#include "squirrel_error.hpp" -namespace Scripting -{ +#include "scripting/squirrel_error.hpp" +#include "scripting/wrapper.hpp" + +namespace scripting { + +extern HSQUIRRELVM global_vm; - extern HSQUIRRELVM global_vm; +void init_squirrel(bool enable_debugger); +void exit_squirrel(); +void update_debugger(); - void init_squirrel(bool enable_debugger); - void exit_squirrel(); - void update_debugger(); +std::string squirrel2string(HSQUIRRELVM vm, SQInteger i); +void print_squirrel_stack(HSQUIRRELVM vm); - std::string squirrel2string(HSQUIRRELVM vm, SQInteger i); - void print_squirrel_stack(HSQUIRRELVM vm); +SQInteger squirrel_read_char(SQUserPointer file); - HSQOBJECT create_thread(HSQUIRRELVM vm); - SQObject vm_to_object(HSQUIRRELVM vm); - HSQUIRRELVM object_to_vm(HSQOBJECT object); +HSQOBJECT create_thread(HSQUIRRELVM vm); +SQObject vm_to_object(HSQUIRRELVM vm); +HSQUIRRELVM object_to_vm(HSQOBJECT object); - void compile_script(HSQUIRRELVM vm, std::istream& in, - const std::string& sourcename); - void compile_and_run(HSQUIRRELVM vm, std::istream& in, - const std::string& sourcename); +void compile_script(HSQUIRRELVM vm, std::istream& in, + const std::string& sourcename); +void compile_and_run(HSQUIRRELVM vm, std::istream& in, + const std::string& sourcename); - template - void expose_object(HSQUIRRELVM v, SQInteger table_idx, T* object, - const std::string& name, bool free = false) - { - sq_pushstring(v, name.c_str(), -1); - Scripting::create_squirrel_instance(v, object, free); +template +void expose_object(HSQUIRRELVM v, SQInteger table_idx, T* object, + const std::string& name, bool free = false) +{ + sq_pushstring(v, name.c_str(), -1); + scripting::create_squirrel_instance(v, object, free); - if(table_idx < 0) - table_idx -= 2; + if(table_idx < 0) + table_idx -= 2; - // register instance in root table - if(SQ_FAILED(sq_createslot(v, table_idx))) { - std::ostringstream msg; - msg << "Couldn't register object '" << name << "' in squirrel table"; - throw Scripting::SquirrelError(v, msg.str()); - } + // register instance in root table + if(SQ_FAILED(sq_createslot(v, table_idx))) { + std::ostringstream msg; + msg << "Couldn't register object '" << name << "' in squirrel table"; + throw scripting::SquirrelError(v, msg.str()); } +} - static inline void unexpose_object(HSQUIRRELVM v, SQInteger table_idx, - const std::string& name) - { - sq_pushstring(v, name.c_str(), name.length()); +static inline void unexpose_object(HSQUIRRELVM v, SQInteger table_idx, + const std::string& name) +{ + sq_pushstring(v, name.c_str(), name.length()); - if(table_idx < 0) - table_idx -= 1; + if(table_idx < 0) + table_idx -= 1; - if(SQ_FAILED(sq_deleteslot(v, table_idx, SQFalse))) { - std::ostringstream msg; - msg << "Couldn't unregister object '" << name << "' in squirrel root table"; - throw Scripting::SquirrelError(v, msg.str()); - } + if(SQ_FAILED(sq_deleteslot(v, table_idx, SQFalse))) { + std::ostringstream msg; + msg << "Couldn't unregister object '" << name << "' in squirrel root table"; + throw scripting::SquirrelError(v, msg.str()); } +} - // begin serialization functions - void store_float(HSQUIRRELVM vm, const char* name, float val); - void store_int(HSQUIRRELVM vm, const char* name, int val); - void store_string(HSQUIRRELVM vm, const char* name, const std::string& val); - void store_bool(HSQUIRRELVM vm, const char* name, bool val); +// begin serialization functions +void store_float(HSQUIRRELVM vm, const char* name, float val); +void store_int(HSQUIRRELVM vm, const char* name, int val); +void store_string(HSQUIRRELVM vm, const char* name, const std::string& val); +void store_bool(HSQUIRRELVM vm, const char* name, bool val); - bool has_float(HSQUIRRELVM vm, const char* name); - bool has_int(HSQUIRRELVM vm, const char* name); - bool has_string(HSQUIRRELVM vm, const char* name); - bool has_bool(HSQUIRRELVM vm, const char* name); +bool has_float(HSQUIRRELVM vm, const char* name); +bool has_int(HSQUIRRELVM vm, const char* name); +bool has_string(HSQUIRRELVM vm, const char* name); +bool has_bool(HSQUIRRELVM vm, const char* name); - bool get_float(HSQUIRRELVM vm, const char* name, float& val); - bool get_int(HSQUIRRELVM vm, const char* name, int& val); - bool get_string(HSQUIRRELVM vm, const char* name, std::string& val); - bool get_bool(HSQUIRRELVM vm, const char* name, bool& val); +bool get_float(HSQUIRRELVM vm, const char* name, float& val); +bool get_int(HSQUIRRELVM vm, const char* name, int& val); +bool get_string(HSQUIRRELVM vm, const char* name, std::string& val); +bool get_bool(HSQUIRRELVM vm, const char* name, bool& val); - float read_float(HSQUIRRELVM vm, const char* name); - int read_int(HSQUIRRELVM vm, const char* name); - std::string read_string(HSQUIRRELVM vm, const char* name); - bool read_bool(HSQUIRRELVM vm, const char* name); - // end serialization functions +float read_float(HSQUIRRELVM vm, const char* name); +int read_int(HSQUIRRELVM vm, const char* name); +std::string read_string(HSQUIRRELVM vm, const char* name); +bool read_bool(HSQUIRRELVM vm, const char* name); +// end serialization functions } #endif + +/* EOF */