Leviathan  0.8.0.0
Leviathan game engine
Console.h
Go to the documentation of this file.
1 #pragma once
2 // ------------------------------------ //
3 #include "Define.h"
4 // ------------------------------------ //
5 #include "ScriptExecutor.h"
6 #include "ErrorReporter.h"
7 
8 
9 namespace Leviathan{
10 
15 };
16 
26 };
27 
30 public:
31  virtual void Write(const std::string &text) override;
32 
33  virtual void WriteLine(const std::string &text) override;
34 
35  virtual void Info(const std::string &text) override;
36 
37  virtual void Warning(const std::string &text) override;
38 
39  virtual void Error(const std::string &text) override;
40 
41  virtual void Fatal(const std::string &text) override;
42 };
43 
46 class ScriptConsole : public ThreadSafe{
47 public:
50 
51  DLLEXPORT bool Init(ScriptExecutor* MainScript);
52  DLLEXPORT void Release();
53 
54  // this function takes direct std::string input from user and translates it to be used in
55  // one of the functions below
56  // console commands should be in format of ">[TYPE=""] [COMMAND]" eg.
57  // ">ADDVAR int newglobal = 25"
58  // or "> for(int i = 0; i < 5; i++) GlobalFunc();" multiline commands are done by
59  // putting '\' to the end of each line
60  DLLEXPORT int RunConsoleCommand(std::string cmd);
61 
63  DLLEXPORT bool ExecuteStringInstruction(Lock &guard, const std::string &statement);
64 
65  DLLEXPORT inline bool ExecuteStringInstruction(const std::string &statement){
66 
67  GUARD_LOCK();
68  return ExecuteStringInstruction(guard, statement);
69  }
70 
71  DLLEXPORT bool AddVariableStringDefinition(Lock &guard, std::string statement);
72  DLLEXPORT bool DeleteVariableStringDefinition(Lock &guard, const std::string &statement);
73  DLLEXPORT bool AddFunctionStringDefinition(Lock &guard, const std::string &statement);
74  DLLEXPORT bool DeleteFunctionStringDefinition(Lock &guard, const std::string &statement);
75 
76  // common functions that are in the style of the angel script sdk example console //
77  DLLEXPORT void ListFunctions(Lock &guard);
78  DLLEXPORT void ListVariables(Lock &guard);
79 
80 private:
81  // function used to add prefix to console output //
82  inline void ConsoleOutput(const std::string &text){
83  LogOutput.Write("[CONSOLE] " + text);
84  }
85 
86  ConsoleLogger LogOutput;
87 
88  // stored pointer to script interface //
89  ScriptExecutor* InterfaceInstance;
90 
91  // the script module that Console runs in //
92  std::weak_ptr<ScriptModule> ConsoleModule;
93 
94  // variables about the current command //
95  // multi line command stored part //
96  std::string PendingCommand;
97 
98  int consoleemptyspam;
99 
100  // static map for special function definitions in command s//
101  static std::map<std::string, CONSOLECOMMANDTYPE> CommandTypeDefinitions;
102 };
103 
104 
105 }
106 
Logger for console output to the standard logger.
Definition: Console.h:29
DLLEXPORT ScriptConsole()
Definition: Console.cpp:10
virtual void Write(const std::string &text) override
Definition: Console.cpp:456
DLLEXPORT bool DeleteFunctionStringDefinition(Lock &guard, const std::string &statement)
Definition: Console.cpp:340
Allows the inherited object to be locked.
Definition: ThreadSafe.h:137
DLLEXPORT ~ScriptConsole()
Definition: Console.cpp:14
Handles ScriptModule creation and AngelScript code execution.
CONSOLECOMMANDTYPE
Definition: Console.h:17
DLLEXPORT bool ExecuteStringInstruction(Lock &guard, const std::string &statement)
calls script helper and runs this statement on the console module
Definition: Console.cpp:232
DLLEXPORT void ListVariables(Lock &guard)
Definition: Console.cpp:417
virtual void WriteLine(const std::string &text) override
Definition: Console.cpp:462
virtual void Fatal(const std::string &text) override
Quits the current game with an error message.
Definition: Console.cpp:486
DLLEXPORT bool Init(ScriptExecutor *MainScript)
Definition: Console.cpp:27
DLLEXPORT bool ExecuteStringInstruction(const std::string &statement)
Definition: Console.h:65
DLLEXPORT bool AddFunctionStringDefinition(Lock &guard, const std::string &statement)
Definition: Console.cpp:303
CONSOLECOMMANDRESULTSTATE
Definition: Console.h:11
DLLEXPORT int RunConsoleCommand(std::string cmd)
Definition: Console.cpp:49
DLLEXPORT void ListFunctions(Lock &guard)
Definition: Console.cpp:383
virtual void Info(const std::string &text) override
Definition: Console.cpp:468
DLLEXPORT bool DeleteVariableStringDefinition(Lock &guard, const std::string &statement)
Definition: Console.cpp:285
DLLEXPORT bool AddVariableStringDefinition(Lock &guard, std::string statement)
Definition: Console.cpp:269
DLLEXPORT void Release()
Definition: Console.cpp:39
virtual void Error(const std::string &text) override
Definition: Console.cpp:480
#define DLLEXPORT
Definition: Include.h:84
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
virtual void Warning(const std::string &text) override
Definition: Console.cpp:474
#define GUARD_LOCK()
Definition: ThreadSafe.h:111
std::unique_lock< std::mutex > Lock
Definition: ThreadSafe.h:18