+
+void
+ScriptInterpreter::add_script_object(Sector* sector, const std::string& name,
+ const std::string& script)
+{
+ try {
+ std::string workdir = GameSession::current()->get_working_directory();
+ std::auto_ptr<ScriptInterpreter> 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 world-specific default.nut file if it exists
+ try {
+ std::string filename = workdir + "/default.nut";
+ IFileStream in(filename);
+ interpreter->run_script(in, filename, false);
+ } catch(std::exception& e) {
+ // nothing
+ }
+
+ std::istringstream in(script);
+ interpreter->run_script(in, name);
+ sector->add_object(interpreter.release());
+ } catch(std::exception& e) {
+ std::cerr << "Couldn't start '" << name << "' script: " << e.what() << "\n";
+ }
+}
+