mirror of
https://github.com/weechat/weechat.git
synced 2026-07-01 07:16:37 +02:00
plugins: move scripting API constants to plugin-script.c
This commit is contained in:
@@ -36,10 +36,6 @@
|
||||
#include "weechat-lua.h"
|
||||
|
||||
|
||||
#define API_DEF_CONST_INT(__name) \
|
||||
{ #__name, __name, NULL }
|
||||
#define API_DEF_CONST_STR(__name) \
|
||||
{ #__name, 0, __name }
|
||||
#define API_DEF_FUNC(__name) \
|
||||
{ #__name, &weechat_lua_api_##__name }
|
||||
#define API_FUNC(__name) \
|
||||
@@ -5966,58 +5962,5 @@ const struct luaL_Reg weechat_lua_api_funcs[] = {
|
||||
API_DEF_FUNC(upgrade_write_object),
|
||||
API_DEF_FUNC(upgrade_read),
|
||||
API_DEF_FUNC(upgrade_close),
|
||||
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
const struct t_lua_const weechat_lua_api_consts[] =
|
||||
{
|
||||
API_DEF_CONST_INT(WEECHAT_RC_OK),
|
||||
API_DEF_CONST_INT(WEECHAT_RC_OK_EAT),
|
||||
API_DEF_CONST_INT(WEECHAT_RC_ERROR),
|
||||
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_READ_OK),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_READ_MEMORY_ERROR),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_READ_FILE_NOT_FOUND),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_WRITE_OK),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_WRITE_ERROR),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_WRITE_MEMORY_ERROR),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_OPTION_SET_OK_CHANGED),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_OPTION_SET_OK_SAME_VALUE),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_OPTION_SET_ERROR),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_OPTION_SET_OPTION_NOT_FOUND),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_OPTION_UNSET_OK_NO_RESET),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_OPTION_UNSET_OK_RESET),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_OPTION_UNSET_OK_REMOVED),
|
||||
API_DEF_CONST_INT(WEECHAT_CONFIG_OPTION_UNSET_ERROR),
|
||||
|
||||
API_DEF_CONST_STR(WEECHAT_LIST_POS_SORT),
|
||||
API_DEF_CONST_STR(WEECHAT_LIST_POS_BEGINNING),
|
||||
API_DEF_CONST_STR(WEECHAT_LIST_POS_END),
|
||||
|
||||
API_DEF_CONST_STR(WEECHAT_HOTLIST_LOW),
|
||||
API_DEF_CONST_STR(WEECHAT_HOTLIST_MESSAGE),
|
||||
API_DEF_CONST_STR(WEECHAT_HOTLIST_PRIVATE),
|
||||
API_DEF_CONST_STR(WEECHAT_HOTLIST_HIGHLIGHT),
|
||||
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_PROCESS_RUNNING),
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_PROCESS_ERROR),
|
||||
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_CONNECT_OK),
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_CONNECT_ADDRESS_NOT_FOUND),
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_CONNECT_IP_ADDRESS_NOT_FOUND),
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_CONNECT_CONNECTION_REFUSED),
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_CONNECT_PROXY_ERROR),
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_CONNECT_LOCAL_HOSTNAME_ERROR),
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_CONNECT_GNUTLS_INIT_ERROR),
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_CONNECT_GNUTLS_HANDSHAKE_ERROR),
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_CONNECT_MEMORY_ERROR),
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_CONNECT_TIMEOUT),
|
||||
API_DEF_CONST_INT(WEECHAT_HOOK_CONNECT_SOCKET_ERROR),
|
||||
|
||||
API_DEF_CONST_STR(WEECHAT_HOOK_SIGNAL_STRING),
|
||||
API_DEF_CONST_STR(WEECHAT_HOOK_SIGNAL_INT),
|
||||
API_DEF_CONST_STR(WEECHAT_HOOK_SIGNAL_POINTER),
|
||||
|
||||
{ NULL, 0, NULL }
|
||||
{ NULL, NULL },
|
||||
};
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#define WEECHAT_PLUGIN_LUA_API_H
|
||||
|
||||
extern struct luaL_Reg weechat_lua_api_funcs[];
|
||||
extern struct t_lua_const weechat_lua_api_consts[];
|
||||
|
||||
extern int weechat_lua_api_buffer_input_data_cb (const void *pointer,
|
||||
void *data,
|
||||
|
||||
@@ -422,25 +422,6 @@ weechat_lua_exec (struct t_plugin_script *script, int ret_type,
|
||||
return ret_value;
|
||||
}
|
||||
|
||||
/*
|
||||
* Adds a constant.
|
||||
*/
|
||||
|
||||
void
|
||||
weechat_lua_add_constant (lua_State *L, struct t_lua_const *ptr_const)
|
||||
{
|
||||
lua_pushstring (L, ptr_const->name);
|
||||
if (ptr_const->str_value)
|
||||
lua_pushstring (L, ptr_const->str_value);
|
||||
else
|
||||
#if LUA_VERSION_NUM >= 503
|
||||
lua_pushinteger (L, ptr_const->int_value);
|
||||
#else
|
||||
lua_pushnumber (L, ptr_const->int_value);
|
||||
#endif /* LUA_VERSION_NUM >= 503 */
|
||||
lua_settable (L, -3);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called when a constant is modified.
|
||||
*/
|
||||
@@ -459,8 +440,7 @@ weechat_lua_newindex (lua_State *L)
|
||||
|
||||
void
|
||||
weechat_lua_register_lib (lua_State *L, const char *libname,
|
||||
const luaL_Reg *lua_api_funcs,
|
||||
struct t_lua_const lua_api_consts[])
|
||||
const luaL_Reg *lua_api_funcs)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -482,10 +462,21 @@ weechat_lua_register_lib (lua_State *L, const char *libname,
|
||||
lua_pushliteral (L, "__index");
|
||||
lua_newtable (L);
|
||||
|
||||
for (i= 0; lua_api_consts[i].name; i++)
|
||||
/* define constants */
|
||||
for (i = 0; weechat_script_constants[i].name; i++)
|
||||
{
|
||||
weechat_lua_add_constant (L, &lua_api_consts[i]);
|
||||
lua_pushstring (L, weechat_script_constants[i].name);
|
||||
if (weechat_script_constants[i].value_string)
|
||||
lua_pushstring (L, weechat_script_constants[i].value_string);
|
||||
else
|
||||
#if LUA_VERSION_NUM >= 503
|
||||
lua_pushinteger (L, weechat_script_constants[i].value_integer);
|
||||
#else
|
||||
lua_pushnumber (L, weechat_script_constants[i].value_integer);
|
||||
#endif /* LUA_VERSION_NUM >= 503 */
|
||||
lua_settable (L, -3);
|
||||
}
|
||||
|
||||
lua_settable (L, -3);
|
||||
|
||||
lua_pushliteral (L, "__newindex");
|
||||
@@ -572,8 +563,7 @@ weechat_lua_load (const char *filename, const char *code)
|
||||
#endif /* LUA_VERSION_NUM */
|
||||
|
||||
weechat_lua_register_lib (lua_current_interpreter, "weechat",
|
||||
weechat_lua_api_funcs,
|
||||
weechat_lua_api_consts);
|
||||
weechat_lua_api_funcs);
|
||||
|
||||
#ifdef LUA_VERSION_NUM
|
||||
if (luaL_dostring (lua_current_interpreter, lua_redirect_output) != 0)
|
||||
|
||||
@@ -27,13 +27,6 @@
|
||||
|
||||
#define LUA_CURRENT_SCRIPT_NAME ((lua_current_script) ? lua_current_script->name : "-")
|
||||
|
||||
struct t_lua_const
|
||||
{
|
||||
char *name;
|
||||
int int_value;
|
||||
char *str_value;
|
||||
};
|
||||
|
||||
extern struct t_weechat_plugin *weechat_lua_plugin;
|
||||
|
||||
extern struct t_plugin_script_data lua_data;
|
||||
@@ -59,7 +52,6 @@ extern void *weechat_lua_exec (struct t_plugin_script *script,
|
||||
const char *function,
|
||||
const char *format, void **argv);
|
||||
extern void weechat_lua_register_lib (lua_State *L, const char *libname,
|
||||
const luaL_Reg *lua_api_funcs,
|
||||
struct t_lua_const lua_api_consts[]);
|
||||
const luaL_Reg *lua_api_funcs);
|
||||
|
||||
#endif /* WEECHAT_PLUGIN_LUA_H */
|
||||
|
||||
Reference in New Issue
Block a user