Chi-Tech
chi_console_flushconsole.cc
Go to the documentation of this file.
2#include "chi_runtime.h"
3#include "chi_log.h"
4
5//###################################################################
6/** This function sends the commands contained in the command_buffer to
7the lua state from where it is executed. These could be commands passed
8 via the command line or loaded elsewhere.*/
10{
11 try
12 {
13 for (auto& command : command_buffer_)
14 {
15 bool error = luaL_dostring(console_state_, command.c_str());
16 if (error)
17 {
18 Chi::log.LogAll() << lua_tostring(console_state_, -1);
19 lua_pop(console_state_, 1);
20 }
21 }
22 }
23 catch(const std::exception& e)
24 {
25 Chi::log.LogAllError() << e.what();
26 Chi::Exit(EXIT_FAILURE);
27 }
28}
static void Exit(int error_code)
Definition: chi_runtime.cc:342
static chi::ChiLog & log
Definition: chi_runtime.h:81
LogStream LogAllError()
Definition: chi_log.h:239
LogStream LogAll()
Definition: chi_log.h:237
lua_State * console_state_
Pointer to lua console state.
Definition: chi_console.h:109
void FlushConsole()
Flushes any commands in the command buffer.
std::vector< std::string > command_buffer_
Buffer of commands to execute.
Definition: chi_console.h:111