26#include <angelscript.h>
28#include "scriptdictionary/scriptdictionary.h"
29#include "scriptarray/scriptarray.h"
30#include "scriptbuilder/scriptbuilder.h"
46 std::string arraydecl = fmt::format(
"array<{}>", decl);
48 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo, vec.size());
50 for (AngelScript::asUINT i = 0; i < arr->GetSize(); i++)
54 arr->SetValue(i, &tempval);
60template <
typename T,
typename U>
61AngelScript::CScriptArray*
MapToScriptArray(std::map<T, U>& map,
const std::string& decl)
63 std::string arraydecl = fmt::format(
"array<{}>", decl);
65 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo, map.size());
67 for (
auto itor = map.begin(); itor != map.end(); itor++)
70 AngelScript::asUINT pos =
static_cast<AngelScript::asUINT
>(std::distance(map.begin(), itor));
71 arr->SetValue(pos, &itor->second);
79template <
typename ItorT>
82 std::string arraydecl = fmt::format(
"array<{}>", decl);
84 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo);
86 for (
auto itor = begin; itor != end; itor++)
88 arr->InsertLast(&itor->second);
94template <
typename ItorT>
97 std::string arraydecl = fmt::format(
"array<{}>", decl);
99 AngelScript::CScriptArray* arr = AngelScript::CScriptArray::Create(typeinfo);
101 for (
auto itor = begin; itor != end; itor++)
103 arr->InsertLast(&itor);
110bool GetValueFromScriptDict(
const std::string& log_msg, AngelScript::CScriptDictionary* dict,
bool required, std::string
const& key,
const char* decl, T & out_value)
121 auto itor = dict->find(key);
122 if (itor == dict->end())
133 const int actual_typeid = itor.GetTypeId();
134 if (actual_typeid != expected_typeid)
145 return itor.GetValue(&out_value, actual_typeid);
159 bool Exists(
const std::string& key)
const
166 if (
m_map.size() == 0)
174 return AngelScript::asUINT(
m_map.size());
179 auto it =
m_map.find(key);
180 if (it !=
m_map.end())
189 AngelScript::CScriptArray* array = AngelScript::CScriptArray::Create(AngelScript::asGetActiveContext()->GetEngine()->GetTypeInfoByDecl(
"array<string>"), AngelScript::asUINT(
m_map.size()));
191 for (
auto it =
m_map.begin(); it !=
m_map.end(); it++)
194 *(std::string*)array->At(current) = it->first;
202 using namespace AngelScript;
208 r = engine->RegisterObjectBehaviour(decl, asBEHAVE_RELEASE,
"void f()", asMETHOD(CReadonlyScriptDictView <T>,
Release), asCALL_THISCALL);
ROR_ASSERT(r >= 0);
215 std::string opIndexDecl = fmt::format(
"{}@ opIndex(const string &in)", value_decl);
217 std::string opIndexConstDecl = fmt::format(
"const {}@ opIndex(const string &in) const", value_decl);
224 using namespace AngelScript;
237 std::string opIndexDecl = fmt::format(
"{}@ opIndex(const string &in)", value_decl);
239 std::string opIndexConstDecl = fmt::format(
"const {}@ opIndex(const string &in) const", value_decl);
247 const std::map<std::string, T>&
m_map;
264 using namespace AngelScript;
270 r = engine->RegisterObjectBehaviour(decl, asBEHAVE_RELEASE,
"void f()", asMETHOD(CReadonlyScriptArrayView <T>,
Release), asCALL_THISCALL);
ROR_ASSERT(r >= 0);
275 std::string opIndexDecl = fmt::format(
"{}@ opIndex(uint pos)", value_decl);
277 std::string opIndexConstDecl = fmt::format(
"const {}@ opIndex(uint pos) const", value_decl);
284 using namespace AngelScript;
295 std::string opIndexDecl = fmt::format(
"{}@ opIndex(uint pos)", value_decl);
297 std::string opIndexConstDecl = fmt::format(
"const {}@ opIndex(uint pos) const", value_decl);
310template<
class A,
class B>
317 B* b =
dynamic_cast<B*
>(a);
327template<
class A,
class B>
334 return dynamic_cast<B*
>(a);
#define ROR_ASSERT(_EXPR)
#define WRAP_MFN(ClassType, name)
static void RegisterReadonlyScriptArrayViewGeneric(AngelScript::asIScriptEngine *engine, const char *decl, const char *value_decl)
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
static void RegisterReadonlyScriptDictViewGeneric(AngelScript::asIScriptEngine *engine, const char *decl, const char *value_decl)
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()