galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
LuaLogging.cpp
Go to the documentation of this file.
1
7
8#include <sol/sol.hpp>
9
12
13#include "../Lua.hpp"
14
15namespace galaxy
16{
17 void log_wrapper(LogLevel error_level, std::string_view message)
18 {
19 switch (error_level)
20 {
21 case LogLevel::INFO:
22 GALAXY_LOG(GALAXY_INFO, "{0}", message);
23 break;
24
26 GALAXY_LOG(GALAXY_WARN, "{0}", message);
27 break;
28
29 case LogLevel::ERROR:
30
31 GALAXY_LOG(GALAXY_ERROR, "{0}", message);
32 break;
33 }
34 }
35
36 void Lua::inject_logging() noexcept
37 {
38 auto& lua = entt::locator<sol::state>::value();
39
40 // clang-format off
41 // We dont have FATAL here because we dont want to throw exceptions inside lua.
42 lua.new_enum<LogLevel>("LogLevels",
43 {
44 {"INFO", LogLevel::INFO},
45 {"WARNING", LogLevel::WARNING},
46 {"ERROR", LogLevel::ERROR},
47 });
48 // clang-format on
49
50 lua.set_function("galaxy_log", &log_wrapper);
51 lua.set_function("galaxy_log_physfs_check", sol::resolve<bool(const int)>(log::physfs_check));
52 }
53} // namespace galaxy
#define GALAXY_INFO
Log.hpp galaxy.
Definition Log.hpp:23
#define GALAXY_LOG(level, msg,...)
Definition Log.hpp:29
#define GALAXY_WARN
Definition Log.hpp:24
#define GALAXY_ERROR
Definition Log.hpp:25
static void inject_logging() noexcept
Injects logging into Lua.
bool physfs_check(const int code) noexcept
Call a physfs function with error handling and logs a message for you.
Application.hpp galaxy.
void log_wrapper(LogLevel error_level, std::string_view message)
LogLevel
Used to determine filtering and colouring of log messages.
Definition LogLevel.hpp:24
@ WARNING
Warning Log Level.
Definition LogLevel.hpp:33
@ INFO
Info Log Level.
Definition LogLevel.hpp:28
@ ERROR
Error Log Level.
Definition LogLevel.hpp:38