added editor WIP
This commit is contained in:
@@ -7,6 +7,8 @@ std::ofstream TSE::Debug::logFile;
|
||||
const std::string fileName = "log.txt";
|
||||
const std::string fileNameOld = "lastlog.txt";
|
||||
|
||||
std::vector<void(*)(const std::string&, const TSE::LogEntryType&)> TSE::Debug::onLogCallbacks = std::vector<void(*)(const std::string&, const LogEntryType&)>();
|
||||
|
||||
int luaPrintRedirect(lua_State* L)
|
||||
{
|
||||
int n = lua_gettop(L);
|
||||
@@ -61,18 +63,30 @@ void TSE::Debug::Log(string msg)
|
||||
{
|
||||
std::cout << msg << std::endl;
|
||||
logFile << msg << std::endl;
|
||||
for(auto fnc : onLogCallbacks)
|
||||
{
|
||||
fnc(msg, LogEntryType::Log);
|
||||
}
|
||||
}
|
||||
|
||||
void TSE::Debug::Error(string msg)
|
||||
{
|
||||
std::cerr << "[Error] " << msg << std::endl;
|
||||
logFile << "[Error] " << msg << std::endl;
|
||||
for(auto fnc : onLogCallbacks)
|
||||
{
|
||||
fnc("[Error] " + msg, LogEntryType::Error);
|
||||
}
|
||||
}
|
||||
|
||||
void TSE::Debug::Warning(string msg)
|
||||
{
|
||||
std::cout << "[Warning] " << msg << std::endl;
|
||||
logFile << "[Warning] " << msg << std::endl;
|
||||
for(auto fnc : onLogCallbacks)
|
||||
{
|
||||
fnc("[Warning] " + msg, LogEntryType::Warning);
|
||||
}
|
||||
}
|
||||
|
||||
void TSE::Debug::Close()
|
||||
@@ -80,3 +94,8 @@ void TSE::Debug::Close()
|
||||
logFile.flush();
|
||||
logFile.close();
|
||||
}
|
||||
|
||||
void TSE::Debug::AddCallback(void (*func)(const std::string &, const LogEntryType &))
|
||||
{
|
||||
onLogCallbacks.push_back(func);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,13 @@
|
||||
|
||||
namespace TSE
|
||||
{
|
||||
enum LogEntryType
|
||||
{
|
||||
Log,
|
||||
Error,
|
||||
Warning,
|
||||
};
|
||||
|
||||
class Debug
|
||||
{
|
||||
public:
|
||||
@@ -25,9 +32,11 @@ namespace TSE
|
||||
static void Warning(string msg);
|
||||
/// @brief closes the log file
|
||||
static void Close();
|
||||
static void AddCallback(void(*func)(const std::string&, const LogEntryType&));
|
||||
|
||||
private:
|
||||
static std::ofstream logFile;
|
||||
static std::vector<void(*)(const std::string&, const LogEntryType&)> onLogCallbacks;
|
||||
};
|
||||
|
||||
} // namespace TSE
|
||||
|
||||
Reference in New Issue
Block a user