embedded mono runtime

This commit is contained in:
2024-08-09 23:02:20 +03:00
parent 0aefa70fb8
commit 2710e5fc9d
7 changed files with 127 additions and 17 deletions

View File

@@ -5,6 +5,9 @@
#include "Game/Scene.hpp"
#include "format.hpp"
#include "exceptions.hpp"
#include <mono/jit/jit.h>
#include <mono/metadata/assembly.h>
#include <mono/metadata/mono-config.h>
using namespace ougge;
@@ -15,6 +18,26 @@ void update(f64 deltaTime){
int main(int argc, const char** argv){
try {
Resources::init();
mono_set_dirs("mono-libs", "mono-libs");
mono_set_assemblies_path("mono-libs");
mono_config_parse("mono-libs/config.xml");
std::cout<<"mono_root_dir: "<<mono_assembly_getrootdir()<<std::endl;
std::cout<<"mono_config_dir: "<<mono_get_config_dir()<<std::endl;
MonoDomain* domain = mono_jit_init("myapp");
if(!domain)
throw UsefulException("can't initialize mono domain");
std::cout<<"jit domain initialized"<<std::endl;
MonoAssembly* assembly = mono_domain_assembly_open(domain, "app.exe");
if(!assembly)
throw UsefulException("can't load assembly");
char* mono_argv[] = { "app.exe" };
int mono_argc = 1;
int retval = mono_jit_exec(domain, assembly, mono_argc, mono_argv);
if(retval)
throw new UsefulException(format("managed assembly returned error code: %i", retval));
mono_jit_cleanup(domain);
return 0;
GUI::MainWindow w;
w.open("ougge", update);
w.startUpdateLoop();