-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathscript.h
More file actions
161 lines (140 loc) · 4.09 KB
/
Copy pathscript.h
File metadata and controls
161 lines (140 loc) · 4.09 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
////////////////////////////////////////////////////////////////////////////////
// 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 <string>
#include "core/quaternion.h"
#include "core/vector3.h"
namespace iris
{
/**
* Interface for script, an object which can execute code from another language embedded in the engine.
*
* 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 Script
{
public:
virtual ~Script() = default;
/**
* Set the name of the function in the script to call.
*
* @param function
* Name of function to call.
*/
virtual void set_function(const std::string &function) = 0;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
virtual void set_argument(bool argument) = 0;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
virtual void set_argument(std::int32_t argument) = 0;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
virtual void set_argument(float argument) = 0;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
virtual void set_argument(const char *argument) = 0;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
virtual void set_argument(const std::string &argument) = 0;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
virtual void set_argument(const Vector3 &argument) = 0;
/**
* Set an argument for the executing function.
*
* @param argument
* Argument for function.
*/
virtual void set_argument(const Quaternion &argument) = 0;
/**
* 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.
*/
virtual void execute(std::uint32_t num_args, std::uint32_t num_results) = 0;
/**
* Get a result from the executed function.
*
* @param result
* Out parameter for result.
*/
virtual void get_result(bool &result) = 0;
/**
* Get a result from the executed function.
*
* @param result
* Out parameter for result.
*/
virtual void get_result(std::int32_t &result) = 0;
/**
* Get a result from the executed function.
*
* @param result
* Out parameter for result.
*/
virtual void get_result(float &result) = 0;
/**
* Get a result from the executed function.
*
* @param result
* Out parameter for result.
*/
virtual void get_result(std::string &result) = 0;
/**
* Get a result from the executed function.
*
* @param result
* Out parameter for result.
*/
virtual void get_result(Vector3 &result) = 0;
/**
* Get a result from the executed function.
*
* @param result
* Out parameter for result.
*/
virtual void get_result(Quaternion &result) = 0;
};
}