some cleanups and changes to miniswig and scripting code
authorMatthias Braun <matze@braunis.de>
Wed, 10 Aug 2005 22:23:50 +0000 (22:23 +0000)
committerMatthias Braun <matze@braunis.de>
Wed, 10 Aug 2005 22:23:50 +0000 (22:23 +0000)
SVN-Revision: 2752

15 files changed:
INSTALL
data/levels/test/script.stl
data/levels/test/simple.stl
src/badguy/kugelblitz.cpp
src/object/path.cpp
src/object/platform.cpp
src/scripting/script_interpreter.cpp
src/scripting/script_interpreter.hpp
src/scripting/squirrel_error.cpp [new file with mode: 0644]
src/scripting/squirrel_error.hpp [new file with mode: 0644]
src/scripting/wrapper.cpp
src/scripting/wrapper.hpp
src/scripting/wrapper_util.cpp
src/scripting/wrapper_util.hpp
tools/miniswig/create_wrapper.cpp

diff --git a/INSTALL b/INSTALL
index 422ebe1..a5859af 100644 (file)
--- a/INSTALL
+++ b/INSTALL
@@ -7,10 +7,6 @@ Last update: April 26, 2004
 REQUIREMENTS
 ------------
 
-  CONTROLS
-  --------
-    The game can be played with either a the keyboard or a joystick.
-
   SDL
   ---
     "SuperTux" was programed using the "Simple DirectMedia Layer"
index 147422d..6671923 100644 (file)
@@ -148,7 +148,7 @@ NOLOK.set_visible(true);
 tuxjumps <- 2;
 while(true) {
   wait(0.8);
-  Sound.play(\"sounds/jump.ogg\");
+  Sound.play(\"sounds/jump.wav\");
   if(tuxjumps >= 0) {
     TUX.set_velocity(50, 300);
   } else {
@@ -165,7 +165,7 @@ while(true) {
   } else if(PENNY.get_animation() == \"jump\") {
     PENNY.set_animation(\"dead\");
   } else {
-    Sound.play(\"sounds/grow.ogg\");
+    Sound.play(\"sounds/grow.wav\");
     PENNY.set_animation(\"stand\");
     PENNY.set_velocity(0, 900);
   }
index fe1d909..4a8a4fe 100644 (file)
     (gravity 10.000000)
     (background (image "arctis.jpg")
                 (speed 0.5))
-    (spawnpoint (name "main") (x 50) (y 200))
+    (spawnpoint (name "main") (x 150) (y 200))
     (rock (x 50) (y 50))
+    (rock (x 50) (y 100))
+    (rock (x 50) (y 150))
     (tilemap
       (layer  "background")
       (solid #f)
index 1f861fe..f8303e0 100644 (file)
@@ -61,7 +61,7 @@ Kugelblitz::activate()
 }
 
 HitResponse
-Kugelblitz::collision_solid(GameObject& other, const CollisionHit& chit)
+Kugelblitz::collision_solid(GameObject& , const CollisionHit& chit)
 {
   //TODO: Explode when Tux is hit
   return hit(chit);
index 941e9d0..ce49d2b 100644 (file)
@@ -94,7 +94,7 @@ Path::update(float elapsed_time)
 }
 
 void
-Path::draw(DrawingContext& context)
+Path::draw(DrawingContext& )
 {
    // TODO: Add a visible flag, draw the path if true
 }
index b3c0dc5..9bbc5fe 100644 (file)
@@ -78,7 +78,7 @@ Platform::collision(GameObject& other, const CollisionHit& hit)
 }
 
 void
-Platform::update(float elapsed_time)
+Platform::update(float )
 {
   set_pos(path->GetPosition() + path_offset);
 }
index 91e3263..f3c8d07 100644 (file)
@@ -26,6 +26,7 @@
 #include "scripting/sound.hpp"
 #include "scripting/scripted_object.hpp"
 #include "scripting/display_effect.hpp"
+#include "scripting/squirrel_error.hpp"
 
 static void printfunc(HSQUIRRELVM, const char* str, ...)
 {
@@ -49,21 +50,21 @@ ScriptInterpreter::ScriptInterpreter(const std::string& new_working_directory)
   // register squirrel libs
   sq_pushroottable(v);
   if(sqstd_register_bloblib(v) < 0)
-    throw SquirrelError(v, "Couldn't register blob lib");
+    throw Scripting::SquirrelError(v, "Couldn't register blob lib");
   if(sqstd_register_iolib(v) < 0)
-    throw SquirrelError(v, "Couldn't register io lib");
+    throw Scripting::SquirrelError(v, "Couldn't register io lib");
   if(sqstd_register_systemlib(v) < 0)
-    throw SquirrelError(v, "Couldn't register system lib");
+    throw Scripting::SquirrelError(v, "Couldn't register system lib");
   if(sqstd_register_mathlib(v) < 0)
-    throw SquirrelError(v, "Couldn't register math lib");
+    throw Scripting::SquirrelError(v, "Couldn't register math lib");
   if(sqstd_register_stringlib(v) < 0)
-    throw SquirrelError(v, "Couldn't register string lib");
+    throw Scripting::SquirrelError(v, "Couldn't register string lib");
 
   // register print function
   sq_setprintfunc(v, printfunc);
   
   // register supertux API
-  SquirrelWrapper::register_supertux_wrapper(v);
+  Scripting::register_supertux_wrapper(v);
 
   // expose some "global" objects
   sound = new Scripting::Sound();
@@ -123,12 +124,12 @@ ScriptInterpreter::run_script(std::istream& in, const std::string& sourcename,
   printf("Stackbefore:\n");
   print_squirrel_stack(v);
   if(sq_compile(v, squirrel_read_char, &in, sourcename.c_str(), true) < 0)
-    throw SquirrelError(v, "Couldn't parse script");
+    throw Scripting::SquirrelError(v, "Couldn't parse script");
  
   _current = this;
   sq_push(v, -2);
   if(sq_call(v, 1, false) < 0)
-    throw SquirrelError(v, "Couldn't start script");
+    throw Scripting::SquirrelError(v, "Couldn't start script");
   _current = 0;
   if(sq_getvmstate(v) != SQ_VMSTATE_SUSPENDED) {
     if(remove_when_terminated) {
@@ -156,7 +157,7 @@ ScriptInterpreter::update(float )
   
   _current = this;
   if(sq_wakeupvm(v, false, false) < 0)
-    throw SquirrelError(v, "Couldn't resume script");
+    throw Scripting::SquirrelError(v, "Couldn't resume script");
   _current = 0;
   if(sq_getvmstate(v) != SQ_VMSTATE_SUSPENDED) {
     printf("script ended...\n");
index c1b7af0..6e233e9 100644 (file)
@@ -11,6 +11,7 @@
 #include "scripting/wrapper_util.hpp"
 #include "scripting/sound.hpp"
 #include "scripting/level.hpp"
+#include "scripting/squirrel_error.hpp"
 
 class Sector;
 
@@ -35,14 +36,14 @@ public:
     sq_pushstring(v, name.c_str(), -1);
 
     sq_pushroottable(v);
-    SquirrelWrapper::create_squirrel_instance(v, object, free);
+    Scripting::create_squirrel_instance(v, object, free);
     sq_remove(v, -2);
                         
     // register instance in root table
     if(sq_createslot(v, -3) < 0) {
       std::ostringstream msg;
       msg << "Couldn't register object '" << name << "' in squirrel root table";
-      throw SquirrelError(v, msg.str());
+      throw Scripting::SquirrelError(v, msg.str());
     }
     
     sq_pop(v, 1);
diff --git a/src/scripting/squirrel_error.cpp b/src/scripting/squirrel_error.cpp
new file mode 100644 (file)
index 0000000..c6bcc73
--- /dev/null
@@ -0,0 +1,37 @@
+#include <config.h>
+
+#include "squirrel_error.hpp"
+#include <sstream>
+
+namespace Scripting
+{
+
+SquirrelError::SquirrelError(HSQUIRRELVM v, const std::string& message) throw()
+{
+  std::ostringstream msg;
+  msg << "Squirrel error: " << message << " (";
+  const char* lasterr;
+  sq_getlasterror(v);
+  if(sq_gettype(v, -1) != OT_STRING)
+  {
+    lasterr = "no error info";
+  }
+  else
+  {
+    sq_getstring(v, -1, &lasterr);
+  }
+  sq_pop(v, 1);
+  msg << lasterr << ")";
+  this->message = msg.str();
+}
+
+SquirrelError::~SquirrelError() throw()
+{}
+
+const char*
+SquirrelError::what() const throw()
+{
+  return message.c_str();
+}
+
+}
diff --git a/src/scripting/squirrel_error.hpp b/src/scripting/squirrel_error.hpp
new file mode 100644 (file)
index 0000000..6bc91b0
--- /dev/null
@@ -0,0 +1,28 @@
+#ifndef __SQUIRREL_ERROR_HPP__
+#define __SQUIRREL_ERROR_HPP__
+
+#include <squirrel.h>
+#include <stdexcept>
+
+namespace Scripting
+{
+
+/** Exception class for squirrel errors, it takes a squirrelvm and uses
+ * sq_geterror() to retrieve additional information about the last error that
+ * occured and creates a readable message from that.
+ */
+class SquirrelError : public std::exception
+{
+public:
+  SquirrelError(HSQUIRRELVM v, const std::string& message) throw();
+  virtual ~SquirrelError() throw();
+
+  const char* what() const throw();
+private:
+  std::string message;
+};
+
+}
+
+#endif
+
index 512c55c..0a7813d 100644 (file)
@@ -8,11 +8,14 @@
 #include <new>
 #include <assert.h>
 #include <string>
+#include <sstream>
 #include <squirrel.h>
-#include "wrapper_util.hpp"
+#include "squirrel_error.hpp"
 #include "wrapper.interface.hpp"
 
-namespace SquirrelWrapper
+namespace Scripting
+{
+namespace Wrapper
 {
 
 static int DisplayEffect_release_hook(SQUserPointer ptr, int )
@@ -22,26 +25,6 @@ static int DisplayEffect_release_hook(SQUserPointer ptr, int )
   return 0;
 }
 
-void create_squirrel_instance(HSQUIRRELVM v, Scripting::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;
@@ -96,26 +79,6 @@ static int Camera_release_hook(SQUserPointer ptr, int )
   return 0;
 }
 
-void create_squirrel_instance(HSQUIRRELVM v, Scripting::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;
@@ -165,26 +128,6 @@ static int Level_release_hook(SQUserPointer ptr, int )
   return 0;
 }
 
-void create_squirrel_instance(HSQUIRRELVM v, Scripting::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;
@@ -226,26 +169,6 @@ static int ScriptedObject_release_hook(SQUserPointer ptr, int )
   return 0;
 }
 
-void create_squirrel_instance(HSQUIRRELVM v, Scripting::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;
@@ -396,26 +319,6 @@ static int Sound_release_hook(SQUserPointer ptr, int )
   return 0;
 }
 
-void create_squirrel_instance(HSQUIRRELVM v, Scripting::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;
@@ -447,26 +350,6 @@ static int Text_release_hook(SQUserPointer ptr, int )
   return 0;
 }
 
-void create_squirrel_instance(HSQUIRRELVM v, Scripting::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;
@@ -534,26 +417,6 @@ static int Player_release_hook(SQUserPointer ptr, int )
   return 0;
 }
 
-void create_squirrel_instance(HSQUIRRELVM v, Scripting::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;
@@ -640,12 +503,198 @@ static int import_wrapper(HSQUIRRELVM v)
   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, "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());
@@ -653,7 +702,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());
@@ -661,7 +710,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());
@@ -669,7 +718,7 @@ 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());
@@ -684,7 +733,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());
@@ -692,7 +741,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());
@@ -700,7 +749,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());
@@ -708,13 +757,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());
@@ -729,7 +778,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());
@@ -737,7 +786,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());
@@ -745,13 +794,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());
@@ -766,7 +815,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());
@@ -774,7 +823,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());
@@ -782,13 +831,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());
@@ -803,7 +852,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());
@@ -811,7 +860,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());
@@ -819,7 +868,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());
@@ -827,7 +876,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());
@@ -835,7 +884,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());
@@ -843,7 +892,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());
@@ -851,7 +900,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());
@@ -859,7 +908,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());
@@ -867,7 +916,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());
@@ -875,7 +924,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());
@@ -883,7 +932,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());
@@ -891,13 +940,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());
@@ -912,7 +961,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());
@@ -920,13 +969,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());
@@ -941,7 +990,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());
@@ -949,7 +998,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());
@@ -957,7 +1006,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());
@@ -965,7 +1014,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());
@@ -973,13 +1022,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,7 +1043,7 @@ void register_supertux_wrapper(HSQUIRRELVM v)
   }
   sq_pushstring(v, "set_bonus", -1);
   sq_newclosure(v, &Player_set_bonus_wrapper, 0);
-  if(sq_createslot(v, -3) < 0) {
+  if(SQ_FAILED(sq_createslot(v, -3))) {
     std::ostringstream msg;
     msg << "Couldn't register function'set_bonus'";
     throw SquirrelError(v, msg.str());
@@ -1002,7 +1051,7 @@ void register_supertux_wrapper(HSQUIRRELVM v)
 
   sq_pushstring(v, "make_invincible", -1);
   sq_newclosure(v, &Player_make_invincible_wrapper, 0);
-  if(sq_createslot(v, -3) < 0) {
+  if(SQ_FAILED(sq_createslot(v, -3))) {
     std::ostringstream msg;
     msg << "Couldn't register function'make_invincible'";
     throw SquirrelError(v, msg.str());
@@ -1010,7 +1059,7 @@ void register_supertux_wrapper(HSQUIRRELVM v)
 
   sq_pushstring(v, "add_life", -1);
   sq_newclosure(v, &Player_add_life_wrapper, 0);
-  if(sq_createslot(v, -3) < 0) {
+  if(SQ_FAILED(sq_createslot(v, -3))) {
     std::ostringstream msg;
     msg << "Couldn't register function'add_life'";
     throw SquirrelError(v, msg.str());
@@ -1018,13 +1067,13 @@ void register_supertux_wrapper(HSQUIRRELVM v)
 
   sq_pushstring(v, "add_coins", -1);
   sq_newclosure(v, &Player_add_coins_wrapper, 0);
-  if(sq_createslot(v, -3) < 0) {
+  if(SQ_FAILED(sq_createslot(v, -3))) {
     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());
@@ -1033,5 +1082,5 @@ void register_supertux_wrapper(HSQUIRRELVM v)
   sq_pop(v, 1);
 }
 
-}
+} // end of namespace Scripting
 
index 22b4626..7f69ea8 100644 (file)
@@ -9,7 +9,7 @@
 #include <squirrel.h>
 #include "wrapper.interface.hpp"
 
-namespace SquirrelWrapper
+namespace Scripting
 {
 
 void register_supertux_wrapper(HSQUIRRELVM v);
index 8b67d34..605ff1b 100644 (file)
@@ -4,6 +4,114 @@
 #include <sstream>
 #include "wrapper_util.hpp"
 
+std::string squirrel2string(HSQUIRRELVM v, int i)
+{
+  std::ostringstream os;
+  switch(sq_gettype(v, i))
+    {
+    case OT_NULL:
+      os << "<null>";        
+      break;
+    case OT_BOOL: {
+      SQBool p;
+      sq_getbool(v, i, &p);
+      if (p) 
+        os << "true";
+      else
+        os << "false";
+      break;
+    }
+    case OT_INTEGER: {
+      int val;
+      sq_getinteger(v, i, &val);
+      os << val;
+      break;
+    }
+    case OT_FLOAT: {
+      float val;
+      sq_getfloat(v, i, &val);
+      os << val;
+      break;
+    }
+    case OT_STRING: {
+      const char* val;
+      sq_getstring(v, i, &val);
+      os << "\"" << val << "\"";
+      break;    
+    }
+    case OT_TABLE: {
+      bool first = true;
+      os << "{";
+      sq_pushnull(v);  //null iterator
+      while(SQ_SUCCEEDED(sq_next(v,i-1)))
+        {
+          if (!first) {
+            os << ", ";
+          }
+          first = false;
+
+          //here -1 is the value and -2 is the key
+          os << squirrel2string(v, -2) << " => " 
+             << squirrel2string(v, -1);
+                              
+          sq_pop(v,2); //pops key and val before the nex iteration
+        }
+      sq_pop(v, 1);
+      os << "}";
+      break;
+    }
+    case OT_ARRAY: {
+      bool first = true;
+      os << "[";
+      sq_pushnull(v);  //null iterator
+      while(SQ_SUCCEEDED(sq_next(v,i-1)))
+        {
+          if (!first) {
+            os << ", ";
+          }
+          first = false;
+
+          //here -1 is the value and -2 is the key
+          // we ignore the key, since that is just the index in an array
+          os << squirrel2string(v, -1);
+                              
+          sq_pop(v,2); //pops key and val before the nex iteration
+        }
+      sq_pop(v, 1);
+      os << "]";
+      break;
+    }
+    case OT_USERDATA:
+      os << "<userdata>";
+      break;
+    case OT_CLOSURE:        
+      os << "<closure (function)>";
+      break;
+    case OT_NATIVECLOSURE:
+      os << "<native closure (C function)>";
+      break;
+    case OT_GENERATOR:
+      os << "<generator>";
+      break;
+    case OT_USERPOINTER:
+      os << "userpointer";
+      break;
+    case OT_THREAD:
+      os << "<thread>";
+      break;
+    case OT_CLASS:
+      os << "<class>";
+      break;
+    case OT_INSTANCE:
+      os << "<instance>";
+      break;
+    default:
+      os << "<unknown>";
+      break;
+    }
+  return os.str();
+}
+
 void print_squirrel_stack(HSQUIRRELVM v)
 {
     printf("--------------------------------------------------------------\n");
@@ -72,29 +180,4 @@ void print_squirrel_stack(HSQUIRRELVM v)
     printf("--------------------------------------------------------------\n");
 }
 
-//----------------------------------------------------------------------------
-
-SquirrelError::SquirrelError(HSQUIRRELVM v, const std::string& message) throw()
-{
-  std::ostringstream msg;
-  msg << "SQuirrel error: " << message << " (";
-  const char* lasterr;
-  sq_getlasterror(v);
-  if(sq_gettype(v, -1) != OT_STRING) {
-    lasterr = "no error info";
-  } else {
-    sq_getstring(v, -1, &lasterr);
-  }
-  sq_pop(v, 1);
-  msg << lasterr << ")";
-  this->message = msg.str();
-}
-
-SquirrelError::~SquirrelError() throw()
-{}
-
-const char*
-SquirrelError::what() const throw()
-{
-  return message.c_str();
-}
+/* EOF */
index 54ca2e9..a6cfa23 100644 (file)
@@ -2,21 +2,10 @@
 #define __WRAPPERUTIL_HPP__
 
 #include <squirrel.h>
-#include <exception>
 #include <sstream>
 #include <string>
 
-class SquirrelError : public std::exception
-{
-public:
-  SquirrelError(HSQUIRRELVM v, const std::string& message) throw();
-  virtual ~SquirrelError() throw();
-
-  const char* what() const throw();
-private:
-  std::string message;
-};
-
+std::string squirrel2string(HSQUIRRELVM v, int i);
 void print_squirrel_stack(HSQUIRRELVM v);
 
 #endif
index 7e44cd6..c279fa4 100644 (file)
@@ -28,7 +28,7 @@ WrapperCreator::create_wrapper(Namespace* ns)
         << "#include <squirrel.h>\n"
         << "#include \"wrapper.interface.hpp\"\n"
         << "\n"
-        << "namespace SquirrelWrapper\n"
+        << "namespace Scripting\n"
         << "{\n"
         << "\n";
 
@@ -63,11 +63,14 @@ WrapperCreator::create_wrapper(Namespace* ns)
         << "#include <new>\n"
         << "#include <assert.h>\n"
         << "#include <string>\n"
+        << "#include <sstream>\n"
         << "#include <squirrel.h>\n"
-        << "#include \"wrapper_util.hpp\"\n"
+        << "#include \"squirrel_error.hpp\"\n"
         << "#include \"wrapper.interface.hpp\"\n"
         << "\n"
-        << "namespace SquirrelWrapper\n"
+        << "namespace Scripting\n"
+        << "{\n"
+        << "namespace Wrapper\n"
         << "{\n"
         << "\n";
 
@@ -83,8 +86,21 @@ WrapperCreator::create_wrapper(Namespace* ns)
         create_function_wrapper(0, *i);
     }
 
+    out << "} // end of namespace Wrapper\n";
+    out << "\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)
+            create_squirrel_instance(_class);
+    }
+    
     out << "void register_" << modulename << "_wrapper(HSQUIRRELVM v)\n"
         << "{\n"
+        << ind << "using namespace Wrapper;\n"
+        << "\n"
         << ind << "sq_pushroottable(v);\n";
 
     create_register_constants_code(ns);
@@ -94,7 +110,7 @@ WrapperCreator::create_wrapper(Namespace* ns)
     out << ind << "sq_pop(v, 1);\n"
         << "}\n"
         << "\n"
-        << "}\n"
+        << "} // end of namespace Scripting\n"
         << "\n";
 }
 
@@ -225,7 +241,7 @@ void
 WrapperCreator::create_register_slot_code(const std::string& what,
                                           const std::string& name)
 {
-    out << ind << "if(sq_createslot(v, -3) < 0) {\n";
+    out << ind << "if(SQ_FAILED(sq_createslot(v, -3))) {\n";
     out << ind << ind << "std::ostringstream msg;\n";
     out << ind << ind << "msg << \"Couldn't register " << what << "'"
         << name << "'\";\n";
@@ -409,7 +425,6 @@ void
 WrapperCreator::create_class_wrapper(Class* _class)
 {
     create_class_release_hook(_class);
-    create_squirrel_instance(_class);
     for(std::vector<ClassMember*>::iterator i = _class->members.begin();
             i != _class->members.end(); ++i) {
         ClassMember* member = *i;
@@ -432,27 +447,32 @@ WrapperCreator::create_squirrel_instance(Class* _class)
         << ns_prefix << _class->name 
         << "* object, bool setup_releasehook)\n"
         << "{\n"
+        << ind << "using namespace Wrapper;\n"
+        << "\n"
+        << ind << "sq_pushroottable(v);\n"
         << ind << "sq_pushstring(v, \"" << _class->name << "\", -1);\n"
-        << ind << "if(sq_get(v, -2) < 0) {\n"
+        << ind << "if(SQ_FAILED(sq_get(v, -2))) {\n"
         << ind << ind << "std::ostringstream msg;\n"
         << ind << ind << "msg << \"Couldn't resolved squirrel type '"
         << _class->name << "'\";\n"
         << ind << ind << "throw SquirrelError(v, msg.str());\n"
         << ind << "}\n"
         << "\n"
-        << ind << "if(sq_createinstance(v, -1) < 0 || "
-        << "sq_setinstanceup(v, -1, object) < 0) {\n"
+        << ind << "if(SQ_FAILED(sq_createinstance(v, -1)) || "
+        << "SQ_FAILED(sq_setinstanceup(v, -1, object))) {\n"
         << ind << ind << "std::ostringstream msg;\n"
         << ind << ind << "msg << \"Couldn't setup squirrel instance for "
         << "object of type '" << _class->name << "'\";\n"
         << ind << ind << "throw SquirrelError(v, msg.str());\n"
         << ind << "}\n"
-        << ind << "sq_remove(v, -2);\n"
+        << ind << "sq_remove(v, -2); // remove object name\n"
         << "\n"
         << ind << "if(setup_releasehook) {\n"
         << ind << ind << "sq_setreleasehook(v, -1, "
         << _class->name << "_release_hook);\n"
         << ind << "}\n"
+        << "\n"
+        << ind << "sq_remove(v, -2); // remove root table\n"
         << "}\n"
         << "\n";
 }