summaryrefslogtreecommitdiffstats
path: root/lua/lua-plugin-init.c
diff options
context:
space:
mode:
authorPeng Wu <epico@dhcp-65-116.nay.redhat.com>2010-03-25 15:37:32 +0800
committerPeng Wu <alexepico@gmail.com>2010-05-19 10:09:31 +0800
commit0bcdae428741bd8e12692df0cb3f93efb76fdd8e (patch)
tree4d491f3f97c568fe159e1664577a2c6bd145d723 /lua/lua-plugin-init.c
parent43b0f21525db609c86800064f176f95cf3e49be1 (diff)
downloadibus-libpinyin-0bcdae428741bd8e12692df0cb3f93efb76fdd8e.tar.gz
ibus-libpinyin-0bcdae428741bd8e12692df0cb3f93efb76fdd8e.tar.xz
ibus-libpinyin-0bcdae428741bd8e12692df0cb3f93efb76fdd8e.zip
add split_string function.
Diffstat (limited to 'lua/lua-plugin-init.c')
-rw-r--r--lua/lua-plugin-init.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/lua/lua-plugin-init.c b/lua/lua-plugin-init.c
index 36647d5..cbd6198 100644
--- a/lua/lua-plugin-init.c
+++ b/lua/lua-plugin-init.c
@@ -58,7 +58,7 @@ static int ime_get_version(lua_State* L){
static int ime_join_string(lua_State* L){
luaL_Buffer buf;
- size_t arr_len; size_t i;
+ size_t vec_len; size_t i;
const char * sep;
const char * str;
@@ -68,8 +68,8 @@ static int ime_join_string(lua_State* L){
sep = lua_tolstring(L, 2, NULL);
luaL_buffinit(L, &buf);
- arr_len = lua_objlen(L, 1);
- for ( i = 1; i < arr_len; ++i){
+ vec_len = lua_objlen(L, 1);
+ for ( i = 1; i < vec_len; ++i){
lua_pushinteger(L, i);
lua_gettable(L, 1);
str = lua_tolstring(L, 3, NULL);
@@ -90,7 +90,24 @@ static int ime_join_string(lua_State* L){
}
static int ime_split_string(lua_State * L){
-
+ gchar ** str_vec;
+ guint str_vec_len = 0;
+ const char * sep;
+ const char * str = lua_tolstring(L, 1, NULL);
+ sep = lua_tolstring(L, 2, NULL);
+ str_vec == g_strsplit(str, sep, 0);
+
+ str_vec_len = g_strv_length(str_vec);
+ lua_createtable(L, str_vec_len, 0);
+ for ( int i = 0; i < str_vec_len; ++i){
+ lua_pushinteger(L, i + 1);
+ lua_pushstring(L, str_vec[i]);
+ lua_settable(L, 3);
+ }
+
+ g_strfreev(str_vec);
+ lua_remove(L, 2); /* remove sep from stack */
+ lua_remove(L, 1); /* remove str from stack */
return 1;
}
@@ -121,7 +138,7 @@ static int ime_push_string(lua_State* L, const char * s,
}
lua_pushlstring(L, s + start, end -start);
lua_remove(L, 1);
- return 1;
+ return 1;
}
static int ime_trim_string_left(lua_State* L){