ae318be60d2f764021c7905ea51177322e141654
[supertux.git] / src / scripting / script_interpreter.h
1 #ifndef __SCRIPT_INTERPRETER_H__
2 #define __SCRIPT_INTERPRETER_H__
3
4 #include <squirrel.h>
5 #include <iostream>
6 #include "timer.h"
7 #include "game_object.h"
8 #include "scripting/sound.h"
9 #include "scripting/level.h"
10
11 class Sector;
12
13 class ScriptInterpreter : public GameObject
14 {
15 public:
16   ScriptInterpreter(const std::string& working_dir);
17   ~ScriptInterpreter();
18
19   void register_sector(Sector* sector);
20
21   void draw(DrawingContext& );
22   void update(float );
23
24   void run_script(std::istream& in, const std::string& sourcename = "",
25           bool remove_when_terminated = true);
26   
27   void expose_object(void* object, const std::string& name,
28                      const std::string& type);
29
30   void set_wakeup_time(float seconds);
31
32   /** helper function that parses a script, starts it and adds it to the sector
33    * specified
34    */
35   static void add_script_object(Sector* sector, const std::string& scriptname,
36       const std::string& script);
37
38   static ScriptInterpreter* current()
39   {
40     return _current;
41   }
42
43   const std::string& get_working_directory() const
44   {
45       return working_directory;
46   }
47
48 private:
49   HSQUIRRELVM v;
50   static ScriptInterpreter* _current;
51   Timer wakeup_timer;
52
53   /// this directory is used as base for all filenames used in scripts
54   std::string working_directory;
55   Scripting::Sound* sound;
56   Scripting::Level* level;
57 };
58
59 #endif
60