supertux
squirrel_environment.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 // 2018 Ingo Ruhnke <grumbel@gmail.com>
4 //
5 // This program is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18 #ifndef HEADER_SUPERTUX_SQUIRREL_SQUIRREL_ENVIRONMENT_HPP
19 #define HEADER_SUPERTUX_SQUIRREL_SQUIRREL_ENVIRONMENT_HPP
20 
21 #include <string>
22 #include <vector>
23 
24 #include <simplesquirrel/vm.hpp>
25 
26 #include "squirrel/exposable_class.hpp"
27 #include "squirrel/squirrel_scheduler.hpp"
28 #include "squirrel/squirrel_util.hpp"
29 #include "util/log.hpp"
30 
35 {
36 public:
37  SquirrelEnvironment(ssq::VM& vm, const std::string& name);
38  virtual ~SquirrelEnvironment();
39 
40 public:
41  ssq::VM& get_vm() const { return m_vm; }
42 
44  void expose_self();
45  void unexpose_self();
46 
48  void expose(ExposableClass& object, const std::string& name);
49  void unexpose(const std::string& name);
50 
53  void run_script(const std::string& script, const std::string& sourcename);
54 
59  void run_script(std::istream& in, const std::string& sourcename);
60 
61  void update(float dt_sec);
62  SQInteger wait_for_seconds(HSQUIRRELVM vm, float seconds);
63  SQInteger skippable_wait_for_seconds(HSQUIRRELVM vm, float seconds);
64 
65 private:
66  void garbage_collect();
67 
68 private:
69  ssq::VM& m_vm;
70  ssq::Table m_table;
71  std::string m_name;
72  std::vector<ssq::VM> m_scripts;
73  std::unique_ptr<SquirrelScheduler> m_scheduler;
74 
75 private:
77  SquirrelEnvironment& operator=(const SquirrelEnvironment&) = delete;
78 };
79 
80 #endif
81 
82 /* EOF */
void expose_self()
Expose this engine under &#39;name&#39;.
Definition: squirrel_environment.cpp:53
The SquirrelEnvironment contains the environment in which a script is executed, meaning a root table ...
Definition: squirrel_environment.hpp:34
void expose(ExposableClass &object, const std::string &name)
Expose and unexpose objects.
Definition: squirrel_environment.cpp:65
Represents a class, which can be exposed to scripting.
Definition: exposable_class.hpp:25
void run_script(const std::string &script, const std::string &sourcename)
Convenience function that takes an std::string instead of an std::istream&.
Definition: squirrel_environment.cpp:99