From: Matthias Braun Date: Sat, 2 Jul 2005 11:57:24 +0000 (+0000) Subject: fix namespace problems X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=c6a73ec922c4fbe72b0b0573c30ca8082bca800d;p=supertux.git fix namespace problems SVN-Revision: 2682 --- diff --git a/src/scripting/wrapper.cpp b/src/scripting/wrapper.cpp index 50734e108..512c55c10 100644 --- a/src/scripting/wrapper.cpp +++ b/src/scripting/wrapper.cpp @@ -15,16 +15,14 @@ namespace SquirrelWrapper { -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) +void create_squirrel_instance(HSQUIRRELVM v, Scripting::DisplayEffect* object, bool setup_releasehook) { sq_pushstring(v, "DisplayEffect", -1); if(sq_get(v, -2) < 0) { @@ -93,12 +91,12 @@ 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) +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Camera* object, bool setup_releasehook) { sq_pushstring(v, "Camera", -1); if(sq_get(v, -2) < 0) { @@ -162,12 +160,12 @@ 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) +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Level* object, bool setup_releasehook) { sq_pushstring(v, "Level", -1); if(sq_get(v, -2) < 0) { @@ -223,12 +221,12 @@ 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) +void create_squirrel_instance(HSQUIRRELVM v, Scripting::ScriptedObject* object, bool setup_releasehook) { sq_pushstring(v, "ScriptedObject", -1); if(sq_get(v, -2) < 0) { @@ -393,12 +391,12 @@ 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) +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Sound* object, bool setup_releasehook) { sq_pushstring(v, "Sound", -1); if(sq_get(v, -2) < 0) { @@ -444,12 +442,12 @@ 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) +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Text* object, bool setup_releasehook) { sq_pushstring(v, "Text", -1); if(sq_get(v, -2) < 0) { @@ -531,12 +529,12 @@ 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) +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Player* object, bool setup_releasehook) { sq_pushstring(v, "Player", -1); if(sq_get(v, -2) < 0) { diff --git a/src/scripting/wrapper.hpp b/src/scripting/wrapper.hpp index 77c6cc0f3..22b462679 100644 --- a/src/scripting/wrapper.hpp +++ b/src/scripting/wrapper.hpp @@ -7,32 +7,20 @@ #define __supertux_WRAPPER_H__ #include - -namespace Scripting -{ -class DisplayEffect; -class Camera; -class Level; -class ScriptedObject; -class Sound; -class Text; -class Player; -} +#include "wrapper.interface.hpp" namespace SquirrelWrapper { -using namespace Scripting; - void register_supertux_wrapper(HSQUIRRELVM v); -void create_squirrel_instance(HSQUIRRELVM v, DisplayEffect* object, bool setup_releasehook = false); -void create_squirrel_instance(HSQUIRRELVM v, Camera* object, bool setup_releasehook = false); -void create_squirrel_instance(HSQUIRRELVM v, Level* object, bool setup_releasehook = false); -void create_squirrel_instance(HSQUIRRELVM v, ScriptedObject* object, bool setup_releasehook = false); -void create_squirrel_instance(HSQUIRRELVM v, Sound* object, bool setup_releasehook = false); -void create_squirrel_instance(HSQUIRRELVM v, Text* object, bool setup_releasehook = false); -void create_squirrel_instance(HSQUIRRELVM v, Player* object, bool setup_releasehook = false); +void create_squirrel_instance(HSQUIRRELVM v, Scripting::DisplayEffect* object, bool setup_releasehook = false); +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Camera* object, bool setup_releasehook = false); +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Level* object, bool setup_releasehook = false); +void create_squirrel_instance(HSQUIRRELVM v, Scripting::ScriptedObject* object, bool setup_releasehook = false); +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Sound* object, bool setup_releasehook = false); +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Text* object, bool setup_releasehook = false); +void create_squirrel_instance(HSQUIRRELVM v, Scripting::Player* object, bool setup_releasehook = false); } diff --git a/tools/miniswig/create_wrapper.cpp b/tools/miniswig/create_wrapper.cpp index ed50a1529..767e5c48a 100644 --- a/tools/miniswig/create_wrapper.cpp +++ b/tools/miniswig/create_wrapper.cpp @@ -10,6 +10,11 @@ WrapperCreator::create_wrapper(Namespace* ns) { std::string fromfile = original_file != "" ? original_file : inputfile; + if(selected_namespace != "") { + ns_prefix = selected_namespace; + ns_prefix += "::"; + } + // hpp file hppout << "/**\n" @@ -21,35 +26,12 @@ WrapperCreator::create_wrapper(Namespace* ns) << "#define __" << modulename << "_WRAPPER_H__\n" << "\n" << "#include \n" + << "#include \"wrapper.interface.hpp\"\n" + << "\n" + << "namespace SquirrelWrapper\n" + << "{\n" << "\n"; - if(selected_namespace != "") { - hppout << "namespace " << selected_namespace << "\n" - << "{\n"; - } - for(std::vector::iterator i = ns->types.begin(); - i != ns->types.end(); ++i) { - AtomicType* type = *i; - Class* _class = dynamic_cast (type); - if(_class == 0) - continue; - hppout << "class " << _class->name << ";\n"; - } - - if(selected_namespace != "") { - hppout << "}\n"; - } - - hppout << "\n" - << "namespace SquirrelWrapper\n" - << "{\n" - << "\n"; - - if(selected_namespace != "") { - hppout << "using namespace " << selected_namespace << ";\n" - << "\n"; - } - hppout << "void register_" << modulename << "_wrapper(HSQUIRRELVM v);\n" << "\n"; @@ -61,7 +43,7 @@ WrapperCreator::create_wrapper(Namespace* ns) continue; hppout << "void create_squirrel_instance(HSQUIRRELVM v, " - << _class->name + << ns_prefix << _class->name << "* object, bool setup_releasehook = false);\n"; } hppout <<"\n" @@ -89,11 +71,6 @@ WrapperCreator::create_wrapper(Namespace* ns) << "{\n" << "\n"; - if(selected_namespace != "") { - out << "using namespace " << selected_namespace << ";\n"; - out << "\n"; - } - for(std::vector::iterator i = ns->types.begin(); i != ns->types.end(); ++i) { AtomicType* type = *i; @@ -426,7 +403,7 @@ void WrapperCreator::create_squirrel_instance(Class* _class) { out << "void create_squirrel_instance(HSQUIRRELVM v, " - << _class->name + << ns_prefix << _class->name << "* object, bool setup_releasehook)\n" << "{\n" << ind << "sq_pushstring(v, \"" << _class->name << "\", -1);\n" @@ -458,8 +435,9 @@ WrapperCreator::create_class_release_hook(Class* _class) { out << "static int " << _class->name << "_release_hook(SQUserPointer ptr, int )\n" << "{\n" - << ind << _class->name - << "* _this = reinterpret_cast<" << _class->name << "*> (ptr);\n" + << ind << ns_prefix << _class->name + << "* _this = reinterpret_cast<" << ns_prefix << _class->name + << "*> (ptr);\n" << ind << "delete _this;\n" << ind << "return 0;\n" << "}\n" diff --git a/tools/miniswig/create_wrapper.hpp b/tools/miniswig/create_wrapper.hpp index 1814cf4f9..ec9842940 100644 --- a/tools/miniswig/create_wrapper.hpp +++ b/tools/miniswig/create_wrapper.hpp @@ -21,6 +21,8 @@ public: void create_wrapper(Namespace* ns); private: + std::string ns_prefix; + void create_register_functions_code(Namespace* ns); void create_register_function_code(Function* function, Class* _class); void create_register_classes_code(Namespace* ns);