add logging functions to the library 'debug'

This commit is contained in:
MihailRis 2024-07-16 12:32:00 +03:00
parent d5877a342f
commit 0df5d34e04
4 changed files with 45 additions and 4 deletions

View File

@ -93,8 +93,7 @@ return {
if callback then
local result, err = pcall(callback)
if err then
--// TODO: replace with error logging
print(err)
debug.error(err)
end
end
end
@ -107,8 +106,7 @@ return {
if callback then
local result, err = pcall(callback)
if err then
--// TODO: replace with error logging
print(err)
debug.error(err)
end
end
end

View File

@ -45,4 +45,6 @@ extern const luaL_Reg transformlib [];
// Lua Overrides
extern int l_print(lua::State* L);
void initialize_libs_extends(lua::State* L);
#endif // LOGIC_SCRIPTING_API_LUA_HPP_

View File

@ -97,6 +97,8 @@ void lua::initialize() {
createtable(L, 0, 0);
setglobal(L, CHUNKS_TABLE);
initialize_libs_extends(L);
newusertype<Bytearray, Bytearray::createMetatable>(L, "bytearray");
}

View File

@ -0,0 +1,39 @@
#include "api_lua.hpp"
#include "../../../debug/Logger.hpp"
static debug::Logger logger("lua-debug");
static int l_debug_error(lua::State* L) {
auto text = lua::require_string(L, 1);
logger.error() << text;
return 0;
}
static int l_debug_warning(lua::State* L) {
auto text = lua::require_string(L, 1);
logger.warning() << text;
return 0;
}
static int l_debug_log(lua::State* L) {
auto text = lua::require_string(L, 1);
logger.info() << text;
return 0;
}
void initialize_libs_extends(lua::State* L) {
if (lua::getglobal(L, "debug")) {
lua::pushcfunction(L, lua::wrap<l_debug_error>);
lua::setfield(L, "error");
lua::pushcfunction(L, lua::wrap<l_debug_warning>);
lua::setfield(L, "warning");
lua::pushcfunction(L, lua::wrap<l_debug_log>);
lua::setfield(L, "log");
lua::pop(L);
}
}