mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 03:06:29 +00:00
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:
@@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2018 Wildfire Games.
|
||||
/* Copyright (C) 2021 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@@ -21,34 +21,23 @@
|
||||
|
||||
#include "ps/CConsole.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "scriptinterface/ScriptInterface.h"
|
||||
#include "scriptinterface/FunctionWrapper.h"
|
||||
|
||||
bool JSI_Console::CheckGlobalInitialized()
|
||||
namespace
|
||||
{
|
||||
CConsole* ConsoleGetter(const ScriptRequest&, JS::CallArgs&)
|
||||
{
|
||||
if (!g_Console)
|
||||
{
|
||||
LOGERROR("Trying to access the console when it's not initialized!");
|
||||
return false;
|
||||
return nullptr;
|
||||
}
|
||||
return true;
|
||||
return g_Console;
|
||||
}
|
||||
}
|
||||
|
||||
bool JSI_Console::GetVisibleEnabled(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate))
|
||||
void JSI_Console::RegisterScriptFunctions(const ScriptRequest& rq)
|
||||
{
|
||||
if (!CheckGlobalInitialized())
|
||||
return false;
|
||||
return g_Console->IsActive();
|
||||
}
|
||||
|
||||
void JSI_Console::SetVisibleEnabled(ScriptInterface::CmptPrivate* UNUSED(pCmptPrivate), bool Enabled)
|
||||
{
|
||||
if (!CheckGlobalInitialized())
|
||||
return;
|
||||
g_Console->SetVisible(Enabled);
|
||||
}
|
||||
|
||||
void JSI_Console::RegisterScriptFunctions(const ScriptInterface& scriptInterface)
|
||||
{
|
||||
scriptInterface.RegisterFunction<bool, &JSI_Console::GetVisibleEnabled>("Console_GetVisibleEnabled");
|
||||
scriptInterface.RegisterFunction<void, bool, &JSI_Console::SetVisibleEnabled>("Console_SetVisibleEnabled");
|
||||
ScriptFunction::Register<&CConsole::IsActive, ConsoleGetter>(rq, "Console_GetVisibleEnabled");
|
||||
ScriptFunction::Register<&CConsole::SetVisible, ConsoleGetter>(rq, "Console_SetVisibleEnabled");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user