summaryrefslogtreecommitdiffstats
path: root/lua/lua-plugin-init.c
diff options
context:
space:
mode:
authorPeng Wu <epico@dhcp-65-116.nay.redhat.com>2010-03-24 14:43:47 +0800
committerPeng Wu <alexepico@gmail.com>2010-05-19 10:09:31 +0800
commit43b0f21525db609c86800064f176f95cf3e49be1 (patch)
tree51759107cf4433eef781b084c7265a6cea8cd72a /lua/lua-plugin-init.c
parenta1a3c7e061376b6426c12f29b4131785a27e943b (diff)
downloadibus-libpinyin-43b0f21525db609c86800064f176f95cf3e49be1.tar.gz
ibus-libpinyin-43b0f21525db609c86800064f176f95cf3e49be1.tar.xz
ibus-libpinyin-43b0f21525db609c86800064f176f95cf3e49be1.zip
the initial ime_join_string implement and add lua_pop for trim_string functions.
Diffstat (limited to 'lua/lua-plugin-init.c')
-rw-r--r--lua/lua-plugin-init.c43
1 files changed, 41 insertions, 2 deletions
diff --git a/lua/lua-plugin-init.c b/lua/lua-plugin-init.c
index 66f50e4..36647d5 100644
--- a/lua/lua-plugin-init.c
+++ b/lua/lua-plugin-init.c
@@ -56,6 +56,44 @@ static int ime_get_version(lua_State* L){
return 1;
}
+static int ime_join_string(lua_State* L){
+ luaL_Buffer buf;
+ size_t arr_len; size_t i;
+ const char * sep;
+ const char * str;
+
+ if ( !lua_istable(L, 1) )
+ return 0;
+
+ sep = lua_tolstring(L, 2, NULL);
+
+ luaL_buffinit(L, &buf);
+ arr_len = lua_objlen(L, 1);
+ for ( i = 1; i < arr_len; ++i){
+ lua_pushinteger(L, i);
+ lua_gettable(L, 1);
+ str = lua_tolstring(L, 3, NULL);
+ luaL_addstring(&buf, str);
+ lua_pop(L, 1);
+ luaL_addstring(&buf, sep);
+ }
+
+ /* add tail of string list */
+ lua_pushinteger(L, i);
+ lua_gettable(L, 1);
+ str = lua_tolstring(L, 3, NULL);
+ luaL_addstring(&buf, str);
+ lua_pop(L, 1);
+ luaL_pushresult(&buf);
+
+ return 1;
+}
+
+static int ime_split_string(lua_State * L){
+
+ return 1;
+}
+
static gboolean ime_is_white_space(const char c){
static const char * const white_space = " \t\n\r\v\f";
int i;
@@ -82,6 +120,7 @@ static int ime_push_string(lua_State* L, const char * s,
return 1;
}
lua_pushlstring(L, s + start, end -start);
+ lua_remove(L, 1);
return 1;
}
@@ -131,14 +170,14 @@ static int ime_trim_string(lua_State* L){
static const luaL_Reg imelib[] = {
{"get_last_commit", ime_get_last_commit},
{"get_version", ime_get_version},
+ {"join_string", ime_join_string},
#if 0
- {"join_string"}, ime_join_string},
{"parse_mapping", ime_parse_mapping},
{"register_command", ime_register_command},
/* Note: the register_trigger function is dropped for ibus-pinyin. */
{"register_trigger", ime_register_trigger},
- {"split_string", ime_split_string},
#endif
+ {"split_string", ime_split_string},
{"trim_string_left", ime_trim_string_left},
{"trim_string_right", ime_trim_string_right},
{"trim_string", ime_trim_string},