X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fscripting%2Fwrapper.cpp;h=8eba394b8ecb64b7b0362097f6d7bce41ffb240e;hb=b72c5d178e4cc95130735d8bf8716513c7cc28e1;hp=50734e10874cb99e2ce8852ddb8e5d065bc35b2d;hpb=43c0eee23cceb62937e75c1652bb50572b854c8b;p=supertux.git diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 50734e108..8eba394b8 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -8,42 +8,23 @@ #include #include #include +#include #include -#include "wrapper_util.hpp" +#include "squirrel_error.hpp" #include "wrapper.interface.hpp" -namespace SquirrelWrapper +namespace Scripting +{ +namespace Wrapper { - -using namespace Scripting; static int DisplayEffect_release_hook(SQUserPointer ptr, int ) { - DisplayEffect* _this = reinterpret_cast (ptr); + Scripting::DisplayEffect* _this = reinterpret_cast (ptr); delete _this; return 0; } -void create_squirrel_instance(HSQUIRRELVM v, DisplayEffect* object, bool setup_releasehook) -{ - sq_pushstring(v, "DisplayEffect", -1); - if(sq_get(v, -2) < 0) { - std::ostringstream msg; - msg << "Couldn't resolved squirrel type 'DisplayEffect'"; - throw SquirrelError(v, msg.str()); - } - - if(sq_createinstance(v, -1) < 0 || sq_setinstanceup(v, -1, object) < 0) { - std::ostringstream msg; - msg << "Couldn't setup squirrel instance for object of type 'DisplayEffect'"; - throw SquirrelError(v, msg.str()); - } - sq_remove(v, -2); - - if(setup_releasehook) { - sq_setreleasehook(v, -1, DisplayEffect_release_hook); - } -} static int DisplayEffect_fade_out_wrapper(HSQUIRRELVM v) { Scripting::DisplayEffect* _this; @@ -93,31 +74,11 @@ static int DisplayEffect_is_black_wrapper(HSQUIRRELVM v) static int Camera_release_hook(SQUserPointer ptr, int ) { - Camera* _this = reinterpret_cast (ptr); + Scripting::Camera* _this = reinterpret_cast (ptr); delete _this; return 0; } -void create_squirrel_instance(HSQUIRRELVM v, Camera* object, bool setup_releasehook) -{ - sq_pushstring(v, "Camera", -1); - if(sq_get(v, -2) < 0) { - std::ostringstream msg; - msg << "Couldn't resolved squirrel type 'Camera'"; - throw SquirrelError(v, msg.str()); - } - - if(sq_createinstance(v, -1) < 0 || sq_setinstanceup(v, -1, object) < 0) { - std::ostringstream msg; - msg << "Couldn't setup squirrel instance for object of type 'Camera'"; - throw SquirrelError(v, msg.str()); - } - sq_remove(v, -2); - - if(setup_releasehook) { - sq_setreleasehook(v, -1, Camera_release_hook); - } -} static int Camera_shake_wrapper(HSQUIRRELVM v) { Scripting::Camera* _this; @@ -162,31 +123,11 @@ static int Camera_set_mode_wrapper(HSQUIRRELVM v) static int Level_release_hook(SQUserPointer ptr, int ) { - Level* _this = reinterpret_cast (ptr); + Scripting::Level* _this = reinterpret_cast (ptr); delete _this; return 0; } -void create_squirrel_instance(HSQUIRRELVM v, Level* object, bool setup_releasehook) -{ - sq_pushstring(v, "Level", -1); - if(sq_get(v, -2) < 0) { - std::ostringstream msg; - msg << "Couldn't resolved squirrel type 'Level'"; - throw SquirrelError(v, msg.str()); - } - - if(sq_createinstance(v, -1) < 0 || sq_setinstanceup(v, -1, object) < 0) { - std::ostringstream msg; - msg << "Couldn't setup squirrel instance for object of type 'Level'"; - throw SquirrelError(v, msg.str()); - } - sq_remove(v, -2); - - if(setup_releasehook) { - sq_setreleasehook(v, -1, Level_release_hook); - } -} static int Level_finish_wrapper(HSQUIRRELVM v) { Scripting::Level* _this; @@ -223,31 +164,11 @@ static int Level_flip_vertically_wrapper(HSQUIRRELVM v) static int ScriptedObject_release_hook(SQUserPointer ptr, int ) { - ScriptedObject* _this = reinterpret_cast (ptr); + Scripting::ScriptedObject* _this = reinterpret_cast (ptr); delete _this; return 0; } -void create_squirrel_instance(HSQUIRRELVM v, ScriptedObject* object, bool setup_releasehook) -{ - sq_pushstring(v, "ScriptedObject", -1); - if(sq_get(v, -2) < 0) { - std::ostringstream msg; - msg << "Couldn't resolved squirrel type 'ScriptedObject'"; - throw SquirrelError(v, msg.str()); - } - - if(sq_createinstance(v, -1) < 0 || sq_setinstanceup(v, -1, object) < 0) { - std::ostringstream msg; - msg << "Couldn't setup squirrel instance for object of type 'ScriptedObject'"; - throw SquirrelError(v, msg.str()); - } - sq_remove(v, -2); - - if(setup_releasehook) { - sq_setreleasehook(v, -1, ScriptedObject_release_hook); - } -} static int ScriptedObject_set_animation_wrapper(HSQUIRRELVM v) { Scripting::ScriptedObject* _this; @@ -393,31 +314,11 @@ static int ScriptedObject_get_name_wrapper(HSQUIRRELVM v) static int Sound_release_hook(SQUserPointer ptr, int ) { - Sound* _this = reinterpret_cast (ptr); + Scripting::Sound* _this = reinterpret_cast (ptr); delete _this; return 0; } -void create_squirrel_instance(HSQUIRRELVM v, Sound* object, bool setup_releasehook) -{ - sq_pushstring(v, "Sound", -1); - if(sq_get(v, -2) < 0) { - std::ostringstream msg; - msg << "Couldn't resolved squirrel type 'Sound'"; - throw SquirrelError(v, msg.str()); - } - - if(sq_createinstance(v, -1) < 0 || sq_setinstanceup(v, -1, object) < 0) { - std::ostringstream msg; - msg << "Couldn't setup squirrel instance for object of type 'Sound'"; - throw SquirrelError(v, msg.str()); - } - sq_remove(v, -2); - - if(setup_releasehook) { - sq_setreleasehook(v, -1, Sound_release_hook); - } -} static int Sound_play_music_wrapper(HSQUIRRELVM v) { Scripting::Sound* _this; @@ -444,31 +345,11 @@ static int Sound_play_wrapper(HSQUIRRELVM v) static int Text_release_hook(SQUserPointer ptr, int ) { - Text* _this = reinterpret_cast (ptr); + Scripting::Text* _this = reinterpret_cast (ptr); delete _this; return 0; } -void create_squirrel_instance(HSQUIRRELVM v, Text* object, bool setup_releasehook) -{ - sq_pushstring(v, "Text", -1); - if(sq_get(v, -2) < 0) { - std::ostringstream msg; - msg << "Couldn't resolved squirrel type 'Text'"; - throw SquirrelError(v, msg.str()); - } - - if(sq_createinstance(v, -1) < 0 || sq_setinstanceup(v, -1, object) < 0) { - std::ostringstream msg; - msg << "Couldn't setup squirrel instance for object of type 'Text'"; - throw SquirrelError(v, msg.str()); - } - sq_remove(v, -2); - - if(setup_releasehook) { - sq_setreleasehook(v, -1, Text_release_hook); - } -} static int Text_set_text_wrapper(HSQUIRRELVM v) { Scripting::Text* _this; @@ -531,75 +412,11 @@ static int Text_set_visible_wrapper(HSQUIRRELVM v) static int Player_release_hook(SQUserPointer ptr, int ) { - Player* _this = reinterpret_cast (ptr); + Scripting::Player* _this = reinterpret_cast (ptr); delete _this; return 0; } -void create_squirrel_instance(HSQUIRRELVM v, Player* object, bool setup_releasehook) -{ - sq_pushstring(v, "Player", -1); - if(sq_get(v, -2) < 0) { - std::ostringstream msg; - msg << "Couldn't resolved squirrel type 'Player'"; - throw SquirrelError(v, msg.str()); - } - - if(sq_createinstance(v, -1) < 0 || sq_setinstanceup(v, -1, object) < 0) { - std::ostringstream msg; - msg << "Couldn't setup squirrel instance for object of type 'Player'"; - throw SquirrelError(v, msg.str()); - } - sq_remove(v, -2); - - if(setup_releasehook) { - sq_setreleasehook(v, -1, Player_release_hook); - } -} -static int Player_set_bonus_wrapper(HSQUIRRELVM v) -{ - Scripting::Player* _this; - sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); - const char* arg0; - sq_getstring(v, 2, &arg0); - - _this->set_bonus(arg0); - - return 0; -} - -static int Player_make_invincible_wrapper(HSQUIRRELVM v) -{ - Scripting::Player* _this; - sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); - - _this->make_invincible(); - - return 0; -} - -static int Player_add_life_wrapper(HSQUIRRELVM v) -{ - Scripting::Player* _this; - sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); - - _this->add_life(); - - return 0; -} - -static int Player_add_coins_wrapper(HSQUIRRELVM v) -{ - Scripting::Player* _this; - sq_getinstanceup(v, 1, (SQUserPointer*) &_this, 0); - int arg0; - sq_getinteger(v, 2, &arg0); - - _this->add_coins(arg0); - - return 0; -} - static int display_text_file_wrapper(HSQUIRRELVM v) { const char* arg0; @@ -642,12 +459,248 @@ static int import_wrapper(HSQUIRRELVM v) return 0; } +static int add_key_wrapper(HSQUIRRELVM v) +{ + int arg0; + sq_getinteger(v, 2, &arg0); + + Scripting::add_key(arg0); + + return 0; +} + +} // end of namespace Wrapper + +void create_squirrel_instance(HSQUIRRELVM v, Scripting::DisplayEffect* object, bool setup_releasehook) +{ + using namespace Wrapper; + + sq_pushroottable(v); + sq_pushstring(v, "DisplayEffect", -1); + if(SQ_FAILED(sq_get(v, -2))) { + std::ostringstream msg; + msg << "Couldn't resolved squirrel type 'DisplayEffect'"; + throw SquirrelError(v, msg.str()); + } + + if(SQ_FAILED(sq_createinstance(v, -1)) || SQ_FAILED(sq_setinstanceup(v, -1, object))) { + std::ostringstream msg; + msg << "Couldn't setup squirrel instance for object of type 'DisplayEffect'"; + throw SquirrelError(v, msg.str()); + } + sq_remove(v, -2); // remove object name + + if(setup_releasehook) { + sq_setreleasehook(v, -1, DisplayEffect_release_hook); + } + + sq_remove(v, -2); // remove root table +} + +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Camera* object, bool setup_releasehook) +{ + using namespace Wrapper; + + sq_pushroottable(v); + sq_pushstring(v, "Camera", -1); + if(SQ_FAILED(sq_get(v, -2))) { + std::ostringstream msg; + msg << "Couldn't resolved squirrel type 'Camera'"; + throw SquirrelError(v, msg.str()); + } + + if(SQ_FAILED(sq_createinstance(v, -1)) || SQ_FAILED(sq_setinstanceup(v, -1, object))) { + std::ostringstream msg; + msg << "Couldn't setup squirrel instance for object of type 'Camera'"; + throw SquirrelError(v, msg.str()); + } + sq_remove(v, -2); // remove object name + + if(setup_releasehook) { + sq_setreleasehook(v, -1, Camera_release_hook); + } + + sq_remove(v, -2); // remove root table +} + +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Level* object, bool setup_releasehook) +{ + using namespace Wrapper; + + sq_pushroottable(v); + sq_pushstring(v, "Level", -1); + if(SQ_FAILED(sq_get(v, -2))) { + std::ostringstream msg; + msg << "Couldn't resolved squirrel type 'Level'"; + throw SquirrelError(v, msg.str()); + } + + if(SQ_FAILED(sq_createinstance(v, -1)) || SQ_FAILED(sq_setinstanceup(v, -1, object))) { + std::ostringstream msg; + msg << "Couldn't setup squirrel instance for object of type 'Level'"; + throw SquirrelError(v, msg.str()); + } + sq_remove(v, -2); // remove object name + + if(setup_releasehook) { + sq_setreleasehook(v, -1, Level_release_hook); + } + + sq_remove(v, -2); // remove root table +} + +void create_squirrel_instance(HSQUIRRELVM v, Scripting::ScriptedObject* object, bool setup_releasehook) +{ + using namespace Wrapper; + + sq_pushroottable(v); + sq_pushstring(v, "ScriptedObject", -1); + if(SQ_FAILED(sq_get(v, -2))) { + std::ostringstream msg; + msg << "Couldn't resolved squirrel type 'ScriptedObject'"; + throw SquirrelError(v, msg.str()); + } + + if(SQ_FAILED(sq_createinstance(v, -1)) || SQ_FAILED(sq_setinstanceup(v, -1, object))) { + std::ostringstream msg; + msg << "Couldn't setup squirrel instance for object of type 'ScriptedObject'"; + throw SquirrelError(v, msg.str()); + } + sq_remove(v, -2); // remove object name + + if(setup_releasehook) { + sq_setreleasehook(v, -1, ScriptedObject_release_hook); + } + + sq_remove(v, -2); // remove root table +} + +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Sound* object, bool setup_releasehook) +{ + using namespace Wrapper; + + sq_pushroottable(v); + sq_pushstring(v, "Sound", -1); + if(SQ_FAILED(sq_get(v, -2))) { + std::ostringstream msg; + msg << "Couldn't resolved squirrel type 'Sound'"; + throw SquirrelError(v, msg.str()); + } + + if(SQ_FAILED(sq_createinstance(v, -1)) || SQ_FAILED(sq_setinstanceup(v, -1, object))) { + std::ostringstream msg; + msg << "Couldn't setup squirrel instance for object of type 'Sound'"; + throw SquirrelError(v, msg.str()); + } + sq_remove(v, -2); // remove object name + + if(setup_releasehook) { + sq_setreleasehook(v, -1, Sound_release_hook); + } + + sq_remove(v, -2); // remove root table +} + +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Text* object, bool setup_releasehook) +{ + using namespace Wrapper; + + sq_pushroottable(v); + sq_pushstring(v, "Text", -1); + if(SQ_FAILED(sq_get(v, -2))) { + std::ostringstream msg; + msg << "Couldn't resolved squirrel type 'Text'"; + throw SquirrelError(v, msg.str()); + } + + if(SQ_FAILED(sq_createinstance(v, -1)) || SQ_FAILED(sq_setinstanceup(v, -1, object))) { + std::ostringstream msg; + msg << "Couldn't setup squirrel instance for object of type 'Text'"; + throw SquirrelError(v, msg.str()); + } + sq_remove(v, -2); // remove object name + + if(setup_releasehook) { + sq_setreleasehook(v, -1, Text_release_hook); + } + + sq_remove(v, -2); // remove root table +} + +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Player* object, bool setup_releasehook) +{ + using namespace Wrapper; + + sq_pushroottable(v); + sq_pushstring(v, "Player", -1); + if(SQ_FAILED(sq_get(v, -2))) { + std::ostringstream msg; + msg << "Couldn't resolved squirrel type 'Player'"; + throw SquirrelError(v, msg.str()); + } + + if(SQ_FAILED(sq_createinstance(v, -1)) || SQ_FAILED(sq_setinstanceup(v, -1, object))) { + std::ostringstream msg; + msg << "Couldn't setup squirrel instance for object of type 'Player'"; + throw SquirrelError(v, msg.str()); + } + sq_remove(v, -2); // remove object name + + if(setup_releasehook) { + sq_setreleasehook(v, -1, Player_release_hook); + } + + sq_remove(v, -2); // remove root table +} + void register_supertux_wrapper(HSQUIRRELVM v) { + using namespace Wrapper; + sq_pushroottable(v); + sq_pushstring(v, "KEY_BRASS", -1); + sq_pushinteger(v, 1); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'KEY_BRASS'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "KEY_IRON", -1); + sq_pushinteger(v, 2); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'KEY_IRON'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "KEY_BRONZE", -1); + sq_pushinteger(v, 4); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'KEY_BRONZE'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "KEY_SILVER", -1); + sq_pushinteger(v, 8); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'KEY_SILVER'"; + throw SquirrelError(v, msg.str()); + } + + sq_pushstring(v, "KEY_GOLD", -1); + sq_pushinteger(v, 16); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register constant'KEY_GOLD'"; + throw SquirrelError(v, msg.str()); + } + sq_pushstring(v, "display_text_file", -1); sq_newclosure(v, &display_text_file_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'display_text_file'"; throw SquirrelError(v, msg.str()); @@ -655,7 +708,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "wait", -1); sq_newclosure(v, &wait_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'wait'"; throw SquirrelError(v, msg.str()); @@ -663,7 +716,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "translate", -1); sq_newclosure(v, &translate_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'translate'"; throw SquirrelError(v, msg.str()); @@ -671,12 +724,20 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "import", -1); sq_newclosure(v, &import_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'import'"; throw SquirrelError(v, msg.str()); } + sq_pushstring(v, "add_key", -1); + sq_newclosure(v, &add_key_wrapper, 0); + if(SQ_FAILED(sq_createslot(v, -3))) { + std::ostringstream msg; + msg << "Couldn't register function'add_key'"; + throw SquirrelError(v, msg.str()); + } + // Register class DisplayEffect sq_pushstring(v, "DisplayEffect", -1); if(sq_newclass(v, SQFalse) < 0) { @@ -686,7 +747,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) } sq_pushstring(v, "fade_out", -1); sq_newclosure(v, &DisplayEffect_fade_out_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'fade_out'"; throw SquirrelError(v, msg.str()); @@ -694,7 +755,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "fade_in", -1); sq_newclosure(v, &DisplayEffect_fade_in_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'fade_in'"; throw SquirrelError(v, msg.str()); @@ -702,7 +763,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "set_black", -1); sq_newclosure(v, &DisplayEffect_set_black_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'set_black'"; throw SquirrelError(v, msg.str()); @@ -710,13 +771,13 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "is_black", -1); sq_newclosure(v, &DisplayEffect_is_black_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'is_black'"; throw SquirrelError(v, msg.str()); } - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register class'DisplayEffect'"; throw SquirrelError(v, msg.str()); @@ -731,7 +792,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) } sq_pushstring(v, "shake", -1); sq_newclosure(v, &Camera_shake_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'shake'"; throw SquirrelError(v, msg.str()); @@ -739,7 +800,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "set_pos", -1); sq_newclosure(v, &Camera_set_pos_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'set_pos'"; throw SquirrelError(v, msg.str()); @@ -747,13 +808,13 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "set_mode", -1); sq_newclosure(v, &Camera_set_mode_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'set_mode'"; throw SquirrelError(v, msg.str()); } - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register class'Camera'"; throw SquirrelError(v, msg.str()); @@ -768,7 +829,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) } sq_pushstring(v, "finish", -1); sq_newclosure(v, &Level_finish_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'finish'"; throw SquirrelError(v, msg.str()); @@ -776,7 +837,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "spawn", -1); sq_newclosure(v, &Level_spawn_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'spawn'"; throw SquirrelError(v, msg.str()); @@ -784,13 +845,13 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "flip_vertically", -1); sq_newclosure(v, &Level_flip_vertically_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'flip_vertically'"; throw SquirrelError(v, msg.str()); } - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register class'Level'"; throw SquirrelError(v, msg.str()); @@ -805,7 +866,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) } sq_pushstring(v, "set_animation", -1); sq_newclosure(v, &ScriptedObject_set_animation_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'set_animation'"; throw SquirrelError(v, msg.str()); @@ -813,7 +874,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "get_animation", -1); sq_newclosure(v, &ScriptedObject_get_animation_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'get_animation'"; throw SquirrelError(v, msg.str()); @@ -821,7 +882,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "move", -1); sq_newclosure(v, &ScriptedObject_move_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'move'"; throw SquirrelError(v, msg.str()); @@ -829,7 +890,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "set_pos", -1); sq_newclosure(v, &ScriptedObject_set_pos_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'set_pos'"; throw SquirrelError(v, msg.str()); @@ -837,7 +898,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "get_pos_x", -1); sq_newclosure(v, &ScriptedObject_get_pos_x_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'get_pos_x'"; throw SquirrelError(v, msg.str()); @@ -845,7 +906,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "get_pos_y", -1); sq_newclosure(v, &ScriptedObject_get_pos_y_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'get_pos_y'"; throw SquirrelError(v, msg.str()); @@ -853,7 +914,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "set_velocity", -1); sq_newclosure(v, &ScriptedObject_set_velocity_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'set_velocity'"; throw SquirrelError(v, msg.str()); @@ -861,7 +922,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "get_velocity_x", -1); sq_newclosure(v, &ScriptedObject_get_velocity_x_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'get_velocity_x'"; throw SquirrelError(v, msg.str()); @@ -869,7 +930,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "get_velocity_y", -1); sq_newclosure(v, &ScriptedObject_get_velocity_y_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'get_velocity_y'"; throw SquirrelError(v, msg.str()); @@ -877,7 +938,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "set_visible", -1); sq_newclosure(v, &ScriptedObject_set_visible_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'set_visible'"; throw SquirrelError(v, msg.str()); @@ -885,7 +946,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "is_visible", -1); sq_newclosure(v, &ScriptedObject_is_visible_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'is_visible'"; throw SquirrelError(v, msg.str()); @@ -893,13 +954,13 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "get_name", -1); sq_newclosure(v, &ScriptedObject_get_name_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'get_name'"; throw SquirrelError(v, msg.str()); } - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register class'ScriptedObject'"; throw SquirrelError(v, msg.str()); @@ -914,7 +975,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) } sq_pushstring(v, "play_music", -1); sq_newclosure(v, &Sound_play_music_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'play_music'"; throw SquirrelError(v, msg.str()); @@ -922,13 +983,13 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "play", -1); sq_newclosure(v, &Sound_play_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'play'"; throw SquirrelError(v, msg.str()); } - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register class'Sound'"; throw SquirrelError(v, msg.str()); @@ -943,7 +1004,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) } sq_pushstring(v, "set_text", -1); sq_newclosure(v, &Text_set_text_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'set_text'"; throw SquirrelError(v, msg.str()); @@ -951,7 +1012,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "set_font", -1); sq_newclosure(v, &Text_set_font_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'set_font'"; throw SquirrelError(v, msg.str()); @@ -959,7 +1020,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "fade_in", -1); sq_newclosure(v, &Text_fade_in_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'fade_in'"; throw SquirrelError(v, msg.str()); @@ -967,7 +1028,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "fade_out", -1); sq_newclosure(v, &Text_fade_out_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'fade_out'"; throw SquirrelError(v, msg.str()); @@ -975,13 +1036,13 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pushstring(v, "set_visible", -1); sq_newclosure(v, &Text_set_visible_wrapper, 0); - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register function'set_visible'"; throw SquirrelError(v, msg.str()); } - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register class'Text'"; throw SquirrelError(v, msg.str()); @@ -994,39 +1055,7 @@ void register_supertux_wrapper(HSQUIRRELVM v) msg << "Couldn't create new class 'Player'"; throw SquirrelError(v, msg.str()); } - sq_pushstring(v, "set_bonus", -1); - sq_newclosure(v, &Player_set_bonus_wrapper, 0); - if(sq_createslot(v, -3) < 0) { - std::ostringstream msg; - msg << "Couldn't register function'set_bonus'"; - throw SquirrelError(v, msg.str()); - } - - sq_pushstring(v, "make_invincible", -1); - sq_newclosure(v, &Player_make_invincible_wrapper, 0); - if(sq_createslot(v, -3) < 0) { - std::ostringstream msg; - msg << "Couldn't register function'make_invincible'"; - throw SquirrelError(v, msg.str()); - } - - sq_pushstring(v, "add_life", -1); - sq_newclosure(v, &Player_add_life_wrapper, 0); - if(sq_createslot(v, -3) < 0) { - std::ostringstream msg; - msg << "Couldn't register function'add_life'"; - throw SquirrelError(v, msg.str()); - } - - sq_pushstring(v, "add_coins", -1); - sq_newclosure(v, &Player_add_coins_wrapper, 0); - if(sq_createslot(v, -3) < 0) { - std::ostringstream msg; - msg << "Couldn't register function'add_coins'"; - throw SquirrelError(v, msg.str()); - } - - if(sq_createslot(v, -3) < 0) { + if(SQ_FAILED(sq_createslot(v, -3))) { std::ostringstream msg; msg << "Couldn't register class'Player'"; throw SquirrelError(v, msg.str()); @@ -1035,5 +1064,5 @@ void register_supertux_wrapper(HSQUIRRELVM v) sq_pop(v, 1); } -} +} // end of namespace Scripting