add some rudimentary lua support, by having a simple interactive console, and providing access to irc_client_quit
#ifndef CONSOLE_H
#define CONSOLE_H
/**
* @file
*
* An interactive line-based console interface for runtime configuration.
*
* This uses the GNU readline library to implement the console, and hence, the console uses global state, and there
* can only be one console per process - not that it should matter, since the console requires a tty.
*
* XXX: the log module interferes with this
*/
#include "error.h"
#include <event2/event.h>
#include <stdbool.h>
/**
* Callbacks for event-based actions
*/
struct console_callbacks {
/**
* A line was read from the console.
*
* XXX: currently, line might be NULL on EOF, but this is probably a second callback
*/
void (*on_line) (const char *line, void *arg);
};
/**
* Configuration info for console operation
*/
struct console_config {
/** The prompt to use when displaying lines */
const char *prompt;
};
/**
* The console state.
*
* You may replace the callbacks/cb_arg field with a new one at any time, using console_set_callbacks().
*/
struct console {
/** The input event */
struct event *ev;
/** The callback functions */
const struct console_callbacks *callbacks;
/** The callback context argument */
void *cb_arg;
/** Already initialized? */
bool initialized;
};
/**
* Initialize the console, setting up the TTY and input handler.
*
* @param console_ptr returned new console struct
* @param ev_base the libevent base to use
* @param config configuration things for the console
* @param callbacks optional callbacks, can be updated later
* @param cb_arg option callback argument, can be updated later
* @param err returned error info
*/
err_t console_init (struct console **console_ptr, struct event_base *ev_base, const struct console_config *config,
const struct console_callbacks *callbacks, void *cb_arg, struct error_info *err);
/**
* Replace the current callbacks with the given new ones.
*/
void console_set_callbacks (struct console *console, const struct console_callbacks *callbacks, void *cb_arg);
/**
* Deinitialize the console, restoring the TTY and releasing resources
*/
void console_destroy (struct console *console);
#endif /* CONSOLE_H */