From a37489a6257604f2262fef178def3555e4a26ca6 Mon Sep 17 00:00:00 2001 From: Matthias Braun Date: Fri, 1 Jul 2005 21:55:00 +0000 Subject: [PATCH] fixed scripting which I just broke SVN-Revision: 2667 --- data/levels/test/script.stl | 4 ++-- src/scripting/script_interpreter.cpp | 3 +-- src/scripting/wrapper_util.cpp | 19 ++++++++++++------- src/scripting/wrapper_util.hpp | 12 +++++++++--- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/data/levels/test/script.stl b/data/levels/test/script.stl index ceca520f4..147422dc7 100644 --- a/data/levels/test/script.stl +++ b/data/levels/test/script.stl @@ -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); } diff --git a/src/scripting/script_interpreter.cpp b/src/scripting/script_interpreter.cpp index 31613df0a..3b1a1d4b3 100644 --- a/src/scripting/script_interpreter.cpp +++ b/src/scripting/script_interpreter.cpp @@ -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(); diff --git a/src/scripting/wrapper_util.cpp b/src/scripting/wrapper_util.cpp index b25930f7b..e70e392df 100644 --- a/src/scripting/wrapper_util.cpp +++ b/src/scripting/wrapper_util.cpp @@ -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); } diff --git a/src/scripting/wrapper_util.hpp b/src/scripting/wrapper_util.hpp index 3f24de8a1..66ac99542 100644 --- a/src/scripting/wrapper_util.hpp +++ b/src/scripting/wrapper_util.hpp @@ -55,10 +55,9 @@ static inline void push_value(HSQUIRRELVM v, const char* str) } template -void register_constants(HSQUIRRELVM v, WrappedConstant* constants) +void _register_constants(HSQUIRRELVM v, WrappedConstant* constants) { - sq_pushroottable(v); - for(WrappedConstant* c = constants; *constants->name != 0; ++c) { + for(WrappedConstant* 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* constants) throw SquirrelError(v, msg.str()); } } +} + +template +void register_constants(HSQUIRRELVM v, WrappedConstant* constants) +{ + sq_pushroottable(v); + _register_constants(v, constants); sq_pop(v, 1); } -- 2.11.0