--- a/main.c Mon Apr 27 12:51:53 2009 +0300
+++ b/main.c Thu May 21 00:13:26 2009 +0300
@@ -1,3 +1,20 @@
+
+/* Copyright 2009 Myhailo Danylenko
+
+This file is part of mcabber-lua.
+
+mcabber-lua is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <glib.h>
#include <gmodule.h>
@@ -38,10 +55,40 @@
/// print
/// Prints its arguments to log with default priority.
-/// A: string/number, ...
+/// A: something, ...
static int lua_global_print (lua_State *L)
{
- lua_concat (L, lua_gettop (L));
+ int top = lua_gettop (L);
+ int i;
+ luaL_Buffer B;
+ luaL_buffinit (L, &B);
+ for (i = 1; i <= top; i++) {
+ int type = lua_type (L, i);
+ if (i > 1)
+ luaL_addchar (&B, '\t');
+ if (type == LUA_TSTRING) {
+ size_t len;
+ const char *str = lua_tolstring (L, i, &len);
+ luaL_addlstring (&B, str, len);
+ } else if (type == LUA_TNUMBER)
+ luaL_addstring (&B, lua_tostring (L, i)); // XXX: modifies
+ else if (type == LUA_TBOOLEAN) {
+ if (lua_toboolean (L, i))
+ luaL_addstring (&B, "true");
+ else
+ luaL_addstring (&B, "false");
+ } else if (type == LUA_TNIL)
+ luaL_addstring (&B, "nil");
+ else {
+ char xbuf[9];
+ luaL_addstring (&B, luaL_typename (L, i));
+ luaL_addstring (&B, ": 0x");
+ snprintf (&xbuf[0], 9, "%08x", (int) lua_topointer (L, i));
+ luaL_addlstring (&B, xbuf, 8); // XXX
+ }
+ }
+ luaL_pushresult (&B);
+
scr_LogPrint (LPRINT_LOGNORM | LPRINT_NOTUTF8, lua_tostring (L, -1));
return 0;
}