How to use pure c not c++
mic89 opened this issue · comments
mic commented
Hello, How to use pure c not c++
Jackson Dunstan commented
Hi @zmicx, the code generator only generates C++ bindings right now. If you want to use C instead of C++, you can write a thin compatibility layer in your C++ game code using extern "C"
. For example,
Game.h
#ifdef __cplusplus
extern "C"
{
#endif
void GameObjectNew();
#ifdef __cplusplus
}
#endif
Game.cpp
#include "Game.h"
#include "Bindings.h"
extern "C"
{
void GameObjectNew(const char* name)
{
System::String managedName(name);
UnityEngine::GameObject go(managedName);
}
}
Game.c
#include "Game.h"
GameObjectNew("test");