debug::Logger

This commit is contained in:
MihailRis
2024-04-04 18:19:19 +03:00
parent f298d6ef1d
commit 0c411cf227
16 changed files with 233 additions and 51 deletions
+5 -2
View File
@@ -4,8 +4,11 @@
#include <iostream>
#include "lua_util.h"
#include "api_lua.h"
#include "../../../debug/Logger.h"
#include "../../../util/stringutil.h"
static debug::Logger logger("lua-state");
lua::luaerror::luaerror(const std::string& message) : std::runtime_error(message) {
}
@@ -19,8 +22,8 @@ void lua::LuaState::removeLibFuncs(const char* libname, const char* funcs[]) {
}
lua::LuaState::LuaState() {
std::cout << LUA_VERSION << std::endl;
std::cout << LUAJIT_VERSION << std::endl;
logger.info() << LUA_VERSION;
logger.info() << LUAJIT_VERSION;
L = luaL_newstate();
if (L == nullptr) {
+7 -4
View File
@@ -3,6 +3,7 @@
#include <iostream>
#include <stdexcept>
#include "../../debug/Logger.h"
#include "../../content/ContentPack.h"
#include "../../files/engine_paths.h"
#include "../../files/files.h"
@@ -26,6 +27,8 @@ namespace scripting {
extern lua::LuaState* state;
}
static debug::Logger logger("scripting");
Engine* scripting::engine = nullptr;
lua::LuaState* scripting::state = nullptr;
Level* scripting::level = nullptr;
@@ -284,7 +287,7 @@ bool scripting::emit_event(const std::string &name, std::function<int(lua::LuaSt
void scripting::load_block_script(int env, std::string prefix, fs::path file, block_funcs_set& funcsset) {
std::string src = files::read_string(file);
std::cout << "loading script " << file.u8string() << std::endl;
logger.info() << "script (block) " << file.u8string();
state->execute(env, src, file.u8string());
funcsset.init = register_event(env, "init", prefix+".init");
funcsset.update = register_event(env, "on_update", prefix+".update");
@@ -297,7 +300,7 @@ void scripting::load_block_script(int env, std::string prefix, fs::path file, bl
void scripting::load_item_script(int env, std::string prefix, fs::path file, item_funcs_set& funcsset) {
std::string src = files::read_string(file);
std::cout << "loading script " << file.u8string() << std::endl;
logger.info() << "script (item) " << file.u8string();
state->execute(env, src, file.u8string());
funcsset.init = register_event(env, "init", prefix+".init");
@@ -308,7 +311,7 @@ void scripting::load_item_script(int env, std::string prefix, fs::path file, ite
void scripting::load_world_script(int env, std::string prefix, fs::path file) {
std::string src = files::read_string(file);
std::cout << "loading script " << file.u8string() << std::endl;
logger.info() << "loading world script for " << prefix;
state->loadbuffer(env, src, file.u8string());
state->callNoThrow(0);
@@ -322,7 +325,7 @@ void scripting::load_world_script(int env, std::string prefix, fs::path file) {
void scripting::load_layout_script(int env, std::string prefix, fs::path file, uidocscript& script) {
std::string src = files::read_string(file);
std::cout << "loading script " << file.u8string() << std::endl;
logger.info() << "loading script " << file.u8string();
script.environment = env;
state->loadbuffer(env, src, file.u8string());
@@ -1,9 +1,10 @@
#include "scripting_frontend.h"
#include "scripting_hud.h"
#include "scripting.h"
#include "lua/api_lua.h"
#include "lua/LuaState.h"
#include "../../debug/Logger.h"
#include "../../frontend/hud.h"
#include "../../objects/Player.h"
#include "../../files/files.h"
@@ -15,6 +16,8 @@ namespace scripting {
extern lua::LuaState* state;
}
static debug::Logger logger("scripting-hud");
Hud* scripting::hud = nullptr;
void scripting::on_frontend_init(Hud* hud) {
@@ -41,7 +44,7 @@ void scripting::on_frontend_close() {
void scripting::load_hud_script(int env, std::string packid, fs::path file) {
std::string src = files::read_string(file);
std::cout << "loading script " << file.u8string() << std::endl;
logger.info() << "loading script " << file.u8string();
state->loadbuffer(env, src, file.u8string());
state->callNoThrow(0);
@@ -1,5 +1,5 @@
#ifndef LOGIC_SCRIPTING_SCRIPTING_FRONTEND_H_
#define LOGIC_SCRIPTING_SCRIPTING_FRONTEND_H_
#ifndef LOGIC_SCRIPTING_SCRIPTING_HUD_H_
#define LOGIC_SCRIPTING_SCRIPTING_HUD_H_
#include <string>
#include <filesystem>
@@ -23,4 +23,4 @@ namespace scripting {
void load_hud_script(int env, std::string packid, fs::path file);
}
#endif // LOGIC_SCRIPTING_SCRIPTING_FRONTEND_H_
#endif // LOGIC_SCRIPTING_SCRIPTING_HUD_H_