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
13
14namespace galaxy
15{
16 namespace lua
17 {
18 void log_wrapper(LogLevel error_level, std::string_view message)
19 {
20 switch (error_level)
21 {
22 case LogLevel::INFO:
23 GALAXY_LOG(GALAXY_INFO, "{0}", message);
24 break;
25
27 GALAXY_LOG(GALAXY_WARNING, "{0}", message);
28 break;
29
30 case LogLevel::ERROR:
31
32 GALAXY_LOG(GALAXY_ERROR, "{0}", message);
33 break;
34 }
35 }
36
38 {
39 auto& lua = entt::locator<sol::state>::value();
40
41 // clang-format off
42 // We dont have FATAL here because we dont want to throw exceptions inside lua.
43 lua.new_enum<LogLevel>("LogLevels",
44 {
45 {"INFO", LogLevel::INFO},
46 {"WARNING", LogLevel::WARNING},
47 {"ERROR", LogLevel::ERROR},
48 });
49 // clang-format on
50
51 lua.set_function("galaxy_log", &log_wrapper);
52 lua.set_function("galaxy_log_physfs_check", sol::resolve<bool(const int)>(log::physfs_check));
53 lua.set_function("galaxy_gl_errcode_as_string", &log::gl_errcode_as_string);
54 lua.set_function("galaxy_gl_get_all_errors", &log::gl_get_all_errors);
55 lua.set_function("galaxy_gl_add_error", &log::gl_add_error);
56 }
57 } // namespace lua
58} // namespace galaxy
#define GALAXY_INFO
Log.hpp galaxy.
Definition Log.hpp:22
#define GALAXY_WARNING
Definition Log.hpp:23
#define GALAXY_LOG(level, msg,...)
Definition Log.hpp:28
#define GALAXY_ERROR
Definition Log.hpp:24
std::vector< std::string > gl_get_all_errors() noexcept
Returns all GL errors on stack.
void gl_add_error(const unsigned int source, const unsigned int type, const unsigned int id, const unsigned int severity, const int length, const char *buf) noexcept
Insert a message into the OpenGL debug stack.
std::string gl_errcode_as_string(const int code) noexcept
Convert a GL error code to a string.
bool physfs_check(const int code) noexcept
Call a physfs function with error handling and logs a message for you.
void inject_logging()
Injects logging into Lua.
void log_wrapper(LogLevel error_level, std::string_view message)
Timer.hpp galaxy.
Definition Timer.cpp:18
LogLevel
Used to determine filtering and colouring of log messages.
Definition LogLevel.hpp:22
@ WARNING
Warning Log Level.
@ INFO
Info Log Level.
@ ERROR
Error Log Level.