diff options
Diffstat (limited to 'plugins/MirLua/src/mlua_utils.cpp')
-rw-r--r-- | plugins/MirLua/src/mlua_utils.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/plugins/MirLua/src/mlua_utils.cpp b/plugins/MirLua/src/mlua_utils.cpp index 7fa59212c5..31af863da2 100644 --- a/plugins/MirLua/src/mlua_utils.cpp +++ b/plugins/MirLua/src/mlua_utils.cpp @@ -38,6 +38,32 @@ int luaM_atpanic(lua_State *L) return 0;
}
+int luaM_toansi(lua_State *L)
+{
+ const char* value = luaL_checkstring(L, 1);
+ int codepage = luaL_optinteger(L, 2, Langpack_GetDefaultCodePage());
+
+ ptrA string(mir_strdup(value));
+ lua_pushstring(L, mir_utf8decodecp(string, codepage, NULL));
+
+ return 1;
+}
+
+int luaM_toucs2(lua_State *L)
+{
+ const char* value = luaL_checkstring(L, 1);
+
+ ptrW unicode(mir_utf8decodeW(value));
+ size_t length = mir_wstrlen(unicode) * sizeof(wchar_t);
+
+ ptrA string((char*)mir_calloc(length + 1));
+ memcpy(string, unicode, length);
+
+ lua_pushlstring(L, string, length + 1);
+
+ return 1;
+}
+
bool luaM_toboolean(lua_State *L, int idx)
{
if (lua_type(L, idx) == LUA_TNUMBER)
@@ -56,6 +82,9 @@ WPARAM luaM_towparam(lua_State *L, int idx) case LUA_TNUMBER:
wParam = lua_tonumber(L, idx);
break;
+ case LUA_TSTRING:
+ wParam = (WPARAM)lua_tostring(L, idx);
+ break;
case LUA_TUSERDATA:
case LUA_TLIGHTUSERDATA:
wParam = (WPARAM)lua_touserdata(L, idx);
@@ -75,6 +104,9 @@ LPARAM luaM_tolparam(lua_State *L, int idx) case LUA_TNUMBER:
lParam = lua_tonumber(L, idx);
break;
+ case LUA_TSTRING:
+ lParam = (LPARAM)lua_tostring(L, idx);
+ break;
case LUA_TUSERDATA:
case LUA_TLIGHTUSERDATA:
lParam = (LPARAM)lua_touserdata(L, idx);
|