add logging functions to the library 'debug'
This commit is contained in:
parent
d5877a342f
commit
0df5d34e04
@ -93,8 +93,7 @@ return {
|
|||||||
if callback then
|
if callback then
|
||||||
local result, err = pcall(callback)
|
local result, err = pcall(callback)
|
||||||
if err then
|
if err then
|
||||||
--// TODO: replace with error logging
|
debug.error(err)
|
||||||
print(err)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -107,8 +106,7 @@ return {
|
|||||||
if callback then
|
if callback then
|
||||||
local result, err = pcall(callback)
|
local result, err = pcall(callback)
|
||||||
if err then
|
if err then
|
||||||
--// TODO: replace with error logging
|
debug.error(err)
|
||||||
print(err)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -45,4 +45,6 @@ extern const luaL_Reg transformlib [];
|
|||||||
// Lua Overrides
|
// Lua Overrides
|
||||||
extern int l_print(lua::State* L);
|
extern int l_print(lua::State* L);
|
||||||
|
|
||||||
|
void initialize_libs_extends(lua::State* L);
|
||||||
|
|
||||||
#endif // LOGIC_SCRIPTING_API_LUA_HPP_
|
#endif // LOGIC_SCRIPTING_API_LUA_HPP_
|
||||||
|
|||||||
@ -97,6 +97,8 @@ void lua::initialize() {
|
|||||||
createtable(L, 0, 0);
|
createtable(L, 0, 0);
|
||||||
setglobal(L, CHUNKS_TABLE);
|
setglobal(L, CHUNKS_TABLE);
|
||||||
|
|
||||||
|
initialize_libs_extends(L);
|
||||||
|
|
||||||
newusertype<Bytearray, Bytearray::createMetatable>(L, "bytearray");
|
newusertype<Bytearray, Bytearray::createMetatable>(L, "bytearray");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
39
src/logic/scripting/lua/lua_extensions.cpp
Normal file
39
src/logic/scripting/lua/lua_extensions.cpp
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user