Skip to content

Commit

Permalink
add logging for trace and warnings to lua bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
arozx committed Jan 23, 2025
1 parent ddb0312 commit 2b44567
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions sandbox/assets/scripts/engine.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
---@field setClearColor fun(r: number, g: number, b: number, a: number) # Sets the renderer clear color
---@field isKeyPressed fun(keycode: number): boolean # Checks if a key is pressed
---@field getMousePosition fun(): number, number # Gets current mouse position
---@field trace fun(message: string) # Logs a trace message
---@field log fun(message: string) # Logs an info message
---@field warn fun(message: string) # Logs an warn message
---@field error fun(message: string) # Logs an error message
---@field loadScript fun(filepath: string): boolean # Loads and executes a Lua script file
engine = {}
Expand Down
3 changes: 3 additions & 0 deletions sandbox/assets/scripts/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,7 @@ end

-- Set default terrain parameters
engine.setTerrainHeight(10.0)
engine.trace("Lua environment initialized")
engine.log("Lua environment initialized")
engine.warn("Lua environment initialized")
engine.error("Lua environment initialized")
12 changes: 10 additions & 2 deletions src/Scripting/LuaScriptSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,20 @@ namespace Engine {
});

// Debug/Logging API
engine.set_function("trace", [](const std::string& message) {
LOG_TRACE_CONCAT("[Lua]: ", message, ".");
});

engine.set_function("log", [](const std::string& message) {
LOG_INFO_CONCAT("[Lua] {", message, "}");
LOG_INFO_CONCAT("[Lua]: ", message, ".");
});

engine.set_function("warn", [](const std::string& message) {
LOG_WARN_CONCAT("[Lua]: ", message, ".");
});

engine.set_function("error", [](const std::string& message) {
LOG_ERROR_CONCAT("[Lua] {", message, "}");
LOG_ERROR_CONCAT("[Lua]: ", message, ".");
});

// File System API
Expand Down

0 comments on commit 2b44567

Please sign in to comment.