-
Notifications
You must be signed in to change notification settings - Fork 1
/
lua_api.c
107 lines (88 loc) · 3.55 KB
/
lua_api.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
/* vim: set sw=4 sts=4 et foldmethod=syntax : */
/*
* Copyright (c) 2009 Alexander Færøy <[email protected]>
*
* 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.h>
#include <lua_irssi.h>
#include <lua_loader.h>
#include <lua_api_settings.h>
#include <lua_api_output.h>
#include <lua_api_commands.h>
#include <lua_api_signals.h>
static const luaL_Reg irssi_lua_functions[] = {
{ "print", lua_api_print },
{ "printtext", lua_api_print },
{ "level2bits", lua_api_level2bits },
{ "bits2level", lua_api_bits2level },
{ "combine_level", lua_api_combine_level },
{ "settings_get_str", lua_api_settings_get_str },
{ "settings_get_int", lua_api_settings_get_int },
{ "settings_get_bool", lua_api_settings_get_bool },
{ "settings_get_time", lua_api_settings_get_time },
{ "settings_get_level", lua_api_settings_get_level },
{ "settings_get_size", lua_api_settings_get_size },
{ "settings_set_str", lua_api_settings_set_str },
{ "settings_set_int", lua_api_settings_set_int },
{ "settings_set_bool", lua_api_settings_set_bool },
{ "settings_set_time", lua_api_settings_set_time },
{ "settings_set_level", lua_api_settings_set_level },
{ "settings_set_size", lua_api_settings_set_size },
{ "settings_add_str", lua_api_settings_add_str },
{ "settings_add_int", lua_api_settings_add_int },
{ "settings_add_bool", lua_api_settings_add_bool },
{ "settings_add_time", lua_api_settings_add_time },
{ "settings_add_level", lua_api_settings_add_level },
{ "settings_add_size", lua_api_settings_add_size },
{ "settings_remove", lua_api_settings_remove },
{ "signal_stop", lua_api_signal_stop },
{ "signal_stop_by_name", lua_api_signal_stop_by_name },
{ NULL, NULL }
};
void arity_mismatch(const char *function_name) {
printtext(NULL, NULL, MSGLEVEL_CLIENTERROR, "Arity mismatch for function \"%s\"", function_name);
}
void register_lua_api(lua_State *interpreter, const char *script_name) {
luaL_openlib(interpreter, "Irssi", irssi_lua_functions, 0);
lua_newtable(interpreter);
lua_pushstring(interpreter, "script_name");
lua_pushstring(interpreter, script_name);
lua_rawset(interpreter, -3);
lua_setglobal(interpreter, "__irssi_script_information__");
register_lua_output_api(interpreter);
}
char *get_caller_name(lua_State *interpreter) {
char *script_name;
lua_getglobal(interpreter, "__irssi_script_information__");
lua_pushstring(interpreter, "script_name");
lua_gettable(interpreter, -2);
script_name = g_strdup(lua_tostring(interpreter, -1));
lua_pop(interpreter, 2);
return script_name;
}
void lua_api_init() {
lua_api_settings_init();
lua_api_commands_init();
lua_api_signals_init();
lua_api_output_init();
}
void lua_api_deinit()
{
lua_api_settings_deinit();
lua_api_commands_deinit();
lua_api_signals_deinit();
lua_api_output_deinit();
}