summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Kolesa <d.kolesa@osg.samsung.com>2017-11-24 10:53:27 +0100
committerDaniel Kolesa <d.kolesa@osg.samsung.com>2017-11-24 10:55:46 +0100
commit40214e16c72fb26e7dbdde0344dc771acc2aaa6b (patch)
tree2099ffc06e0f32c1602809a9db3a00e045218af4
parent6587613a5810188378d52191fbc12ba44394b607 (diff)
downloadefl-40214e16c72fb26e7dbdde0344dc771acc2aaa6b.tar.gz
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.
-rw-r--r--src/lib/elua/elua.c33
-rw-r--r--src/scripts/elua/core/gettext.lua26
2 files changed, 38 insertions, 21 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)
return 1;
};
+#ifdef ENABLE_NLS
+static int
+_elua_dgettext(lua_State *L)
+{
+ const char *domain = luaL_checkstring(L, 1);
+ const char *msgid = luaL_checkstring(L, 2);
+ char *ret = dgettext(domain, msgid);
+ if (!ret)
+ lua_pushnil(L);
+ else
+ lua_pushstring(L, ret);
+ return 1;
+}
+
+static int
+_elua_dngettext(lua_State *L)
+{
+ const char *domain = luaL_checkstring(L, 1);
+ const char *msgid = luaL_checkstring(L, 2);
+ const char *plmsgid = luaL_checkstring(L, 3);
+ char *ret = dngettext(domain, msgid, plmsgid, luaL_checklong(L, 4));
+ if (!ret)
+ lua_pushnil(L);
+ else
+ lua_pushstring(L, ret);
+ return 1;
+}
+#endif
+
const luaL_Reg gettextlib[] =
{
{ "bind_textdomain", _elua_gettext_bind_textdomain },
{ "get_message_language", _elua_get_message_language },
{ "get_localeconv", _elua_get_localeconv },
#ifdef ENABLE_NLS
- { "dgettext", dgettext },
- { "dgettext", dngettext },
+ { "dgettext", _elua_dgettext },
+ { "dngettext", _elua_dngettext },
#endif
{ NULL, NULL }
};
diff --git a/src/scripts/elua/core/gettext.lua b/src/scripts/elua/core/gettext.lua
index 96af7d3941..3659b4e043 100644
--- a/src/scripts/elua/core/gettext.lua
+++ b/src/scripts/elua/core/gettext.lua
@@ -1,7 +1,5 @@
-- elua gettext module
-local ffi = require("ffi")
-
local M = {}
local gettext = ...
@@ -10,12 +8,6 @@ local bind_textdomain = gettext.bind_textdomain
local dgettext = gettext.dgettext
local dngettext = gettext.dngettext
-if dgettext then
- dgettext = ffi.cast("char *(*)(const char*, const char*)", dgettext)
- dngettext = ffi.cast("char *(*)(const char*, const char*, const char*, "
- .. "unsigned long)", dngettext)
-end
-
local domains = {}
local default_domain
@@ -39,7 +31,6 @@ M.set_default_domain = function(dom)
return true
end
-local cast, ffistr = ffi.cast, ffi.string
local floor = math.floor
local type = type
@@ -50,12 +41,11 @@ if dgettext then
dom = default_domain
end
if not domains[dom] or not msgid then return msgid end
- local cmsgid = cast("const char*", msgid)
- local lmsgid = dgettext(dom, cmsgid)
- if cmsgid == lmsgid then
+ local lmsgid = dgettext(dom, msgid)
+ if msgid == lmsgid then
return msgid
end
- return ffistr(lmsgid)
+ return lmsgid
end
M.dgettext = M.gettext
M.ngettext = function(dom, msgid, plmsgid, n)
@@ -69,15 +59,13 @@ if dgettext then
if not msgid or n == 1 then return msgid end
return plmsgid
end
- local cmsgid = cast("const char*", msgid)
- local cplmsgid = cast("const char*", plmsgid)
- local lmsgid = dngettext(dom, cmsgid, cplmsgid, n)
+ local lmsgid = dngettext(dom, msgid, plmsgid, n)
if n == 1 then
- if cmsgid == lmsgid then return msgid end
+ if msgid == lmsgid then return msgid end
else
- if cplmsgid == lmsgid then return plmsgid end
+ if plmsgid == lmsgid then return plmsgid end
end
- return ffistr(lmsgid)
+ return lmsgid
end
M.dngettext = M.ngettext
else