Spiky, Snowball and Poison Ivy can move again
[supertux.git] / src / script_manager.cpp
index 2cd0842..14e6599 100644 (file)
@@ -1,7 +1,7 @@
-//  $Id: main.cpp 3275 2006-04-09 00:32:34Z sommer $
-// 
+//  $Id$
+//
 //  SuperTux
-//  Copyright (C) 2005 Matthias Braun <matze@braunis.de>
+//  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
 //
 //  This program is free software; you can redistribute it and/or
 //  modify it under the terms of the GNU General Public License
@@ -12,7 +12,7 @@
 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 //  GNU General Public License for more details.
-// 
+//
 //  You should have received a copy of the GNU General Public License
 //  along with this program; if not, write to the Free Software
 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
@@ -32,6 +32,7 @@
 
 #include "timer.hpp"
 #include "console.hpp"
+#include "log.hpp"
 #include "scripting/wrapper.hpp"
 #include "scripting/wrapper_util.hpp"
 #include "scripting/squirrel_error.hpp"
@@ -54,7 +55,7 @@ static void printfunc(HSQUIRRELVM, const char* str, ...)
 ScriptManager::ScriptManager()
   : parent(NULL)
 {
-  vm = sq_open(1024);
+  vm = sq_open(64);
   if(vm == 0)
     throw std::runtime_error("Couldn't initialize squirrel vm");
   sq_setforeignptr(vm, (SQUserPointer) this);
@@ -75,6 +76,15 @@ ScriptManager::ScriptManager()
   sq_setprintfunc(vm, printfunc);
   // register default error handlers
   sqstd_seterrorhandlers(vm); 
+
+  // try to load default script
+  try {
+    std::string filename = "scripts/default.nut";
+    IFileStream stream(filename);
+    Scripting::compile_and_run(vm, stream, filename);
+  } catch(std::exception& e) {
+    log_warning << "Couldn't load default.nut: " << e.what() << std::endl;
+  }
 }
 
 ScriptManager::ScriptManager(ScriptManager* parent)
@@ -102,7 +112,7 @@ ScriptManager::~ScriptManager()
 HSQUIRRELVM
 ScriptManager::create_thread(bool leave_thread_on_stack)
 {
-  HSQUIRRELVM new_vm = sq_newthread(vm, 1024);
+  HSQUIRRELVM new_vm = sq_newthread(vm, 64);
   if(new_vm == NULL)
     throw SquirrelError(vm, "Couldn't create new VM");
   sq_setforeignptr(new_vm, (SQUserPointer) this);