diff options
| author | mniip <mniip@mniip.com> | 2013-04-26 13:15:33 (GMT) |
|---|---|---|
| committer | mniip <mniip@mniip.com> | 2013-04-26 13:15:33 (GMT) |
| commit | 9f7d45f8fd663a043c5eee26583372d51440d6ff (patch) | |
| tree | 7ffd5f67494f03d32430150b184a8567c66d2fae /src/cat/LegacyLuaAPI.cpp | |
| parent | f9017bc7bbaf74729552897e98093923318b8e76 (diff) | |
| download | powder-9f7d45f8fd663a043c5eee26583372d51440d6ff.zip powder-9f7d45f8fd663a043c5eee26583372d51440d6ff.tar.gz | |
print does implicit tostring, also generates a list ouside of console too
Diffstat (limited to 'src/cat/LegacyLuaAPI.cpp')
| -rw-r--r-- | src/cat/LegacyLuaAPI.cpp | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/src/cat/LegacyLuaAPI.cpp b/src/cat/LegacyLuaAPI.cpp index df019fa..302f2f1 100644 --- a/src/cat/LegacyLuaAPI.cpp +++ b/src/cat/LegacyLuaAPI.cpp @@ -843,22 +843,44 @@ int luatpt_setconsole(lua_State* l) luacon_controller->HideConsole(); return 0; } - +static int luaL_tostring (lua_State *L, int n) { + luaL_checkany(L, n); + switch (lua_type(L, n)) { + case LUA_TNUMBER: + lua_pushstring(L, lua_tostring(L, n)); + break; + case LUA_TSTRING: + lua_pushvalue(L, n); + break; + case LUA_TBOOLEAN: + lua_pushstring(L, (lua_toboolean(L, n) ? "true" : "false")); + break; + case LUA_TNIL: + lua_pushliteral(L, "nil"); + break; + default: + lua_pushfstring(L, "%s: %p", luaL_typename(L, n), lua_topointer(L, n)); + break; + } + return 1; +} int luatpt_log(lua_State* l) { int args = lua_gettop(l); + std::string text = ""; for(int i = 1; i <= args; i++) { - if((*luacon_currentCommand)) - { - if(!(*luacon_lastError).length()) - (*luacon_lastError) = luaL_optstring(l, i, ""); - else - (*luacon_lastError) += ", " + std::string(luaL_optstring(l, i, "")); - } + luaL_tostring(l, lua_gettop(l)); + if(text.length()) + text=std::string(luaL_optstring(l, lua_gettop(l), "")) + ", " + text; else - luacon_ci->Log(CommandInterface::LogNotice, luaL_optstring(l, i, "")); + text=std::string(luaL_optstring(l, lua_gettop(l), "")); + lua_pop(l, 2); } + if((*luacon_currentCommand)) + (*luacon_lastError) = text; + else + luacon_ci->Log(CommandInterface::LogNotice, text.c_str()); return 0; } |
