24 #ifdef USE_ANGELSCRIPT
26 #include <angelscript.h>
27 #include "scriptdictionary/scriptdictionary.h"
28 #include "scriptarray/scriptarray.h"
29 #include "scriptbuilder/scriptbuilder.h"
44 std::string arraydecl =
fmt::format(
"array<{}>", decl);
46 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo, vec.size());
48 for (AngelScript::asUINT i = 0; i < arr->GetSize(); i++)
52 arr->SetValue(i, &tempval);
58 template <
typename T,
typename U>
59 AngelScript::CScriptArray*
MapToScriptArray(std::map<T, U>& map,
const std::string& decl)
61 std::string arraydecl =
fmt::format(
"array<{}>", decl);
63 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo, map.size());
65 for (
auto itor = map.begin(); itor != map.end(); itor++)
68 AngelScript::asUINT pos =
static_cast<AngelScript::asUINT
>(std::distance(map.begin(), itor));
69 arr->SetValue(pos, &itor->second);
77 template <
typename ItorT>
80 std::string arraydecl =
fmt::format(
"array<{}>", decl);
82 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo);
84 for (
auto itor = begin; itor != end; itor++)
86 arr->InsertLast(&itor->second);
92 template <
typename ItorT>
95 std::string arraydecl =
fmt::format(
"array<{}>", decl);
97 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo);
99 for (
auto itor = begin; itor != end; itor++)
101 arr->InsertLast(&itor);
108 bool GetValueFromScriptDict(
const std::string& log_msg, AngelScript::CScriptDictionary* dict,
bool required, std::string
const& key,
const char* decl, T & out_value)
119 auto itor = dict->find(key);
120 if (itor == dict->end())
131 const int actual_typeid = itor.GetTypeId();
132 if (actual_typeid != expected_typeid)
143 return itor.GetValue(&out_value, actual_typeid);
157 bool Exists(
const std::string& key)
const
164 if (
m_map.size() == 0)
172 return AngelScript::asUINT(
m_map.size());
177 auto it =
m_map.find(key);
178 if (it !=
m_map.end())
187 AngelScript::CScriptArray* array = AngelScript::CScriptArray::Create(AngelScript::asGetActiveContext()->GetEngine()->GetTypeInfoByDecl(
"array<string>"), AngelScript::asUINT(
m_map.size()));
189 for (
auto it =
m_map.begin(); it !=
m_map.end(); it++)
192 *(std::string*)array->At(current) = it->first;
200 using namespace AngelScript;
213 std::string opIndexDecl =
fmt::format(
"{}@ opIndex(const string &in)", value_decl);
215 std::string opIndexConstDecl =
fmt::format(
"const {}@ opIndex(const string &in) const", value_decl);
224 const std::map<std::string, T>&
m_map;
228 template <
typename T>
235 bool IsEmpty()
const {
return m_vec.empty(); }
236 unsigned GetSize()
const {
return m_vec.size(); }
237 T
OpIndex(
unsigned pos) {
return m_vec.at(pos); }
241 using namespace AngelScript;
252 std::string opIndexDecl =
fmt::format(
"{}@ opIndex(uint pos)", value_decl);
254 std::string opIndexConstDecl =
fmt::format(
"const {}@ opIndex(uint pos) const", value_decl);
268 template<
class A,
class B>
275 B* b =
dynamic_cast<B*
>(a);
285 template<
class A,
class B>
292 return dynamic_cast<B*
>(a);
299 #endif // USE_ANGELSCRIPT