GArray * lua_commands; /* Array of lua_command_t. */
};
-
G_DEFINE_TYPE (IBusEnginePlugin, ibus_engine_plugin, G_TYPE_OBJECT);
-static void
-ibus_engine_plugin_dispose (GObject *gobject)
-{
- IBusEnginePlugin *self = IBUS_ENGINE_PLUGIN (gobject);
-
- /* do some cleaning here. */
-
- /* Chain up to the parent class */
- G_OBJECT_CLASS (ibus_engine_plugin_parent_class)->dispose(gobject);
-}
-
-static void
-ibus_engine_plugin_finalize (GObject *gobject)
-{
- IBusEnginePlugin *self = IBUS_ENGINE_PLUGIN (gobject);
-
- /* Chain up to the parent class */
- G_OBJECT_CLASS (ibus_engine_plugin_parent_class)->dispose(gobject);
-}
-
-static void
-ibus_engine_plugin_class_init (IBusEnginePluginClass *klass)
-{
- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->dispose = ibus_engine_plugin_dispose;
- gobject_class->finalize = ibus_engine_plugin_finalize;
-
- g_type_class_add_private (klass, sizeof (IBusEnginePluginPrivate));
-}
-
static int
lua_plugin_init(IBusEnginePluginPrivate * plugin){
g_assert(NULL == plugin->L);
/* enable libs in sandbox */
lua_plugin_openlibs(plugin->L);
- if ( NULL == plugin->lua_commands )
- plugin->lua_commands = g_array_new(TRUE, TRUE, sizeof(lua_command_t));
-
+ g_assert ( NULL == plugin->lua_commands );
+ plugin->lua_commands = g_array_new(TRUE, TRUE, sizeof(lua_command_t));
return 0;
}
}
lua_close(plugin->L);
+ plugin->L = NULL;
return 0;
}
static void
+ibus_engine_plugin_dispose (GObject *gobject)
+{
+ IBusEnginePlugin *self = IBUS_ENGINE_PLUGIN (gobject);
+
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS (ibus_engine_plugin_parent_class)->dispose(gobject);
+}
+
+static void
+ibus_engine_plugin_finalize (GObject *gobject)
+{
+ IBusEnginePlugin *self = IBUS_ENGINE_PLUGIN (gobject);
+
+ /* do some cleaning here. */
+ lua_plugin_fini(self->priv);
+
+ /* Chain up to the parent class */
+ G_OBJECT_CLASS (ibus_engine_plugin_parent_class)->dispose(gobject);
+}
+
+static void
+ibus_engine_plugin_class_init (IBusEnginePluginClass *klass)
+{
+ GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
+
+ gobject_class->dispose = ibus_engine_plugin_dispose;
+ gobject_class->finalize = ibus_engine_plugin_finalize;
+
+ g_type_class_add_private (klass, sizeof (IBusEnginePluginPrivate));
+}
+
+static void
ibus_engine_plugin_init (IBusEnginePlugin *self)
{
IBusEnginePluginPrivate *priv;
self->priv = priv = IBUS_ENGINE_PLUGIN_GET_PRIVATE (self);
memset(priv, 0, sizeof(IBusEnginePluginPrivate));
+
+ lua_plugin_init(priv);
+}
+
+IBusEnginePlugin * ibus_engine_plugin_new(){
+ IBusEnginePlugin * plugin;
+
+ plugin = (IBusEnginePlugin *) g_object_new (IBUS_TYPE_ENGINE_PLUGIN,
+ NULL);
+
+ return plugin;
+}
+
+/* will drop this function soon. */
+lua_State * ibus_engine_plugin_get_lua_State(IBusEnginePlugin * plugin){
+ return plugin->priv->L;
}
GType ibus_engine_plugin_get_type(void);
+IBusEnginePlugin * ibus_engine_plugin_new();
+
/**
* retrieve all available lua plugin commands.
* return array of command informations of type lua_command_t.
*/
-GArray * lua_plugin_ime_get_available_commands(IBusEnginePlugin * plugin);
+GArray * ibus_engine_plugin_ime_get_available_commands(IBusEnginePlugin * plugin);
/**
* retval int: only support string or string array.
*/
-int lua_plugin_ime_call(IBusEnginePlugin * plugin, const lua_command_t * command, const char * argument /*optional, maybe NULL.*/);
+int ibus_engine_plugin_ime_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 * lua_plugin_ime_get_retval(IBusEnginePlugin * plugin);
+const char * ibus_engine_plugin_ime_get_retval(IBusEnginePlugin * plugin);
/**
* retrieve the array of string values. (string values have been copied.)
*/
-GArray * lua_plugin_ime_get_retvals(IBusEnginePlugin * plugin);
+GArray * ibus_engine_plugin_ime_get_retvals(IBusEnginePlugin * plugin);
+
+/*< private >*/
+/* will drop this function soon. */
+lua_State * ibus_engine_plugin_get_lua_State(IBusEnginePlugin * plugin);
#endif
int main(int argc, char * argv[]){
printf("starting test...\n");
+ g_type_init();
+
+ IBusEnginePlugin * plugin;
+ plugin = ibus_engine_plugin_new();
- IBusEnginePluginPrivate priv;
-
- priv.L = NULL;
- priv.lua_commands = NULL;
-
- lua_plugin_init(&priv);
-
- run_test(priv.L, "test.lua");
+ lua_State * L = ibus_engine_plugin_get_lua_State(plugin);
+ run_test(L, "test.lua");
- lua_plugin_fini(&priv);
+ g_object_unref(plugin);
return 0;
}