Permalink
Browse files

extend Spring.Log syntax, it's now Spring.Log(logsection, loglevel, ...)

  • Loading branch information...
1 parent c1f5202 commit c2f3ea32b57152b05bab0b5170976f390db3691c jK committed Mar 18, 2012
Showing with 19 additions and 15 deletions.
  1. +1 −0 cont/LuaUI/system.lua
  2. +4 −3 doc/changelog.txt
  3. +14 −12 rts/Lua/LuaUtils.cpp
View
@@ -33,6 +33,7 @@ if (System == nil) then
GL = GL,
CMD = CMD,
CMDTYPE = CMDTYPE,
+ LOG = LOG,
UnitDefs = UnitDefs,
UnitDefNames = UnitDefNames,
View
@@ -18,9 +18,10 @@ Unitsync:
Lua:
- added new Spring.TestMoveOrder(unitDefID, worldx, worldy, worldz) -> boolean
- added new Spring.Log()
- - same as Spring.Echo, but passes a LOG_LEVEL to the logsystem (LOG.DEBUG is by default hidden for release builds)
- - Spring.Log(int loglevel, ...) (with loglevel either: LOG.DEBUG, LOG.INFO, LOG.WARNING, LOG.ERROR, LOG.FATAL)
- - Spring.Log(string loglevel, ...) (with either: "debug", "info", "warning", "error", "fatal" [lower-/uppercase doesn't matter])
+ - same as Spring.Echo, but passes metadata to the logsystem
+ ! to be able to use LOG.XYZ you need to update your system.lua
+ - Spring.Log(string logsection, int loglevel, ...) (with loglevel either: LOG.DEBUG, LOG.INFO, LOG.WARNING, LOG.ERROR, LOG.FATAL)
+ - Spring.Log(string logsection, string loglevel, ...) (with either: "debug", "info", "warning", "error", "fatal" [lower-/uppercase doesn't matter])
- fixed WeaponDefs[123].pairs()
- added myGravity tag to WeaponDefs[] table (thx DeadnightWarrior)
! distinguish water-damage in Unit{Pre}Damaged
View
@@ -793,23 +793,25 @@ bool LuaUtils::PushLogEntries(lua_State* L)
Logs a msg to the logfile / console
@param loglevel loglevel that will be used for the message
@param msg string to be logged
- @fn Spring.Log(int loglevel, ...)
- @fn Spring.Log(string loglevel, ...)
+ @fn Spring.Log(string logsection, int loglevel, ...)
+ @fn Spring.Log(string logsection, string loglevel, ...)
*/
int LuaUtils::Log(lua_State* L)
{
const int args = lua_gettop(L); // number of arguments
- if (args < 1)
- return luaL_error(L, "Incorrect arguments to Spring.Log(loglevel, ...)");
if (args < 2)
+ return luaL_error(L, "Incorrect arguments to Spring.Log(logsection, loglevel, ...)");
+ if (args < 3)
return 0;
+ const std::string section = luaL_checkstring(L, 1);
+
int loglevel;
- if (lua_israwnumber(L, 1)) {
- loglevel = lua_tonumber(L, 1);
+ if (lua_israwnumber(L, 2)) {
+ loglevel = lua_tonumber(L, 2);
}
- else if (lua_israwstring(L, 1)) {
- std::string loglvlstr = lua_tostring(L, 1);
+ else if (lua_israwstring(L, 2)) {
+ std::string loglvlstr = lua_tostring(L, 2);
StringToLowerInPlace(loglvlstr);
if (loglvlstr == "debug") {
loglevel = LOG_LEVEL_DEBUG;
@@ -827,15 +829,15 @@ int LuaUtils::Log(lua_State* L)
loglevel = LOG_LEVEL_FATAL;
}
else {
- return luaL_error(L, "Incorrect arguments to Spring.Log(loglevel, ...)");
+ return luaL_error(L, "Incorrect arguments to Spring.Log(logsection, loglevel, ...)");
}
}
else {
- return luaL_error(L, "Incorrect arguments to Spring.Log(loglevel, ...)");
+ return luaL_error(L, "Incorrect arguments to Spring.Log(logsection, loglevel, ...)");
}
- const std::string msg = getprintf_msg(L, 2);
- LOG_I(loglevel, msg.c_str());
+ const std::string msg = getprintf_msg(L, 3);
+ LOG_SI(section.c_str(), loglevel, msg.c_str());
return 0;
}

0 comments on commit c2f3ea3

Please sign in to comment.