diff options
author | Peng Wu <alexepico@gmail.com> | 2012-07-16 13:43:13 +0800 |
---|---|---|
committer | Peng Wu <alexepico@gmail.com> | 2012-07-16 13:43:13 +0800 |
commit | dcdf9813c13856403142da5044ff6b51e2e2737d (patch) | |
tree | 18a86708033946865f43ea3fdbdb9ee46fef15d7 /lua | |
parent | 6a422d70a223a059393432ff45f7c1c3b1b44ae0 (diff) | |
download | ibus-libpinyin-dcdf9813c13856403142da5044ff6b51e2e2737d.tar.gz ibus-libpinyin-dcdf9813c13856403142da5044ff6b51e2e2737d.tar.xz ibus-libpinyin-dcdf9813c13856403142da5044ff6b51e2e2737d.zip |
write int_to_hex_string
Diffstat (limited to 'lua')
-rw-r--r-- | lua/lua-plugin-init.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lua/lua-plugin-init.c b/lua/lua-plugin-init.c index d45916a..db04514 100644 --- a/lua/lua-plugin-init.c +++ b/lua/lua-plugin-init.c @@ -79,6 +79,23 @@ static int ime_get_version(lua_State* L){ return 1; } +static int ime_int_to_hex_string(lua_State* L){ + lua_Integer val = lua_checkinteger(L, 1); + lua_Integer width = lua_optinteger(L, 2, -1); + + luaL_Buffer buf; + luaL_buffinit(L, &buf); + + gchar * str = g_strdup_printf("%0*x", width, val); + luaL_addstring(&buf, str); + g_free(str); + + luaL_pushresult(&buf); + lua_remove(L, 2); + lua_remove(L, 1); + return 1; +} + static int ime_join_string(lua_State* L){ luaL_Buffer buf; size_t vec_len; size_t i; @@ -369,6 +386,7 @@ static int ime_utf16_to_utf8(lua_State* L){ static const luaL_Reg imelib[] = { {"get_last_commit", ime_get_last_commit}, {"get_version", ime_get_version}, + {"int_to_hex_string", ime_int_to_hex_string}, {"join_string", ime_join_string}, {"parse_mapping", ime_parse_mapping}, {"register_command", ime_register_command}, |