26#include <angelscript.h>
28#include "scriptdictionary/scriptdictionary.h"
29#include "scriptarray/scriptarray.h"
30#include "scriptbuilder/scriptbuilder.h"
45 std::string arraydecl = fmt::format(
"array<{}>", decl);
47 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo, vec.size());
49 for (AngelScript::asUINT i = 0; i < arr->GetSize(); i++)
53 arr->SetValue(i, &tempval);
59template <
typename T,
typename U>
60AngelScript::CScriptArray*
MapToScriptArray(std::map<T, U>& map,
const std::string& decl)
62 std::string arraydecl = fmt::format(
"array<{}>", decl);
64 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo, map.size());
66 for (
auto itor = map.begin(); itor != map.end(); itor++)
69 AngelScript::asUINT pos =
static_cast<AngelScript::asUINT
>(std::distance(map.begin(), itor));
70 arr->SetValue(pos, &itor->second);
60AngelScript::CScriptArray*
MapToScriptArray(std::map<T, U>& map,
const std::string& decl) {
…}
78template <
typename ItorT>
81 std::string arraydecl = fmt::format(
"array<{}>", decl);
83 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo);
85 for (
auto itor = begin; itor != end; itor++)
87 arr->InsertLast(&itor->second);
93template <
typename ItorT>
96 std::string arraydecl = fmt::format(
"array<{}>", decl);
98 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo);
100 for (
auto itor = begin; itor != end; itor++)
102 arr->InsertLast(&itor);
109bool GetValueFromScriptDict(
const std::string& log_msg, AngelScript::CScriptDictionary* dict,
bool required, std::string
const& key,
const char* decl, T & out_value)
120 auto itor = dict->find(key);
121 if (itor == dict->end())
132 const int actual_typeid = itor.GetTypeId();
133 if (actual_typeid != expected_typeid)
144 return itor.GetValue(&out_value, actual_typeid);
109bool GetValueFromScriptDict(
const std::string& log_msg, AngelScript::CScriptDictionary* dict,
bool required, std::string
const& key,
const char* decl, T & out_value) {
…}
158 bool Exists(
const std::string& key)
const
165 if (
m_map.size() == 0)
173 return AngelScript::asUINT(
m_map.size());
178 auto it =
m_map.find(key);
179 if (it !=
m_map.end())
188 AngelScript::CScriptArray* array = AngelScript::CScriptArray::Create(AngelScript::asGetActiveContext()->GetEngine()->GetTypeInfoByDecl(
"array<string>"), AngelScript::asUINT(
m_map.size()));
190 for (
auto it =
m_map.begin(); it !=
m_map.end(); it++)
193 *(std::string*)array->At(current) = it->first;
201 using namespace AngelScript;
207 r = engine->RegisterObjectBehaviour(decl, asBEHAVE_RELEASE,
"void f()", asMETHOD(CReadonlyScriptDictView <T>,
Release), asCALL_THISCALL);
ROR_ASSERT(r >= 0);
214 std::string opIndexDecl = fmt::format(
"{}@ opIndex(const string &in)", value_decl);
216 std::string opIndexConstDecl = fmt::format(
"const {}@ opIndex(const string &in) const", value_decl);
225 const std::map<std::string, T>&
m_map;
242 using namespace AngelScript;
248 r = engine->RegisterObjectBehaviour(decl, asBEHAVE_RELEASE,
"void f()", asMETHOD(CReadonlyScriptArrayView <T>,
Release), asCALL_THISCALL);
ROR_ASSERT(r >= 0);
253 std::string opIndexDecl = fmt::format(
"{}@ opIndex(uint pos)", value_decl);
255 std::string opIndexConstDecl = fmt::format(
"const {}@ opIndex(uint pos) const", value_decl);
269template<
class A,
class B>
276 B* b =
dynamic_cast<B*
>(a);
286template<
class A,
class B>
293 return dynamic_cast<B*
>(a);
#define ROR_ASSERT(_EXPR)
CReadonlyScriptArrayView(const std::vector< T > &vec)
const std::vector< T > & m_vec
static void RegisterReadonlyScriptArrayView(AngelScript::asIScriptEngine *engine, const char *decl, const char *value_decl)
T OpIndex(const std::string &key) const
static void RegisterReadonlyScriptDictView(AngelScript::asIScriptEngine *engine, const char *decl, const char *value_decl)
AngelScript::asUINT GetSize() const
const std::map< std::string, T > & m_map
bool Exists(const std::string &key) const
CReadonlyScriptDictView(const std::map< std::string, T > &map)
AngelScript::CScriptArray * GetKeys() const
void SLOG(const char *msg)
Replacement of macro.
AngelScript::asIScriptEngine * getEngine()
AngelScript::CScriptArray * VectorToScriptArray(const std::vector< T > &vec, const std::string &decl)
AngelScript::CScriptArray * MapToScriptArray(std::map< T, U > &map, const std::string &decl)
B * ScriptRefCastNoCount(A *a)
bool GetValueFromScriptDict(const std::string &log_msg, AngelScript::CScriptDictionary *dict, bool required, std::string const &key, const char *decl, T &out_value)
AngelScript::CScriptArray * IterableMapToScriptArray(ItorT begin, ItorT end, const std::string &decl)
AngelScript::CScriptArray * IterableListToScriptArray(ItorT begin, ItorT end, const std::string &decl)
ScriptEngine * GetScriptEngine()