diff options
author | Daniel Kolesa <d.kolesa@osg.samsung.com> | 2017-11-24 10:53:27 +0100 |
---|---|---|
committer | Daniel Kolesa <d.kolesa@osg.samsung.com> | 2017-11-24 10:55:46 +0100 |
commit | 40214e16c72fb26e7dbdde0344dc771acc2aaa6b (patch) | |
tree | 2099ffc06e0f32c1602809a9db3a00e045218af4 /src/lib/elua/elua.c | |
parent | 6587613a5810188378d52191fbc12ba44394b607 (diff) |
elua: correctly wrap gettext funcs
Now, we cannot directly register funcs defined by a different
signature than the lua standard (int (*)(lua_State *)) so we
have to correctly wrap those with proper conversions etc.
Diffstat (limited to 'src/lib/elua/elua.c')
-rw-r--r-- | src/lib/elua/elua.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/src/lib/elua/elua.c b/src/lib/elua/elua.c index 44b5c32c59..3f3654e678 100644 --- a/src/lib/elua/elua.c +++ b/src/lib/elua/elua.c | |||
@@ -360,14 +360,43 @@ _elua_get_localeconv(lua_State *L) | |||
360 | return 1; | 360 | return 1; |
361 | }; | 361 | }; |
362 | 362 | ||
363 | #ifdef ENABLE_NLS | ||
364 | static int | ||
365 | _elua_dgettext(lua_State *L) | ||
366 | { | ||
367 | const char *domain = luaL_checkstring(L, 1); | ||
368 | const char *msgid = luaL_checkstring(L, 2); | ||
369 | char *ret = dgettext(domain, msgid); | ||
370 | if (!ret) | ||
371 | lua_pushnil(L); | ||
372 | else | ||
373 | lua_pushstring(L, ret); | ||
374 | return 1; | ||
375 | } | ||
376 | |||
377 | static int | ||
378 | _elua_dngettext(lua_State *L) | ||
379 | { | ||
380 | const char *domain = luaL_checkstring(L, 1); | ||
381 | const char *msgid = luaL_checkstring(L, 2); | ||
382 | const char *plmsgid = luaL_checkstring(L, 3); | ||
383 | char *ret = dngettext(domain, msgid, plmsgid, luaL_checklong(L, 4)); | ||
384 | if (!ret) | ||
385 | lua_pushnil(L); | ||
386 | else | ||
387 | lua_pushstring(L, ret); | ||
388 | return 1; | ||
389 | } | ||
390 | #endif | ||
391 | |||
363 | const luaL_Reg gettextlib[] = | 392 | const luaL_Reg gettextlib[] = |
364 | { | 393 | { |
365 | { "bind_textdomain", _elua_gettext_bind_textdomain }, | 394 | { "bind_textdomain", _elua_gettext_bind_textdomain }, |
366 | { "get_message_language", _elua_get_message_language }, | 395 | { "get_message_language", _elua_get_message_language }, |
367 | { "get_localeconv", _elua_get_localeconv }, | 396 | { "get_localeconv", _elua_get_localeconv }, |
368 | #ifdef ENABLE_NLS | 397 | #ifdef ENABLE_NLS |
369 | { "dgettext", dgettext }, | 398 | { "dgettext", _elua_dgettext }, |
370 | { "dgettext", dngettext }, | 399 | { "dngettext", _elua_dngettext }, |
371 | #endif | 400 | #endif |
372 | { NULL, NULL } | 401 | { NULL, NULL } |
373 | }; | 402 | }; |