summaryrefslogtreecommitdiffstats
path: root/lua/lua-plugin.c
diff options
context:
space:
mode:
authorPeng Wu <alexepico@gmail.com>2010-04-16 14:10:04 +0800
committerPeng Wu <alexepico@gmail.com>2010-05-19 10:09:32 +0800
commit560cdb15c6c238252d49c362a631de35d05713c2 (patch)
treed2d567ed439ef27219b8fff932e26f60219a5bb6 /lua/lua-plugin.c
parent7cf2505a5790195814e05e4a26f40fe8319d5e67 (diff)
downloadibus-libpinyin-560cdb15c6c238252d49c362a631de35d05713c2.tar.gz
ibus-libpinyin-560cdb15c6c238252d49c362a631de35d05713c2.tar.xz
ibus-libpinyin-560cdb15c6c238252d49c362a631de35d05713c2.zip
write ibus_engine_plugin_load_lua_script.
Diffstat (limited to 'lua/lua-plugin.c')
-rw-r--r--lua/lua-plugin.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/lua/lua-plugin.c b/lua/lua-plugin.c
index 65ab9e4..467070c 100644
--- a/lua/lua-plugin.c
+++ b/lua/lua-plugin.c
@@ -109,6 +109,29 @@ IBusEnginePlugin * ibus_engine_plugin_new(){
return plugin;
}
+static void l_message (const char *pname, const char *msg) {
+ if (pname) fprintf(stderr, "%s: ", pname);
+ fprintf(stderr, "%s\n", msg);
+ fflush(stderr);
+}
+
+static int report (lua_State *L, int status) {
+ if (status && !lua_isnil(L, -1)) {
+ const char *msg = lua_tostring(L, -1);
+ if (msg == NULL) msg = "(error object is not a string)";
+ l_message(NULL, msg);
+ lua_pop(L, 1);
+ }
+ return status;
+}
+
+int ibus_engine_plugin_load_lua_script(IBusEnginePlugin * plugin, const char * filename){
+ IBusEnginePluginPrivate * priv = IBUS_ENGINE_PLUGIN_GET_PRIVATE(plugin);
+ int status = luaL_dofile(priv->L, filename);
+ return report(priv->L, status);
+}
+
+
static gint compare_command(gconstpointer a, gconstpointer b){
lua_command_t * ca = (lua_command_t *) a;
lua_command_t * cb = (lua_command_t *) b;
@@ -126,6 +149,7 @@ gboolean ibus_engine_plugin_add_command(IBusEnginePlugin * plugin, lua_command_t
lua_command_clone(command, &new_command);
g_array_append_val(priv->lua_commands, new_command);
+ /* Note: need to improve speed here? */
g_array_sort(priv->lua_commands, compare_command);
return TRUE;