1 Star 0 Fork 0

2144/mono_lib

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
Object.cpp 1.91 KB
一键复制 编辑 原始数据 按行查看 历史
2144 提交于 2024-10-26 12:33 . ss
#include "Object.h"
#include "States.h"
#include "Clazz.h"
#include "Field.h"
using namespace mono;
template <>
void Object::PushArg<glm::vec3>(std::vector<void *> &addresses, glm::vec3 &arg)
{
auto clazz = mono::States::GetClazz("Vec3");
m_MonoObject = clazz->NewInstanceObject();
//auto monoClass = clazz->m_Class;
mono_field_set_value(m_MonoObject, clazz->GetField("x")->m_Field, &arg.x);
mono_field_set_value(m_MonoObject, clazz->GetField("y")->m_Field, &arg.y);
mono_field_set_value(m_MonoObject, clazz->GetField("z")->m_Field, &arg.z);
addresses.push_back(m_MonoObject);
};
template <>
void Object::PushArg<int>(std::vector<void *> &addresses, int &arg)
{
addresses.push_back(&arg);
};
template <>
void Object::PushArg<std::string>(std::vector<void *> &addresses, std::string &arg)
{
addresses.push_back(mono_string_new(mono_domain_get(), arg.c_str()));
};
template <>
void Object::PushArg<float>(std::vector<void *> &addresses, float &arg)
{
addresses.push_back(&arg);
};
template <>
glm::vec3 Object::As<glm::vec3>()
{
auto clazz = mono::States::GetClazz("Vec3");
glm::vec3 arg;
MonoClassField *fieldX = mono_class_get_field_from_name(clazz->m_Class, "x");
MonoClassField *fieldY = mono_class_get_field_from_name(clazz->m_Class, "y");
MonoClassField *fieldZ = mono_class_get_field_from_name(clazz->m_Class, "z");
mono_field_get_value(this->m_MonoObject, fieldX, &arg.x);
mono_field_get_value(this->m_MonoObject, fieldY, &arg.y);
mono_field_get_value(this->m_MonoObject, fieldZ, &arg.z);
return arg;
};
template <>
int Object::As<int>()
{
return *(int *)mono_object_unbox(m_MonoObject);
};
template <>
float Object::As<float>()
{
return *(float*)mono_object_unbox(m_MonoObject);
};
template <>
std::string Object::As<std::string>()
{
MonoString *resultString = (MonoString *)m_MonoObject;
return mono_string_to_utf8(resultString);
};
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/iamherer/mono_lib.git
git@gitee.com:iamherer/mono_lib.git
iamherer
mono_lib
mono_lib
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385