ice yeti animation updates
[supertux.git] / src / scripting / script_interpreter.hpp
index 3788c30..6e233e9 100644 (file)
@@ -3,10 +3,15 @@
 
 #include <squirrel.h>
 #include <iostream>
+#include <sstream>
+#include <string>
 #include "timer.hpp"
 #include "game_object.hpp"
+#include "scripting/wrapper.hpp"
+#include "scripting/wrapper_util.hpp"
 #include "scripting/sound.hpp"
 #include "scripting/level.hpp"
+#include "scripting/squirrel_error.hpp"
 
 class Sector;
 
@@ -23,9 +28,26 @@ public:
 
   void run_script(std::istream& in, const std::string& sourcename = "",
           bool remove_when_terminated = true);
-  
-  void expose_object(void* object, const std::string& name,
-                     const std::string& type);
+
+  template<typename T>
+  void expose_object(T* object, const std::string& name, bool free = false)
+  {
+    sq_pushroottable(v);
+    sq_pushstring(v, name.c_str(), -1);
+
+    sq_pushroottable(v);
+    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 Scripting::SquirrelError(v, msg.str());
+    }
+    
+    sq_pop(v, 1);
+  }
 
   void set_wakeup_time(float seconds);