<commit_before>#include "csharp.h"
#include "audio/audio_scene.h"
#include "animation/animation.h"
#include "animation/animation_scene.h"
#include "engine/blob.h"
#include "engine/crc32.h"
#include "engine/engine.h"
#include "engine/hash_map.h"
#include "engine/iallocator.h"
#include "engine/iplugin.h"
#include "engine/log.h"
#include "engine/path.h"
#include "engine/path_utils.h"
#include "engine/property_register.h"
#include "engine/serializer.h"
#include "engine/universe/component.h"
#include "engine/universe/universe.h"
#include "imgui/imgui.h"
#include "navigation/navigation_scene.h"
#include "physics/physics_scene.h"
#include "renderer/render_scene.h"

#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/mono-config.h>
#include <mono/metadata/tokentype.h>


#pragma comment(lib, "mono-2.0-sgen.lib")


namespace Lumix
{


static const ComponentType CSHARP_SCRIPT_TYPE = PropertyRegister::getComponentType("csharp_script");


struct CSharpPluginImpl : public CSharpPlugin
{
	CSharpPluginImpl(Engine& engine);
	~CSharpPluginImpl();
	const char* getName() const override { return "csharp_script"; }
	void createScenes(Universe& universe) override;
	void destroyScene(IScene* scene) override { LUMIX_DELETE(m_engine.getAllocator(), scene); }
	void unloadAssembly() override;
	void loadAssembly() override;
	int getNamesCount() const override { return m_names.size(); }
	const char* getName(int idx) const override { return m_names.at(idx).c_str(); }

	Engine& m_engine;
	IAllocator& m_allocator;
	MonoDomain* m_domain = nullptr;
	MonoAssembly* m_assembly = nullptr;
	MonoDomain* m_assembly_domain = nullptr;
	AssociativeArray<u32, string> m_names;
	DelegateList<void()> m_on_assembly_unload;
	DelegateList<void()> m_on_assembly_load;
};


ComponentHandle csharp_Entity_getComponent(Universe* universe, Entity entity, MonoString* cmp_type)
{
	const char* type = mono_string_to_utf8(cmp_type);
	return universe->getComponent(entity, PropertyRegister::getComponentType(type)).handle;
}


IScene* csharp_Component_getScene(Universe* universe, MonoString* type_str)
{
	const char* type = mono_string_to_utf8(type_str);
	ComponentType cmp_type = PropertyRegister::getComponentType(type);
	return universe->getScene(cmp_type);
}


int csharp_Component_create(Universe* universe, int entity, MonoString* type_str)
{
	const char* type = mono_string_to_utf8(type_str);
	ComponentType cmp_type = PropertyRegister::getComponentType(type);
	IScene* scene = universe->getScene(cmp_type);
	if (!scene) return INVALID_COMPONENT.index;
	if (scene->getComponent({entity}, cmp_type) != INVALID_COMPONENT)
	{
		g_log_error.log("C# Script") << "Component " << type << " already exists in entity " << entity;
		return INVALID_COMPONENT.index;
	}

	return scene->createComponent(cmp_type, {entity}).index;
}


void csharp_Entity_destroy(Universe* universe, int entity)
{
	universe->destroyEntity({entity});
}


void csharp_Entity_setPosition(Universe* universe, int entity, const Vec3& pos)
{
	universe->setPosition({entity}, pos);
}


Vec3 csharp_Entity_getPosition(Universe* universe, int entity)
{
	return universe->getPosition({entity});
}


void csharp_Entity_setRotation(Universe* universe, int entity, const Quat& pos)
{
	universe->setRotation({entity}, pos);
}


Quat csharp_Entity_getRotation(Universe* universe, int entity)
{
	return universe->getRotation({entity});
}


void csharp_Entity_setName(Universe* universe, int entity, MonoString* name)
{
	universe->setEntityName({ entity }, mono_string_to_utf8(name));
}


MonoString* csharp_Entity_getName(Universe* universe, int entity)
{
	return mono_string_new(mono_domain_get(), universe->getEntityName({entity}));
}


template <typename T> struct ToCSharpType { typedef T Type; };
template <> struct ToCSharpType<const char*> { typedef MonoString* Type; };
template <> struct ToCSharpType<Path> { typedef MonoString* Type; };
template <typename T> T toCSharpValue(T val) { return val; }
MonoString* toCSharpValue(const char* val) { return mono_string_new(mono_domain_get(), val); }
MonoString* toCSharpValue(const Path& val) { return mono_string_new(mono_domain_get(), val.c_str()); }
template <typename T> T fromCSharpValue(T val) { return val; }
const char* fromCSharpValue(MonoString* val) { return mono_string_to_utf8(val); }


template<typename T> struct CSharpTypeConvertor
{
	using Type = T;

	static Type convert(Type val) { return val; }
};

<commit_msg>compilable with void return value<commit_after>#include "csharp.h"
#include "audio/audio_scene.h"
#include "animation/animation.h"
#include "animation/animation_scene.h"
#include "engine/blob.h"
#include "engine/crc32.h"
#include "engine/engine.h"
#include "engine/hash_map.h"
#include "engine/iallocator.h"
#include "engine/iplugin.h"
#include "engine/log.h"
#include "engine/path.h"
#include "engine/path_utils.h"
#include "engine/property_register.h"
#include "engine/serializer.h"
#include "engine/universe/component.h"
#include "engine/universe/universe.h"
#include "imgui/imgui.h"
#include "navigation/navigation_scene.h"
#include "physics/physics_scene.h"
#include "renderer/render_scene.h"

#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/mono-config.h>
#include <mono/metadata/tokentype.h>


#pragma comment(lib, "mono-2.0-sgen.lib")


namespace Lumix
{


static const ComponentType CSHARP_SCRIPT_TYPE = PropertyRegister::getComponentType("csharp_script");


struct CSharpPluginImpl : public CSharpPlugin
{
	CSharpPluginImpl(Engine& engine);
	~CSharpPluginImpl();
	const char* getName() const override { return "csharp_script"; }
	void createScenes(Universe& universe) override;
	void destroyScene(IScene* scene) override { LUMIX_DELETE(m_engine.getAllocator(), scene); }
	void unloadAssembly() override;
	void loadAssembly() override;
	int getNamesCount() const override { return m_names.size(); }
	const char* getName(int idx) const override { return m_names.at(idx).c_str(); }

	Engine& m_engine;
	IAllocator& m_allocator;
	MonoDomain* m_domain = nullptr;
	MonoAssembly* m_assembly = nullptr;
	MonoDomain* m_assembly_domain = nullptr;
	AssociativeArray<u32, string> m_names;
	DelegateList<void()> m_on_assembly_unload;
	DelegateList<void()> m_on_assembly_load;
};


ComponentHandle csharp_Entity_getComponent(Universe* universe, Entity entity, MonoString* cmp_type)
{
	const char* type = mono_string_to_utf8(cmp_type);
	return universe->getComponent(entity, PropertyRegister::getComponentType(type)).handle;
}


IScene* csharp_Component_getScene(Universe* universe, MonoString* type_str)
{
	const char* type = mono_string_to_utf8(type_str);
	ComponentType cmp_type = PropertyRegister::getComponentType(type);
	return universe->getScene(cmp_type);
}


int csharp_Component_create(Universe* universe, int entity, MonoString* type_str)
{
	const char* type = mono_string_to_utf8(type_str);
	ComponentType cmp_type = PropertyRegister::getComponentType(type);
	IScene* scene = universe->getScene(cmp_type);
	if (!scene) return INVALID_COMPONENT.index;
	if (scene->getComponent({entity}, cmp_type) != INVALID_COMPONENT)
	{
		g_log_error.log("C# Script") << "Component " << type << " already exists in entity " << entity;
		return INVALID_COMPONENT.index;
	}

	return scene->createComponent(cmp_type, {entity}).index;
}


void csharp_Entity_destroy(Universe* universe, int entity)
{
	universe->destroyEntity({entity});
}


void csharp_Entity_setPosition(Universe* universe, int entity, const Vec3& pos)
{
	universe->setPosition({entity}, pos);
}


Vec3 csharp_Entity_getPosition(Universe* universe, int entity)
{
	return universe->getPosition({entity});
}


void csharp_Entity_setRotation(Universe* universe, int entity, const Quat& pos)
{
	universe->setRotation({entity}, pos);
}


Quat csharp_Entity_getRotation(Universe* universe, int entity)
{
	return universe->getRotation({entity});
}


void csharp_Entity_setName(Universe* universe, int entity, MonoString* name)
{
	universe->setEntityName({ entity }, mono_string_to_utf8(name));
}


MonoString* csharp_Entity_getName(Universe* universe, int entity)
{
	return mono_string_new(mono_domain_get(), universe->getEntityName({entity}));
}


template <typename T> struct ToCSharpType { typedef T Type; };
template <> struct ToCSharpType<const char*> { typedef MonoString* Type; };
template <> struct ToCSharpType<Path> { typedef MonoString* Type; };
template <typename T> T toCSharpValue(T val) { return val; }
MonoString* toCSharpValue(const char* val) { return mono_string_new(mono_domain_get(), val); }
MonoString* toCSharpValue(const Path& val) { return mono_string_new(mono_domain_get(), val.c_str()); }
template <typename T> T fromCSharpValue(T val) { return val; }
const char* fromCSharpValue(MonoString* val) { return mono_string_to_utf8(val); }


template<typename T> struct CSharpTypeConvertor
{
	using Type = T;

	static Type convert(Type val) { return val; }
};


template<> struct CSharpTypeConvertor<void>
{
	using Type = void;
};



{'fraction_non_alphanumeric': 0.12582708425231584, 'fraction_numerical': 0.002867225408028231, 'mean_word_length': 6.9274475524475525, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 61, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7341062', 'n_tokens_mistral': 3170, 'n_tokens_neox': 3045, 'n_words': 652}