Exemplo n.º 1
0
static
XS (XS_Xchat_register)
{
	char *name, *version, *desc, *filename;
	void *gui_entry;
	dXSARGS;
	if (items != 4) {
		xchat_printf (ph,
						  "Usage: Xchat::Internal::register(scriptname, version, desc, filename)");
	} else {
		name = SvPV_nolen (ST (0));
		version = SvPV_nolen (ST (1));
		desc = SvPV_nolen (ST (2));
		filename = SvPV_nolen (ST (3));

		gui_entry = xchat_plugingui_add (ph, filename, name,
													desc, version, NULL);

		XSRETURN_IV (PTR2IV (gui_entry));

	}
}
Exemplo n.º 2
0
int xchat_plugin_init(xchat_plugin *plugin_handle,
                      char **plugin_name,
                      char **plugin_desc,
                      char **plugin_version,
                      char *arg)
{
	struct lxc_States	*state;	
	lua_State *L;
	const char *xdir;
	const char *name, *desc, *vers;
	char *xsubdir;
   /* we need to save this for use with any xchat_* functions */
   ph = plugin_handle;

   /* tell xchat our info */
   *plugin_name = LXC_NAME;
   *plugin_desc = LXC_DESC;
   *plugin_version = LXC_VERSION;

	xchat_hook_command(ph, "LOAD", XCHAT_PRI_NORM, lxc_cb_load, NULL, NULL);
	xchat_hook_command(ph, "UNLOAD", XCHAT_PRI_NORM, lxc_cb_unload, NULL, NULL);
	xchat_hook_command(ph, "LUA", XCHAT_PRI_NORM, lxc_cb_lua, "Usage: LUA <code>, executes <code> in a new lua state", NULL);

	xdir = xchat_get_info (ph, "xchatdirfs");
	xsubdir = g_build_filename (xdir, "addons", NULL);
	lxc_autoload_from_path (xsubdir);
	g_free (xsubdir);

	/* put this here, otherwise it's only displayed when a script is autoloaded upon start */
	xchat_printf(ph, "Lua interface loaded");

	if (!lxc_states) /* no scripts loaded */
		return 1;
	
	state = lxc_states;
	while (state) {
		L = state->state;
		lua_pushstring(L, "xchat_register");
		lua_gettable(L, LUA_GLOBALSINDEX);
		if (lua_pcall(L, 0, 3, 0)) {
			xchat_printf(ph, "Lua plugin: error registering script %s", 	
								lua_tostring(L, -1));
			lua_pop(L, 1);
			state = state->next;
			continue;
		}

		name = lua_tostring(L, -3);
		desc = lua_tostring(L, -2);
		vers = lua_tostring(L, -1);
		lua_pop(L, 4); /* func + 3 ret value */
		state->gui = xchat_plugingui_add(ph, state->file, name, desc, vers, NULL);

		lua_pushstring(L, "xchat_init");
		lua_gettable(L, LUA_GLOBALSINDEX);
		if (lua_type(L, -1) != LUA_TFUNCTION) 
			lua_pop(L, 1);
		else {
			if (lua_pcall(L, 0, 0, 0)) {
				xchat_printf(ph, "Lua plugin: error calling xchat_init() %s", 	
								lua_tostring(L, -1));
				lua_pop(L, 1);
			}
		}
		state = state->next;
	}
	return 1; 
}
Exemplo n.º 3
0
static int lxc_cb_load(char *word[], char *word_eol[], void *userdata)
{
	int len;
	struct lxc_States *state;
	lua_State *L;
	const char *name, *desc, *vers;
	const char *xdir = "";
	char  *buf;
	char file[PATH_MAX+1];
	struct stat *st;

	if (word_eol[2][0] == 0)
		return XCHAT_EAT_NONE;
	
	buf = malloc(PATH_MAX + 1);
	if (!buf) {
		xchat_printf(ph, "malloc() failed: %s\n", strerror(errno));
		return XCHAT_EAT_NONE;
	}

	st = malloc(sizeof(struct stat));
	if (!st) {
		xchat_printf(ph, "malloc() failed: %s\n", strerror(errno));
		free(buf);
		return XCHAT_EAT_NONE;
	}

 	len = strlen(word[2]);
	if (len > 4 && strcasecmp (".lua", word[2] + len - 4) == 0) {
#ifdef WIN32
		if (strrchr(word[2], '\\') != NULL)
#else
		if (strrchr(word[2], '/') != NULL)
#endif
			strncpy(file, word[2], PATH_MAX);
		else {
			if (stat(word[2], st) == 0)
			{
				xdir = getcwd (buf, PATH_MAX);
				snprintf (file, PATH_MAX, "%s/%s", xdir, word[2]);
			}
			else
			{
				xdir = xchat_get_info (ph, "xchatdirfs");
				snprintf (file, PATH_MAX, "%s/addons/%s", xdir, word[2]);
			}
		}

		if (lxc_load_file((const char *)file) == 0) {
			free(st);
			free(buf);
			return XCHAT_EAT_ALL;
		}

		state = lxc_states;
		while (state) {
			if (state->next == NULL) {
				L = state->state;

				lua_pushstring(L, "xchat_register");
				lua_gettable(L, LUA_GLOBALSINDEX);
				if (lua_pcall(L, 0, 3, 0)) {
					xchat_printf(ph, "Lua plugin: error registering script %s", 	
								lua_tostring(L, -1));
					lua_pop(L, 1);
					free(st);
					free(buf);
					return XCHAT_EAT_ALL;
				}

				name = lua_tostring(L, -3);
				desc = lua_tostring(L, -2);
				vers = lua_tostring(L, -1);
				lua_pop(L, 4); /* func + 3 ret value */
				state->gui = xchat_plugingui_add(ph, state->file, 
																 name, desc, vers, NULL
															);

				lua_pushstring(L, "xchat_init");
				lua_gettable(L, LUA_GLOBALSINDEX);
				if (lua_type(L, -1) != LUA_TFUNCTION) 
					lua_pop(L, 1);
				else {
					if (lua_pcall(L, 0, 0, 0)) {
						xchat_printf(ph, 
									"Lua plugin: error calling xchat_init() %s", 	
									lua_tostring(L, -1));
						lua_pop(L, 1);
					}
				}
				free(st);
				free(buf);
				return XCHAT_EAT_ALL;
			}
			state = state->next;
		}
	}
	free(st);
	free(buf);
	return XCHAT_EAT_NONE;
}