update for backscrolling, badguy behaviour
[supertux.git] / src / scripting / wrapper.cpp
index cb77fab..89746de 100644 (file)
@@ -424,6 +424,29 @@ static int Level_flip_vertically_wrapper(HSQUIRRELVM vm)
   
 }
 
+static int Level_toggle_pause_wrapper(HSQUIRRELVM vm)
+{
+  Scripting::Level* _this;
+  if(SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*> (&_this), 0))) {
+    sq_throwerror(vm, _SC("'toggle_pause' called without instance"));
+    return SQ_ERROR;
+  }
+  
+  try {
+    _this->toggle_pause();
+  
+    return 0;
+  
+  } catch(std::exception& e) {
+    sq_throwerror(vm, e.what());
+    return SQ_ERROR;
+  } catch(...) {
+    sq_throwerror(vm, _SC("Unexpected exception while executing function 'toggle_pause'"));
+    return SQ_ERROR;
+  }
+  
+}
+
 static int ScriptedObject_release_hook(SQUserPointer ptr, int )
 {
   Scripting::ScriptedObject* _this = reinterpret_cast<Scripting::ScriptedObject*> (ptr);
@@ -1141,6 +1164,34 @@ static int Player_get_visible_wrapper(HSQUIRRELVM vm)
   
 }
 
+static int Player_kill_wrapper(HSQUIRRELVM vm)
+{
+  Scripting::Player* _this;
+  if(SQ_FAILED(sq_getinstanceup(vm, 1, reinterpret_cast<SQUserPointer*> (&_this), 0))) {
+    sq_throwerror(vm, _SC("'kill' called without instance"));
+    return SQ_ERROR;
+  }
+  SQBool arg0;
+  if(SQ_FAILED(sq_getbool(vm, 2, &arg0))) {
+    sq_throwerror(vm, _SC("Argument 1 not a bool"));
+    return SQ_ERROR;
+  }
+  
+  try {
+    _this->kill(arg0);
+  
+    return 0;
+  
+  } catch(std::exception& e) {
+    sq_throwerror(vm, e.what());
+    return SQ_ERROR;
+  } catch(...) {
+    sq_throwerror(vm, _SC("Unexpected exception while executing function 'kill'"));
+    return SQ_ERROR;
+  }
+  
+}
+
 static int FloatingImage_release_hook(SQUserPointer ptr, int )
 {
   Scripting::FloatingImage* _this = reinterpret_cast<Scripting::FloatingImage*> (ptr);
@@ -1920,44 +1971,6 @@ static int mortal_wrapper(HSQUIRRELVM vm)
   
 }
 
-static int shrink_wrapper(HSQUIRRELVM vm)
-{
-  (void) vm;
-  
-  try {
-    Scripting::shrink();
-  
-    return 0;
-  
-  } catch(std::exception& e) {
-    sq_throwerror(vm, e.what());
-    return SQ_ERROR;
-  } catch(...) {
-    sq_throwerror(vm, _SC("Unexpected exception while executing function 'shrink'"));
-    return SQ_ERROR;
-  }
-  
-}
-
-static int kill_wrapper(HSQUIRRELVM vm)
-{
-  (void) vm;
-  
-  try {
-    Scripting::kill();
-  
-    return 0;
-  
-  } catch(std::exception& e) {
-    sq_throwerror(vm, e.what());
-    return SQ_ERROR;
-  } catch(...) {
-    sq_throwerror(vm, _SC("Unexpected exception while executing function 'kill'"));
-    return SQ_ERROR;
-  }
-  
-}
-
 static int restart_wrapper(HSQUIRRELVM vm)
 {
   (void) vm;
@@ -2053,6 +2066,25 @@ static int quit_wrapper(HSQUIRRELVM vm)
   
 }
 
+static int rand_wrapper(HSQUIRRELVM vm)
+{
+  
+  try {
+    int return_value = Scripting::rand();
+  
+    sq_pushinteger(vm, return_value);
+    return 1;
+  
+  } catch(std::exception& e) {
+    sq_throwerror(vm, e.what());
+    return SQ_ERROR;
+  } catch(...) {
+    sq_throwerror(vm, _SC("Unexpected exception while executing function 'rand'"));
+    return SQ_ERROR;
+  }
+  
+}
+
 } // end of namespace Wrapper
 
 void create_squirrel_instance(HSQUIRRELVM v, Scripting::DisplayEffect* object, bool setup_releasehook)
@@ -2427,18 +2459,6 @@ void register_supertux_wrapper(HSQUIRRELVM v)
     throw SquirrelError(v, "Couldn't register function 'mortal'");
   }
 
-  sq_pushstring(v, "shrink", -1);
-  sq_newclosure(v, &shrink_wrapper, 0);
-  if(SQ_FAILED(sq_createslot(v, -3))) {
-    throw SquirrelError(v, "Couldn't register function 'shrink'");
-  }
-
-  sq_pushstring(v, "kill", -1);
-  sq_newclosure(v, &kill_wrapper, 0);
-  if(SQ_FAILED(sq_createslot(v, -3))) {
-    throw SquirrelError(v, "Couldn't register function 'kill'");
-  }
-
   sq_pushstring(v, "restart", -1);
   sq_newclosure(v, &restart_wrapper, 0);
   if(SQ_FAILED(sq_createslot(v, -3))) {
@@ -2469,6 +2489,12 @@ void register_supertux_wrapper(HSQUIRRELVM v)
     throw SquirrelError(v, "Couldn't register function 'quit'");
   }
 
+  sq_pushstring(v, "rand", -1);
+  sq_newclosure(v, &rand_wrapper, 0);
+  if(SQ_FAILED(sq_createslot(v, -3))) {
+    throw SquirrelError(v, "Couldn't register function 'rand'");
+  }
+
   // Register class DisplayEffect
   sq_pushstring(v, "DisplayEffect", -1);
   if(sq_newclass(v, SQFalse) < 0) {
@@ -2576,6 +2602,12 @@ void register_supertux_wrapper(HSQUIRRELVM v)
     throw SquirrelError(v, "Couldn't register function 'flip_vertically'");
   }
 
+  sq_pushstring(v, "toggle_pause", -1);
+  sq_newclosure(v, &Level_toggle_pause_wrapper, 0);
+  if(SQ_FAILED(sq_createslot(v, -3))) {
+    throw SquirrelError(v, "Couldn't register function 'toggle_pause'");
+  }
+
   if(SQ_FAILED(sq_createslot(v, -3))) {
     throw SquirrelError(v, "Couldn't register class 'Level'");
   }
@@ -2765,6 +2797,12 @@ void register_supertux_wrapper(HSQUIRRELVM v)
     throw SquirrelError(v, "Couldn't register function 'get_visible'");
   }
 
+  sq_pushstring(v, "kill", -1);
+  sq_newclosure(v, &Player_kill_wrapper, 0);
+  if(SQ_FAILED(sq_createslot(v, -3))) {
+    throw SquirrelError(v, "Couldn't register function 'kill'");
+  }
+
   if(SQ_FAILED(sq_createslot(v, -3))) {
     throw SquirrelError(v, "Couldn't register class 'Player'");
   }