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_VM_HPP |
19 | #define |
20 | |
21 | #include <string> |
22 | #include <vector> |
23 | |
24 | #include <squirrel.h> |
25 | |
26 | /** Basic wrapper around HSQUIRRELVM with some utility functions, not |
27 | to be confused with SquirrelVirtualMachine. The classes might be |
28 | merged in the future. */ |
29 | class SquirrelVM |
30 | { |
31 | public: |
32 | SquirrelVM(); |
33 | ~SquirrelVM(); |
34 | |
35 | HSQUIRRELVM get_vm() const { return m_vm; } |
36 | |
37 | void begin_table(const char* name); |
38 | void end_table(const char* name); |
39 | |
40 | /** Creates an empty table with given name |
41 | @param vm VM to create table on |
42 | @param name Name of the table to create */ |
43 | void create_empty_table(const char* name); |
44 | |
45 | bool has_property(const char* name); |
46 | |
47 | void store_bool(const char* name, bool val); |
48 | void store_int(const char* name, int val); |
49 | void store_float(const char* name, float val); |
50 | void store_string(const char* name, const std::string& val); |
51 | void store_object(const char* name, const HSQOBJECT& val); |
52 | |
53 | bool get_bool(const char* name, bool& val); |
54 | bool get_int(const char* name, int& val); |
55 | bool get_float(const char* name, float& val); |
56 | bool get_string(const char* name, std::string& val); |
57 | |
58 | bool read_bool(const char* name); |
59 | int read_int(const char* name); |
60 | float read_float(const char* name); |
61 | std::string read_string(const char* name); |
62 | |
63 | void get_table_entry(const std::string& name); |
64 | void get_or_create_table_entry(const std::string& name); |
65 | void delete_table_entry(const char* name); |
66 | void rename_table_entry(const char* oldname, const char* newname); |
67 | std::vector<std::string> get_table_keys(); |
68 | |
69 | HSQOBJECT create_thread(); |
70 | |
71 | private: |
72 | HSQUIRRELVM m_vm; |
73 | |
74 | private: |
75 | SquirrelVM(const SquirrelVM&) = delete; |
76 | SquirrelVM& operator=(const SquirrelVM&) = delete; |
77 | }; |
78 | |
79 | #endif |
80 | |
81 | /* EOF */ |
82 | |