Introduce C++ templates replacements for DEFINE_INTERFACE_X and RegisterFunction macros

The new methods:
- aren't included in ScriptInterface.h directly, lightening that header
- don't use boost CPP
- don't need argument types or number or constness to be specified
- can work with object methods somewhat transparently
- support optional cmptPrivate (allowing removal of many UNUSED macro)
- support optional const ScriptRequest&, which is safer.

This first diff changes only some of the JSI files & the component
manager. Further diffs will update other files and finally delete the
current code.

Differential Revision: https://code.wildfiregames.com/D2818
This was SVN commit r24969.
This commit is contained in:
wraitii
2021-03-01 20:52:24 +00:00
parent 9ed3b88d25
commit f3aedf88a6
17 changed files with 562 additions and 243 deletions
+6 -4
View File
@@ -36,6 +36,7 @@
#include "lib/timer.h"
#include "lib/sysdep/sysdep.h"
#include "ps/Profiler2.h"
#include "scriptinterface/FunctionWrapper.h"
#include "scriptinterface/ScriptEngine.h"
#include "scriptinterface/ScriptContext.h"
#include "scriptinterface/ScriptInterface.h"
@@ -138,15 +139,16 @@ OsPath DataDir()
namespace
{
void script_TS_FAIL(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), const std::wstring& msg)
void script_TS_FAIL(const std::wstring& msg)
{
TS_FAIL(utf8_from_wstring(msg).c_str());
}
}
void ScriptTestSetup(const ScriptInterface& scriptinterface)
void ScriptTestSetup(const ScriptInterface& scriptInterface)
{
scriptinterface.RegisterFunction<void, std::wstring, script_TS_FAIL>("TS_FAIL");
ScriptRequest rq(scriptInterface);
ScriptFunction::Register<script_TS_FAIL>(rq, "TS_FAIL");
// Load the TS_* function definitions
// (We don't use VFS because tests might not have the normal VFS paths loaded)
@@ -154,5 +156,5 @@ void ScriptTestSetup(const ScriptInterface& scriptinterface)
std::ifstream ifs(OsString(path).c_str());
ENSURE(ifs.good());
std::string content((std::istreambuf_iterator<char>(ifs)), std::istreambuf_iterator<char>());
ENSURE(scriptinterface.LoadScript(L"test_setup.js", content));
ENSURE(scriptInterface.LoadScript(L"test_setup.js", content));
}