fixed scripting which I just broke
authorMatthias Braun <matze@braunis.de>
Fri, 1 Jul 2005 21:55:00 +0000 (21:55 +0000)
committerMatthias Braun <matze@braunis.de>
Fri, 1 Jul 2005 21:55:00 +0000 (21:55 +0000)
SVN-Revision: 2667

data/levels/test/script.stl
src/scripting/script_interpreter.cpp
src/scripting/wrapper_util.cpp
src/scripting/wrapper_util.hpp

index ceca520..147422d 100644 (file)
@@ -148,7 +148,7 @@ NOLOK.set_visible(true);
 tuxjumps <- 2;
 while(true) {
   wait(0.8);
-  Sound.play(\"jump\");
+  Sound.play(\"sounds/jump.ogg\");
   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(\"grow\");
+    Sound.play(\"sounds/grow.ogg\");
     PENNY.set_animation(\"stand\");
     PENNY.set_velocity(0, 900);
   }
index 31613df..3b1a1d4 100644 (file)
@@ -63,8 +63,7 @@ ScriptInterpreter::ScriptInterpreter(const std::string& new_working_directory)
   sq_setprintfunc(v, printfunc);
   
   // register supertux API
-  register_functions(v, supertux_global_functions);
-  register_classes(v, supertux_classes);
+  register_supertux_wrapper(v);
 
   // expose some "global" objects
   sound = new Scripting::Sound();
index b25930f..e70e392 100644 (file)
@@ -15,14 +15,21 @@ static void register_function(HSQUIRRELVM v, SQFUNCTION func, const char* name)
     }
 }
 
+static void _register_functions(HSQUIRRELVM v, WrappedFunction* functions)
+{
+    for(WrappedFunction* func = functions; func->name != 0; ++func) {
+        register_function(v, func->f, func->name);
+    }
+}
+
 static void register_class(HSQUIRRELVM v, WrappedClass* wclass)
 {
     sq_pushstring(v, wclass->name, -1);
     sq_newclass(v, false);
-    register_functions(v, wclass->functions);
-    register_constants(v, wclass->int_consts);
-    register_constants(v, wclass->float_consts);
-    register_constants(v, wclass->string_consts);
+    _register_functions(v, wclass->functions);
+    _register_constants(v, wclass->int_consts);
+    _register_constants(v, wclass->float_consts);
+    _register_constants(v, wclass->string_consts);
 
     if(sq_createslot(v, -3) < 0) {
         std::stringstream msg;
@@ -34,9 +41,7 @@ static void register_class(HSQUIRRELVM v, WrappedClass* wclass)
 void register_functions(HSQUIRRELVM v, WrappedFunction* functions)
 {
     sq_pushroottable(v);
-    for(WrappedFunction* func = functions; func->name != 0; ++func) {
-        register_function(v, func->f, func->name);
-    }
+    _register_functions(v, functions);
     sq_pop(v, 1);
 }
 
index 3f24de8..66ac995 100644 (file)
@@ -55,10 +55,9 @@ static inline void push_value(HSQUIRRELVM v, const char* str)
 }
 
 template<typename T>
-void register_constants(HSQUIRRELVM v, WrappedConstant<T>* constants)
+void _register_constants(HSQUIRRELVM v, WrappedConstant<T>* constants)
 {
-    sq_pushroottable(v);
-    for(WrappedConstant<T>* c = constants; *constants->name != 0; ++c) {
+    for(WrappedConstant<T>* c = constants; c->name != 0; ++c) {
         sq_pushstring(v, c->name, -1);
         push_value(v, c->value);
         if(sq_createslot(v, -3) < 0) {
@@ -67,6 +66,13 @@ void register_constants(HSQUIRRELVM v, WrappedConstant<T>* constants)
             throw SquirrelError(v, msg.str());
         }
     }
+}
+
+template<typename T>
+void register_constants(HSQUIRRELVM v, WrappedConstant<T>* constants)
+{
+    sq_pushroottable(v);
+    _register_constants(v, constants);
     sq_pop(v, 1);
 }