X-Git-Url: https://git.verplant.org/?a=blobdiff_plain;f=src%2Fscripting%2Fscript_interpreter.cpp;h=1047ed7f7761093678c96e6add3ceec8dc780729;hb=85a02e771388b133940b45e29768e697a29c1a36;hp=f3c8d0793b50e9f70058435a0140102024056e0f;hpb=ce0795230a1fbf9d4867f966aa6909d19975bfcf;p=supertux.git diff --git a/src/scripting/script_interpreter.cpp b/src/scripting/script_interpreter.cpp index f3c8d0793..1047ed7f7 100644 --- a/src/scripting/script_interpreter.cpp +++ b/src/scripting/script_interpreter.cpp @@ -23,6 +23,7 @@ #include "object/text_object.hpp" #include "object/scripted_object.hpp" #include "object/display_effect.hpp" +#include "object/player.hpp" #include "scripting/sound.hpp" #include "scripting/scripted_object.hpp" #include "scripting/display_effect.hpp" @@ -89,6 +90,7 @@ ScriptInterpreter::register_sector(Sector* sector) expose_object(scripted_object, scripted_object->get_name()); } + expose_object(static_cast (sector->player), "Tux"); TextObject* text_object = new TextObject(); sector->add_object(text_object); Scripting::Text* text = static_cast (text_object); @@ -121,8 +123,6 @@ void ScriptInterpreter::run_script(std::istream& in, const std::string& sourcename, bool remove_when_terminated) { - printf("Stackbefore:\n"); - print_squirrel_stack(v); if(sq_compile(v, squirrel_read_char, &in, sourcename.c_str(), true) < 0) throw Scripting::SquirrelError(v, "Couldn't parse script"); @@ -135,12 +135,9 @@ ScriptInterpreter::run_script(std::istream& in, const std::string& sourcename, if(remove_when_terminated) { remove_me(); } - printf("ended.\n"); // remove closure from stack sq_pop(v, 1); } - printf("After:\n"); - print_squirrel_stack(v); } void @@ -179,8 +176,18 @@ ScriptInterpreter::add_script_object(Sector* sector, const std::string& name, std::auto_ptr interpreter( new ScriptInterpreter(workdir)); interpreter->register_sector(sector); + + // load global default.nut file if it exists + //TODO: Load all .nut files from that directory + try { + std::string filename = "script/default.nut"; + IFileStream in(filename); + interpreter->run_script(in, filename, false); + } catch(std::exception& e) { + // nothing + } - // load default.nut file if it exists + // load world-specific default.nut file if it exists try { std::string filename = workdir + "/default.nut"; IFileStream in(filename);