elua lib: add API to retrieve lconv from lua
authorDaniel Kolesa <d.kolesa@osg.samsung.com>
Thu, 30 Apr 2015 10:50:09 +0000 (11:50 +0100)
committerDaniel Kolesa <d.kolesa@osg.samsung.com>
Wed, 6 May 2015 14:05:23 +0000 (15:05 +0100)
src/lib/elua/elua.c
src/lib/elua/elua_private.h

index 3e1a715a981266a879ff256d534940721ce09b6b..ed5a4e378661bf1372f8e3a88c30b8bb1f8fc33a 100644 (file)
@@ -277,10 +277,57 @@ success:
    return 1;
 };
 
+static int
+_elua_get_localeconv(lua_State *L)
+{
+   struct lconv *lc = localeconv();
+   lua_createtable(L, 0, 24);
+
+#define ELUA_LCF_S(name) \
+   lua_pushstring(L, lc->name); \
+   lua_setfield(L, -2, #name);
+
+#define ELUA_LCF_C(name) \
+   lua_pushinteger(L, (int)lc->name); \
+   lua_setfield(L, -2, #name);
+
+   ELUA_LCF_S(decimal_point);
+   ELUA_LCF_S(thousands_sep);
+   ELUA_LCF_S(grouping);
+   ELUA_LCF_S(int_curr_symbol);
+   ELUA_LCF_S(currency_symbol);
+   ELUA_LCF_S(mon_decimal_point);
+   ELUA_LCF_S(mon_thousands_sep);
+   ELUA_LCF_S(mon_grouping);
+   ELUA_LCF_S(positive_sign);
+   ELUA_LCF_S(negative_sign);
+
+   ELUA_LCF_C(frac_digits);
+   ELUA_LCF_C(p_cs_precedes);
+   ELUA_LCF_C(n_cs_precedes);
+   ELUA_LCF_C(p_sep_by_space);
+   ELUA_LCF_C(n_sep_by_space);
+   ELUA_LCF_C(p_sign_posn);
+   ELUA_LCF_C(n_sign_posn);
+   ELUA_LCF_C(int_frac_digits);
+   ELUA_LCF_C(int_p_cs_precedes);
+   ELUA_LCF_C(int_n_cs_precedes);
+   ELUA_LCF_C(int_p_sep_by_space);
+   ELUA_LCF_C(int_n_sep_by_space);
+   ELUA_LCF_C(int_p_sign_posn);
+   ELUA_LCF_C(int_n_sign_posn);
+
+#undef ELUA_LCF_S
+#undef ELUA_LCF_C
+
+   return 1;
+};
+
 const luaL_reg gettextlib[] =
 {
    { "bind_textdomain", _elua_gettext_bind_textdomain },
    { "get_message_language", _elua_get_message_language },
+   { "get_localeconv", _elua_get_localeconv },
    { NULL, NULL }
 };
 
index 53b514e6276dcc9b0301913c827c05382fb30dbf..01d8e4b1ac057a9e88cad50641b141037c227884 100644 (file)
@@ -5,8 +5,9 @@
 # include <config.h>
 #endif
 
+#include <locale.h>
+
 #ifdef ENABLE_NLS
-# include <locale.h>
 # include <libintl.h>
 # define _(x) dgettext(PACKAGE, x)
 #else