Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JSInterface_Console.cpp
Go to the documentation of this file.
1 /* Copyright (C) 2013 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * 0 A.D. is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include "precompiled.h"
19 
21 #include "JSInterface_Console.h"
22 #include "ps/CConsole.h"
23 #include "ps/CLogger.h"
24 
26 {
27  if (!g_Console)
28  {
29  LOGERROR(L"Trying to access the console when it's not initialized!");
30  return false;
31  }
32  return true;
33 }
34 
36 {
38  return false;
39  return g_Console->IsActive();
40 }
41 
42 void JSI_Console::SetVisibleEnabled(void* UNUSED(cbdata), bool Enabled)
43 {
45  return;
46  g_Console->SetVisible(Enabled);
47 }
48 
49 void JSI_Console::Write(void* UNUSED(cbdata), std::wstring output)
50 {
52  return;
53  g_Console->InsertMessage(L"%ls", output.c_str());
54 }
55 
57 {
58  scriptInterface.RegisterFunction<bool, &JSI_Console::GetVisibleEnabled>("Console_GetVisibleEnabled");
59  scriptInterface.RegisterFunction<void, bool, &JSI_Console::SetVisibleEnabled>("Console_SetVisibleEnabled");
60  scriptInterface.RegisterFunction<void, std::wstring, &JSI_Console::Write>("Console_Write");
61 }
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning. ...
#define LOGERROR
Definition: CLogger.h:35
tuple output
Definition: tests.py:116
bool GetVisibleEnabled(void *cbdata)
bool IsActive()
Definition: CConsole.h:88
CConsole * g_Console
Definition: CConsole.cpp:46
void SetVisibleEnabled(void *cbdata, bool Enabled)
bool CheckGlobalInitialized()
void Write(void *cbdata, std::wstring output)
Abstraction around a SpiderMonkey JSContext.
void RegisterScriptFunctions(ScriptInterface &scriptInterface)
void SetVisible(bool visible)
Definition: CConsole.cpp:96
void InsertMessage(const wchar_t *szMessage,...) WPRINTF_ARGS(2)
Definition: CConsole.cpp:508