I’m desperately trying to make the excellent Lua wrapper Sol2 work with UE4 C++ in Visual Studio 2015 for a Windows game.
The problem is that Sol2 requires C++14(/17) and it seems that UE4 only uses C++11 (even though VS2015 has a C++14 compiler by default), which results in ton’s of error messages (i’ve listed some here) when the compiler is trying to go through the sol2 file (i’m using the single-header file version).
Sol2 works with every other software project i’ve done so far, it’s only UE4 that has these problems with it.
Is it possible to make/compile UE4 so it uses C++14(/17) in VS2015? If so, how (if possible, with details)?
I’ve tried looking into the “\Engine\Source\Programs\UnrealBuildTool\Windows\VCToolChain.cs” file but i couldn’t find any compiler options for VS2015 that i could make any use of, i think the only compiler options i could find in that file was for the Clang compiler:
if (WindowsPlatform.bCompileWithClang)
{
if (!WindowsPlatform.bUseVCCompilerArgs)
{
Arguments.Append(" -std=c++11");
Arguments.Append(" -fdiagnostics-format=msvc");
Arguments.Append(" -Xclang -relaxed-aliasing -Xclang --dependent-lib=msvcrt -Xclang --dependent-lib=oldnames -gline-tables-only -ffunction-sections");
}
but i’m using Visual Studio 2015, not Clang.
I know there was a topic about this last december
but the method that person used doesn’t work for me (not sure if that other person used a compiler other than the one from VS2015 and if the file structure has changed since then, none of the subfolders of my UnrealBuildTool folder does have any ToolChain.cs file nor any config file for Windows with a “GetCompileArguments” function).
Any help is greatly appreciated.
EDIT : SOLUTION
It seems that the new Sol2 release is UE4 compatible.
There is only one thing you need to pay attention to :
When including the “sol.hpp” in an UE4 project you need to wrap it around in an #undef and #define shell for the check() macro, like this:
#undef check
#include "sol.hpp"
#if DO_CHECK
#define check(expr) { if(UNLIKELY(!(expr))) { FDebug::LogAssertFailedMessage( #expr, __FILE__, __LINE__ ); _DebugBreakAndPromptForRemote(); FDebug::AssertFailed( #expr, __FILE__, __LINE__ ); CA_ASSUME(false); } }
#else
#define check(expr) { CA_ASSUME(expr); }
#endif
(the first #define check(expr) { if(UNLIKELY… ) should be one consistent line, here it seems to be broken up)
The reason for that is because Unreal4 uses several “#define check(expr)…” macros and sol2 uses check(expr) aswell, but in a different way, so check() needs to be undefined when including sol.hpp and then redefined when the include code returns to UE4.
There could also be compiler warnings like
warning C4628: digraphs not supported with -Ze. Character sequence '<:' not interpreted as alternate token for '['
But those can be ignored.
If you want to get rid of these warnings you can manually search for any occurence of “::std::” and “::sol::” in the sol.hpp and change it to “std::” and “sol::” (aka remove the “::” global scope prefixes so it only says “std::” and “sol::”), its only like 4 lines
So if anyone else needs a great and fast C++ Lua Wrapper for UE4, feel free to use Sol2
Happy scripting