Leviathan  0.8.0.0
Leviathan game engine
ScriptRunningSetup.h
Go to the documentation of this file.
1 // Leviathan Game Engine
2 // Copyright (c) 2012-2017 Henri Hyyryläinen
3 #pragma once
4 #include "Define.h"
5 // ------------------------------------ //
6 #include "ScriptCallingHelpers.h"
7 
9 
10 namespace Leviathan {
11 
13 
15 
17 public:
19 
21  DLLEXPORT ScriptRunningSetup(const std::string& entrypoint);
22 
23  DLLEXPORT ~ScriptRunningSetup();
24 
25  // named constructor idiom //
26  inline ScriptRunningSetup& SetEntrypoint(const std::string& epoint)
27  {
28  // set //
29  Entryfunction = epoint;
30  return *this;
31  }
32 
33  // This is in the script executor
34  // //! \param func Pointer to the script function. The caller must
35  // //! keep a reference alive to this function as long as this run
36  // //! setup is alive
37  // DLLEXPORT inline ScriptRunningSetup& SetEntrypoint(asIScriptFunction* func){
38 
39  // PreFetchedFunction = func;
40  // return *this;
41  // }
42 
43  inline ScriptRunningSetup& SetUseFullDeclaration(const bool& state)
44  {
45  // set //
46  FullDeclaration = state;
47  return *this;
48  }
49 
50  inline ScriptRunningSetup& SetPrintErrors(const bool& state)
51  {
52 
53  PrintErrors = state;
54  return *this;
55  }
56 
57  bool PrintErrors = true;
58  bool FullDeclaration = false;
59  bool ErrorOnNonExistingFunction = true;
61 
62 
63  bool ScriptExisted = false;
64 
65  std::string Entryfunction;
66 };
67 
72 template<typename ReturnT>
74 
75  ScriptRunResult(SCRIPT_RUN_RESULT result, ReturnT&& value) :
76  Result(result), Value(std::move(value))
77  {
78  // We need to take a reference as the script context is reset
79  // before we are returned to the caller
80  IncreasePointerReference();
81  }
82 
84  Result(other.Result), Value(other.Value)
85  {
86  // We need to take a reference as the other instance will release its pointer
87  IncreasePointerReference();
88  }
89 
91  Result(other.Result), Value(std::move(other.Value))
92  {
93  }
94 
96  ScriptRunResult(SCRIPT_RUN_RESULT result) : Result(result)
97  {
98  if constexpr(std::is_pointer_v<ReturnT>)
99  Value = nullptr;
100  }
101 
103  {
104  ReleasePointerReference();
105  }
106 
109  {
110  // Release our old pointer if it was reference counted
111  ReleasePointerReference();
112 
113  Value = other.Value;
114  Result = other.Result;
115 
116  // We need to take a reference as the other instance will release its pointer
117  IncreasePointerReference();
118 
119  return *this;
120  }
121 
122 protected:
125  {
126  if constexpr(std::is_pointer_v<ReturnT>) {
128  }
129  }
130 
133  {
134  if constexpr(std::is_pointer_v<ReturnT>) {
135 
137  }
138  }
139 
140 public:
143 
146  ReturnT Value;
147 };
148 
149 template<>
150 struct ScriptRunResult<void> {
151 
152  ScriptRunResult(SCRIPT_RUN_RESULT result) : Result(result) {}
153 
154  ScriptRunResult(const ScriptRunResult<void>& other) : Result(other.Result) {}
155 
158 
159  // This is the variant with no wanted return type
160 };
161 
162 } // namespace Leviathan
163 
164 #ifdef LEAK_INTO_GLOBAL
168 #endif // LEAK_INTO_GLOBAL
ScriptRunResult(SCRIPT_RUN_RESULT result)
Only set result code.
void ReleasePointerReference()
Helper for the multiple places that do pointer reference decrease.
ScriptRunningSetup & SetUseFullDeclaration(const bool &state)
ScriptRunningSetup & SetEntrypoint(const std::string &epoint)
STL namespace.
ScriptRunResult(const ScriptRunResult< void > &other)
Holds a result of the new script run method.
void IncreasePointerReference()
Helper for the multiple places that do pointer reference increase.
ScriptRunResult(SCRIPT_RUN_RESULT result, ReturnT &&value)
ScriptRunningSetup & SetPrintErrors(const bool &state)
ScriptRunResult & operator=(const ScriptRunResult< ReturnT > &other)
Assign other.
ScriptRunResult(ScriptRunResult< ReturnT > &&other)
ScriptRunResult(SCRIPT_RUN_RESULT result)
#define DLLEXPORT
Definition: Include.h:118
SCRIPT_RUN_RESULT Result
Result code of the script running.
static void DecrementRefCountIfRefCountedType(T *current)
Increments refcount of obj if it is derived from ReferenceCounted or an angelscript type...
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
static void IncrementRefCountIfRefCountedType(T *current)
Increments refcount of obj if it is derived from ReferenceCounted or an angelscript type...
ScriptRunResult(const ScriptRunResult< ReturnT > &other)
SCRIPT_RUN_RESULT Result
Result code of the script running.