-
Notifications
You must be signed in to change notification settings - Fork 1
/
lua_api_output.c
142 lines (112 loc) · 4.29 KB
/
lua_api_output.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
* Copyright (c) 2009 Alexander Færøy <ahf@irssi.org>
*
* This program 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, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <lua_api_output.h>
#include <lua_irssi.h>
#define ADD_KV_PAIR(interpreter, key, value) \
lua_pushstring(interpreter, key); \
lua_pushnumber(interpreter, value); \
lua_rawset(interpreter, -3);
int lua_api_print(lua_State *interpreter) {
const char *message;
int n;
int msglevel;
n = lua_gettop(interpreter);
if (2 < n || 0 >= n) {
arity_mismatch("print");
return LUA_FAILURE;
}
if (2 != n) {
msglevel = MSGLEVEL_CLIENTCRAP;
message = lua_tostring(interpreter, -1);
} else {
msglevel = lua_tonumber(interpreter, -1);
message = lua_tostring(interpreter, -2);
}
printtext(NULL, NULL, msglevel, "%s", message);
return LUA_SUCCESS;
}
int lua_api_level2bits(lua_State *interpreter) {
const char *level;
int number;
if (1 != lua_gettop(interpreter)) {
arity_mismatch("level2bits");
return LUA_FAILURE;
}
level = lua_tostring(interpreter, -1);
number = level2bits(level, NULL);
lua_pushnumber(interpreter, number);
return LUA_SUCCESS;
}
int lua_api_bits2level(lua_State *interpreter) {
int level_number;
if (1 != lua_gettop(interpreter)) {
arity_mismatch("bits2level");
return LUA_FAILURE;
}
level_number = lua_tonumber(interpreter, -1);
lua_pushstring(interpreter, bits2level(level_number));
return LUA_SUCCESS;
}
int lua_api_combine_level(lua_State *interpreter) {
int level;
const char *str;
if (2 != lua_gettop(interpreter)) {
arity_mismatch("combine_level");
return LUA_FAILURE;
}
level = lua_tonumber(interpreter, -2);
str = lua_tostring(interpreter, -1);
lua_pushnumber(interpreter, combine_level(level, str));
return LUA_SUCCESS;
}
void register_lua_output_api(lua_State *interpreter) {
lua_newtable(interpreter);
ADD_KV_PAIR(interpreter, "crap", MSGLEVEL_CRAP);
ADD_KV_PAIR(interpreter, "msgs", MSGLEVEL_MSGS);
ADD_KV_PAIR(interpreter, "public", MSGLEVEL_PUBLIC);
ADD_KV_PAIR(interpreter, "notices", MSGLEVEL_NOTICES);
ADD_KV_PAIR(interpreter, "snotes", MSGLEVEL_SNOTES);
ADD_KV_PAIR(interpreter, "ctcps", MSGLEVEL_CTCPS);
ADD_KV_PAIR(interpreter, "actions", MSGLEVEL_ACTIONS);
ADD_KV_PAIR(interpreter, "joins", MSGLEVEL_JOINS);
ADD_KV_PAIR(interpreter, "parts", MSGLEVEL_PARTS);
ADD_KV_PAIR(interpreter, "quits", MSGLEVEL_QUITS);
ADD_KV_PAIR(interpreter, "kicks", MSGLEVEL_KICKS);
ADD_KV_PAIR(interpreter, "modes", MSGLEVEL_MODES);
ADD_KV_PAIR(interpreter, "topics", MSGLEVEL_TOPICS);
ADD_KV_PAIR(interpreter, "wallops", MSGLEVEL_WALLOPS);
ADD_KV_PAIR(interpreter, "invites", MSGLEVEL_INVITES);
ADD_KV_PAIR(interpreter, "nicks", MSGLEVEL_NICKS);
ADD_KV_PAIR(interpreter, "dcc", MSGLEVEL_DCC);
ADD_KV_PAIR(interpreter, "dccmsgs", MSGLEVEL_DCCMSGS);
ADD_KV_PAIR(interpreter, "clientnotice", MSGLEVEL_CLIENTNOTICE);
ADD_KV_PAIR(interpreter, "clientcrap", MSGLEVEL_CLIENTCRAP);
ADD_KV_PAIR(interpreter, "clienterror", MSGLEVEL_CLIENTERROR);
ADD_KV_PAIR(interpreter, "hilight", MSGLEVEL_HILIGHT);
ADD_KV_PAIR(interpreter, "all", MSGLEVEL_ALL);
ADD_KV_PAIR(interpreter, "nohilight", MSGLEVEL_NOHILIGHT);
ADD_KV_PAIR(interpreter, "no_act", MSGLEVEL_NO_ACT);
ADD_KV_PAIR(interpreter, "never", MSGLEVEL_NEVER);
ADD_KV_PAIR(interpreter, "lastlog", MSGLEVEL_LASTLOG);
lua_setglobal(interpreter, "msglevel");
}
void lua_api_output_init() {
}
void lua_api_output_deinit() {
}