static int l_tm_log(lua_State* L) { const char level = lua_tonumber(L, 1); size_t buf_len = 0; const char* buf = (const char*) colony_tolutf8(L, 2, &buf_len); tm_log(level, buf, buf_len); return 0; }
void tm_logf(char level, const char* format, ...) { va_list args; va_start(args, format); char buf[BUF_SIZE]; int len = vsnprintf(buf, sizeof(buf), format, args); if (len > BUF_SIZE) len = BUF_SIZE; va_end (args); tm_log(level, buf, len); }
static int report(lua_State *L, int status) { if (status != 0) { size_t len = 0; const char *msg = colony_tolstring(L, -1, &len); if (msg != NULL) { tm_log(SYS_ERR, msg, len); } else { tm_logf(SYS_ERR, "(error traceback is not a string)"); } lua_pop(L, 1); } return status; }