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 <entt/locator/locator.hpp>
9#include <sol/sol.hpp>
10
14
15#include "../Lua.hpp"
16
17namespace galaxy
18{
19 void log_wrapper(LogLevel error_level, std::string_view message)
20 {
21 switch (error_level)
22 {
23 case LogLevel::INFO:
24 GALAXY_LOG(GALAXY_INFO, "{0}", message);
25 break;
26
28 GALAXY_LOG(GALAXY_WARN, "{0}", message);
29 break;
30
31 case LogLevel::ERROR:
32
33 GALAXY_LOG(GALAXY_ERROR, "{0}", message);
34 break;
35 }
36 }
37
38 void Lua::inject_logging() noexcept
39 {
40 auto& lua = entt::locator<sol::state>::value();
41
42 // clang-format off
43 // We dont have FATAL here because we dont want to throw exceptions inside lua.
44 lua.new_enum<LogLevel>("LogLevels",
45 {
46 {"INFO", LogLevel::INFO},
47 {"WARNING", LogLevel::WARNING},
48 {"ERROR", LogLevel::ERROR},
49 });
50 // clang-format on
51
52 lua.set_function("galaxy_log", &log_wrapper);
53 lua.set_function("galaxy_log_physfs_check", sol::resolve<bool(const int)>(log::physfs_check));
54 lua.set_function("galaxy_gl_errcode_as_string", &log::gl_errcode_as_string);
55 lua.set_function("galaxy_gl_get_all_errors", &log::gl_get_all_errors);
56 lua.set_function("galaxy_gl_add_error", &log::gl_add_error);
57 }
58} // 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.
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.
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