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 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
|
/* vim:set et ts=4 sts=4:
*
* ibus-libpinyin - Intelligent Pinyin engine based on libpinyin for IBus
*
* Copyright (c) 2010 Peng Wu <alexepico@gmail.com>
*
* 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 3 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, see <http://www.gnu.org/licenses/>.
*/
#ifndef LUA_PLUGIN_H
#define LUA_PLUGIN_H
#include <glib.h>
G_BEGIN_DECLS
#include <lua.h>
#include <lualib.h>
#include <lauxlib.h>
#include <glib-object.h>
#define LUA_IMELIBNAME "ime"
LUALIB_API int (luaopen_ime) (lua_State * L);
LUALIB_API int (luaopen_myos) (lua_State * L);
#define LUA_IMELIB_CONTEXT "__context"
typedef struct _lua_command_t{
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 _lua_command_candidate_t{
const char * suggest;
const char * help;
const char * content;
} lua_command_candidate_t;
typedef struct _lua_trigger_t{
const char * lua_function_name;
const char * description;
gchar **input_trigger_strings;
gchar **candidate_trigger_strings;
} lua_trigger_t;
typedef struct _lua_converter_t{
const char * lua_function_name;
const char * description;
} lua_converter_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);
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 information of type lua_command_t without copies.
*/
const GArray * ibus_engine_plugin_get_available_commands(IBusEnginePlugin * plugin);
/**
* add a lua_trigger_t to plugin.
*/
gboolean ibus_engine_plugin_add_trigger(IBusEnginePlugin * plugin, lua_trigger_t * trigger);
/**
* retrieve all available lua plugin triggers.
* return array of trigger information of type lua_trigger_t without copies.
*/
const GArray * ibus_engine_plugin_get_available_triggers(IBusEnginePlugin * plugin);
/**
* retrieve the lua function name of the matched input for lua_trigger_t.
*/
gboolean ibus_engine_plugin_match_input(IBusEnginePlugin * plugin, const char * input, const char ** lua_function_name);
/**
* retrieve the lua function name of the matched candidate for lua_trigger_t.
*/
gboolean ibus_engine_plugin_match_candidate(IBusEnginePlugin * plugin, const char * candidate, const char ** lua_function_name);
/**
* add a lua_converter_t to plugin.
*/
gboolean ibus_engine_plugin_add_converter(IBusEnginePlugin * plugin, lua_converter_t * converter);
/**
* retrieve all available lua plugin converters.
* return array of converter information of type lua_converter_t without copies.
*/
const GArray * ibus_engine_plugin_get_available_converters(IBusEnginePlugin * plugin);
/**
* set the converter with the lua function name.
*/
gboolean ibus_engine_plugin_set_converter(IBusEnginePlugin * plugin, const char * lua_function_name);
/**
* get the converter with the lua function name.
*/
const char * ibus_engine_plugin_get_converter(IBusEnginePlugin * plugin);
/**
* Lookup a special command in ime lua extension.
* command must be an 2-char long string.
* return the matched command.
*/
const lua_command_t * ibus_engine_plugin_lookup_command(IBusEnginePlugin * plugin, const char * command_name);
/**
* retval int: returns the number of results,
* only support string or string array.
* the consequence call of ibus_engine_plugin_get_retval* must follow this call immediately.
*/
int ibus_engine_plugin_call(IBusEnginePlugin * plugin, const char * lua_function_name, const char * argument /*optional, maybe NULL.*/);
/**
* retrieve the number of string values.
*/
gint ibus_engine_plugin_get_n_result(IBusEnginePlugin * plugin);
/**
* retrieve the nth string value. (value has been copied.)
*/
gchar * ibus_engine_plugin_get_nth_result(IBusEnginePlugin * plugin, gint index);
/**
* clear the string values from the stack.
*/
void ibus_engine_plugin_clear_results(IBusEnginePlugin * plugin);
/**
* retrieve the retval string value. (value has been copied.)
*/
const lua_command_candidate_t * ibus_engine_plugin_get_retval(IBusEnginePlugin * plugin);
/**
* retrieve the array of lua_command_candidate_t values. (string values have been copied.)
*/
GArray * ibus_engine_plugin_get_retvals(IBusEnginePlugin * plugin);
void ibus_engine_plugin_free_candidate(lua_command_candidate_t * candidate);
G_END_DECLS
#endif
|