From 8800cf6f40aa90302f3cb412df2152aaed1a411c Mon Sep 17 00:00:00 2001
From: Alexander Gavrilov
Date: Mon, 10 Feb 2014 18:54:52 +0400
Subject: [PATCH] Export functions for converting between UTF-8 and CP437 to
lua.
---
Lua API.html | 6 ++++++
Lua API.rst | 8 ++++++++
library/LuaApi.cpp | 5 +++++
3 files changed, 19 insertions(+)
diff --git a/Lua API.html b/Lua API.html
index 4aecf48a0..2a214259c 100644
--- a/Lua API.html
+++ b/Lua API.html
@@ -1119,6 +1119,12 @@ can be omitted.
dfhack.TranslateName(name[,in_english,only_last_name])
Convert a language_name or only the last name part to string.
+dfhack.df2utf(string)
+Convert a string from DF's CP437 encoding to UTF-8.
+
+dfhack.utf2df(string)
+Convert a string from UTF-8 to DF's CP437 encoding.
+
diff --git a/Lua API.rst b/Lua API.rst
index 1fd5147b5..6c769f004 100644
--- a/Lua API.rst
+++ b/Lua API.rst
@@ -812,6 +812,14 @@ can be omitted.
Convert a language_name or only the last name part to string.
+* ``dfhack.df2utf(string)``
+
+ Convert a string from DF's CP437 encoding to UTF-8.
+
+* ``dfhack.utf2df(string)``
+
+ Convert a string from UTF-8 to DF's CP437 encoding.
+
Gui module
----------
diff --git a/library/LuaApi.cpp b/library/LuaApi.cpp
index bdc0c39e5..c64ad6634 100644
--- a/library/LuaApi.cpp
+++ b/library/LuaApi.cpp
@@ -1279,6 +1279,9 @@ static std::string getHackPath() { return Core::getInstance().getHackPath(); }
static bool isWorldLoaded() { return Core::getInstance().isWorldLoaded(); }
static bool isMapLoaded() { return Core::getInstance().isMapLoaded(); }
+static std::string df2utf(std::string s) { return DF2UTF(s); }
+static std::string utf2df(std::string s) { return UTF2DF(s); }
+
static const LuaWrapper::FunctionReg dfhack_module[] = {
WRAP(getOSType),
WRAP(getDFVersion),
@@ -1288,6 +1291,8 @@ static const LuaWrapper::FunctionReg dfhack_module[] = {
WRAP(isWorldLoaded),
WRAP(isMapLoaded),
WRAPM(Translation, TranslateName),
+ WRAP(df2utf),
+ WRAP(utf2df),
{ NULL, NULL }
};