fix namespace problems
authorMatthias Braun <matze@braunis.de>
Sat, 2 Jul 2005 11:57:24 +0000 (11:57 +0000)
committerMatthias Braun <matze@braunis.de>
Sat, 2 Jul 2005 11:57:24 +0000 (11:57 +0000)
SVN-Revision: 2682

src/scripting/wrapper.cpp
src/scripting/wrapper.hpp
tools/miniswig/create_wrapper.cpp
tools/miniswig/create_wrapper.hpp

index 50734e1..512c55c 100644 (file)
 namespace SquirrelWrapper
 {
 
-using namespace Scripting;
-
 static int DisplayEffect_release_hook(SQUserPointer ptr, int )
 {
-  DisplayEffect* _this = reinterpret_cast<DisplayEffect*> (ptr);
+  Scripting::DisplayEffect* _this = reinterpret_cast<Scripting::DisplayEffect*> (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<Camera*> (ptr);
+  Scripting::Camera* _this = reinterpret_cast<Scripting::Camera*> (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<Level*> (ptr);
+  Scripting::Level* _this = reinterpret_cast<Scripting::Level*> (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<ScriptedObject*> (ptr);
+  Scripting::ScriptedObject* _this = reinterpret_cast<Scripting::ScriptedObject*> (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<Sound*> (ptr);
+  Scripting::Sound* _this = reinterpret_cast<Scripting::Sound*> (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<Text*> (ptr);
+  Scripting::Text* _this = reinterpret_cast<Scripting::Text*> (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<Player*> (ptr);
+  Scripting::Player* _this = reinterpret_cast<Scripting::Player*> (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) {
index 77c6cc0..22b4626 100644 (file)
@@ -7,32 +7,20 @@
 #define __supertux_WRAPPER_H__
 
 #include <squirrel.h>
-
-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);
 
 }
 
index ed50a15..767e5c4 100644 (file)
@@ -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 <squirrel.h>\n"
+        << "#include \"wrapper.interface.hpp\"\n"
+        << "\n"
+        << "namespace SquirrelWrapper\n"
+        << "{\n"
         << "\n";
-    if(selected_namespace != "") {
-      hppout << "namespace " << selected_namespace << "\n"
-             << "{\n";
-    }
-    for(std::vector<AtomicType*>::iterator i = ns->types.begin();
-            i != ns->types.end(); ++i) {
-        AtomicType* type = *i;
-        Class* _class = dynamic_cast<Class*> (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<AtomicType*>::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"
index 1814cf4..ec98429 100644 (file)
@@ -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);