-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathlua_script.h
More file actions
191 lines (166 loc) · 4.74 KB
/
Copy pathlua_script.h
File metadata and controls
191 lines (166 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
////////////////////////////////////////////////////////////////////////////////
// Distributed under the Boost Software License, Version 1.0. //
// (See accompanying file LICENSE or copy at //
// https://www.boost.org/LICENSE_1_0.txt) //
////////////////////////////////////////////////////////////////////////////////
#pragma once
#include <cstdint>
#include <memory>
#include <string>
#include "core/quaternion.h"
#include "core/resource_manager.h"
#include "core/vector3.h"
#include "scripting/script.h"
namespace iris
{
/**
* Implementation of Script for Lua.
*
* Note that this interface is deliberately verbose. It's effectively a state machine where you:
* - set the function you want to call
* - set the arguments (on order)
* - call execute (with the number of arguments and results)
* - get all the results (in reverse order)
*
* Whilst flexible this is error prone, the preferred way to execute a script is to use the ScriptRunner class, which
* handles all the complexity and provides a much simpler interface.
*/
class LuaScript : public Script
{
public:
/**
* Construct a new LuaScript.
*
* @param source
* The source for the lua script.
*/
explicit LuaScript(const std::string &source);
/**
* Construct a new LuaScript.
*
* @param file
* File to load script from (via ResourceLoader).
*
* @param
* Tag to indicate script should be loaded from a file.
*/
LuaScript(ResourceManager &resource_manager, const std::string &file);
~LuaScript() override;
LuaScript(const LuaScript &) = delete;
LuaScript &operator=(const LuaScript &) = delete;
/**
* Set the name of the function in the script to call.
*
* @param function
* Name of function to call.
*/
void set_function(const std::string &function) override;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
void set_argument(bool argument) override;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
void set_argument(std::int32_t argument) override;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
void set_argument(float argument) override;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
void set_argument(const char *argument) override;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
void set_argument(const std::string &argument) override;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
void set_argument(const Vector3 &argument) override;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
void set_argument(const Quaternion &argument) override;
/**
* Execute the set function.
*
* Note it is undefined to call this method without first correctly setting the function name and arguments.
*
* @param num_args
* Number of arguments to pass to the function.
*
* @param num_results
* Number if results expected from the script.
*/
void execute(std::uint32_t num_args, std::uint32_t num_results) override;
/**
* Get a result from the executed function.
*
* @param result
* Out parameter for result.
*/
void get_result(bool &result) override;
/**
* Get a result from the executed function.
*
* @param result
* Out parameter for result.
*/
void get_result(std::int32_t &result) override;
/**
* Get a result from the executed function.
*
* @param result
* Out parameter for result.
*/
void get_result(float &result) override;
/**
* Get a result from the executed function.
*
* @param result
* Out parameter for result.
*/
void get_result(std::string &result) override;
/**
* Get a result from the executed function.
*
* @param result
* Out parameter for result.
*/
void get_result(Vector3 &result) override;
/**
* Get a result from the executed function.
*
* @param result
* Out parameter for result.
*/
void get_result(Quaternion &result) override;
private:
/** Pointer to implementation. */
struct implementation;
std::unique_ptr<implementation> impl_;
};
}