diff options
author | madmaxoft <github@xoft.cz> | 2014-03-31 22:51:14 +0200 |
---|---|---|
committer | madmaxoft <github@xoft.cz> | 2014-03-31 22:51:14 +0200 |
commit | 8126d9e66ef1ac90db2660ae357c9aa1c14c7126 (patch) | |
tree | 50b5d1fe0106761a31de387f4574b592bc9fb28d /src/Bindings/ManualBindings.cpp | |
parent | APIDump: Added code completion support file to ZBS tutorial. (diff) | |
download | cuberite-8126d9e66ef1ac90db2660ae357c9aa1c14c7126.tar cuberite-8126d9e66ef1ac90db2660ae357c9aa1c14c7126.tar.gz cuberite-8126d9e66ef1ac90db2660ae357c9aa1c14c7126.tar.bz2 cuberite-8126d9e66ef1ac90db2660ae357c9aa1c14c7126.tar.lz cuberite-8126d9e66ef1ac90db2660ae357c9aa1c14c7126.tar.xz cuberite-8126d9e66ef1ac90db2660ae357c9aa1c14c7126.tar.zst cuberite-8126d9e66ef1ac90db2660ae357c9aa1c14c7126.zip |
Diffstat (limited to '')
-rw-r--r-- | src/Bindings/ManualBindings.cpp | 46 |
1 files changed, 34 insertions, 12 deletions
diff --git a/src/Bindings/ManualBindings.cpp b/src/Bindings/ManualBindings.cpp index 20bbc48f2..95cd5e904 100644 --- a/src/Bindings/ManualBindings.cpp +++ b/src/Bindings/ManualBindings.cpp @@ -115,10 +115,35 @@ static int tolua_StringSplitAndTrim(lua_State * tolua_S) -static int tolua_LOG(lua_State* tolua_S) +/** Retrieves the log message from the first param on the Lua stack. +Can take either a string or a cCompositeChat. +*/ +static AString GetLogMessage(lua_State * tolua_S) { - const char* str = tolua_tocppstring(tolua_S,1,0); - cMCLogger::GetInstance()->LogSimple( str, 0 ); + tolua_Error err; + if (tolua_isusertype(tolua_S, 1, "cCompositeChat", false, &err)) + { + return ((cCompositeChat *)tolua_tousertype(tolua_S, 1, NULL))->ExtractText(); + } + else + { + size_t len = 0; + const char * str = lua_tolstring(tolua_S, 1, &len); + if (str != NULL) + { + return AString(str, len); + } + } + return ""; +} + + + + + +static int tolua_LOG(lua_State * tolua_S) +{ + cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 0); return 0; } @@ -126,10 +151,9 @@ static int tolua_LOG(lua_State* tolua_S) -static int tolua_LOGINFO(lua_State* tolua_S) +static int tolua_LOGINFO(lua_State * tolua_S) { - const char* str = tolua_tocppstring(tolua_S,1,0); - cMCLogger::GetInstance()->LogSimple( str, 1 ); + cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 1); return 0; } @@ -137,10 +161,9 @@ static int tolua_LOGINFO(lua_State* tolua_S) -static int tolua_LOGWARN(lua_State* tolua_S) +static int tolua_LOGWARN(lua_State * tolua_S) { - const char* str = tolua_tocppstring(tolua_S,1,0); - cMCLogger::GetInstance()->LogSimple( str, 2 ); + cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 2); return 0; } @@ -148,10 +171,9 @@ static int tolua_LOGWARN(lua_State* tolua_S) -static int tolua_LOGERROR(lua_State* tolua_S) +static int tolua_LOGERROR(lua_State * tolua_S) { - const char* str = tolua_tocppstring(tolua_S,1,0); - cMCLogger::GetInstance()->LogSimple( str, 3 ); + cMCLogger::GetInstance()->LogSimple(GetLogMessage(tolua_S).c_str(), 3); return 0; } |