summaryrefslogtreecommitdiffstats
path: root/lua/lua-plugin.h
blob: 8e6e056ded0b0c90aa2d1cf7ed87363e14ea93da (plain)
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
#ifndef LUA_PLUGIN_H
#define LUA_PLUGIN_H

#include <glib-object.h>

#define LUA_IMELIBNAME   "ime"
LUALIB_API int (luaopen_ime) (lua_State * L);
#define LUA_IMELIB_CONTEXT "__context"

typedef struct{
  const char * command_name;
  const char * lua_function_name;
  const char * description;
  const char * leading; /* optional, default "digit". */
  const char * help; /* optional. */
} lua_command_t;

typedef struct{
  const char * lua_function_name;
  const char * description;
  /*< private, skip it, and register it into Special Table directly with * wildcard. >*/
  /*
   * list of input_trigger_strings;
   * list of candidate_trigger_strings;
   */
} lua_trigger_t;

/*
 * Type macros.
 */

#define IBUS_TYPE_ENGINE_PLUGIN                 (ibus_engine_plugin_get_type ())
#define IBUS_ENGINE_PLUGIN(obj)                 (G_TYPE_CHECK_INSTANCE_CAST ((obj), IBUS_TYPE_ENGINE_PLUGIN, IBusEnginePlugin))
#define IBUS_IS_ENGINE_PLUGIN(obj)              (G_TYPE_CHECK_INSTANCE_TYPE ((obj), IBUS_TYPE_ENGINE_PLUGIN))
#define IBUS_ENGINE_PLUGIN_CLASS(klass)         (G_TYPE_CHECK_CLASS_CAST ((klass), IBUS_TYPE_ENGINE_PLUGIN, IBusEnginePluginClass))
#define IBUS_IS_ENGINE_PLUGIN_CLASS(klass)      (G_TYPE_CHECK_CLASS ((klass), IBUS_TYPE_ENGINE_PLUGIN))
#define IBUS_ENGINE_PLUGIN_GET_CLASS(obj)       (G_TYPE_INSTANCE_GET_CLASS ((obj), IBUS_TYPE_ENGINE_PLUGIN, IBusEnginePluginClass))

typedef struct _IBusEnginePlugin IBusEnginePlugin;
typedef struct _IBusEnginePluginClass IBusEnginePluginClass;
typedef struct _IBusEnginePluginPrivate IBusEnginePluginPrivate;

void lua_plugin_openlibs (lua_State *L);
void lua_plugin_store_plugin(lua_State * L, IBusEnginePlugin * plugin);
IBusEnginePlugin * lua_plugin_retrieve_plugin(lua_State * L);

struct _IBusEnginePlugin
{
  GObject parent_instance;

  /*< private >*/
  IBusEnginePluginPrivate *priv;  
};

struct _IBusEnginePluginClass
{
  GObjectClass parent_class;
};

GType ibus_engine_plugin_get_type(void);

/**
 * create a new ibus engine plugin.
 */
IBusEnginePlugin * ibus_engine_plugin_new();

/**
 * load a new lua script for ibus engine plugin.
 */
int ibus_engine_plugin_load_lua_script(IBusEnginePlugin * plugin, const char * filename);

/**
 * add a lua_command_t to plugin.
 */
gboolean ibus_engine_plugin_add_command(IBusEnginePlugin * plugin, lua_command_t * command);

/**
 * retrieve all available lua plugin commands.
 * return array of command informations of type lua_command_t without copies.
 */
const GArray * ibus_engine_plugin_get_available_commands(IBusEnginePlugin * plugin);

/**
 * Lookup a special command in ime lua extension.
 * command must be an 2-char long string.
 * return the matched command.
 */
lua_command_t * ibus_engine_plugin_lookup_command(IBusEnginePlugin * plugin, const char * command);

/**
 * retval int: returns the number of results,
 *              only support string or string array.
 */
int ibus_engine_plugin_call(IBusEnginePlugin * plugin, const lua_command_t * command, const char * argument /*optional, maybe NULL.*/);

/**
 * retrieve the retval string value. (value has been copied.)
 */
const char * ibus_engine_plugin_get_retval(IBusEnginePlugin * plugin);
/**
 * retrieve the array of string values. (string values have been copied.)
 */
GArray * ibus_engine_plugin_get_retvals(IBusEnginePlugin * plugin);


/*< private >*/
/* will drop this function soon. */
lua_State * ibus_engine_plugin_get_lua_State(IBusEnginePlugin * plugin);
#endif