summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Sluift/Lua')
-rw-r--r--Sluift/Lua/Check.cpp12
-rw-r--r--Sluift/Lua/Check.h5
-rw-r--r--Sluift/Lua/LuaUtils.cpp8
-rw-r--r--Sluift/Lua/LuaUtils.h2
4 files changed, 25 insertions, 2 deletions
diff --git a/Sluift/Lua/Check.cpp b/Sluift/Lua/Check.cpp
index 65ada7b..a9b8f02 100644
--- a/Sluift/Lua/Check.cpp
+++ b/Sluift/Lua/Check.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013 Remko Tronçon
+ * Copyright (c) 2013-2014 Remko Tronçon
* Licensed under the GNU General Public License.
* See the COPYING file for more information.
*/
@@ -12,6 +12,7 @@
#include <lua.hpp>
#include <Sluift/Lua/Exception.h>
+#include <Swiften/Base/ByteArray.h>
using namespace Swift;
@@ -43,6 +44,15 @@ std::string Lua::checkString(lua_State* L, int arg) {
return std::string(s);
}
+ByteArray Lua::checkByteArray(lua_State* L, int arg) {
+ size_t len;
+ const char *s = lua_tolstring(L, arg, &len);
+ if (!s) {
+ throw Lua::Exception(getArgTypeError(L, arg, LUA_TSTRING));
+ }
+ return createByteArray(s, len);
+}
+
void* Lua::checkUserDataRaw(lua_State* L, int arg) {
void* userData = lua_touserdata(L, arg);
if (!userData) {
diff --git a/Sluift/Lua/Check.h b/Sluift/Lua/Check.h
index 8a8b64a..c22751b 100644
--- a/Sluift/Lua/Check.h
+++ b/Sluift/Lua/Check.h
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013 Remko Tronçon
+ * Copyright (c) 2013-2014 Remko Tronçon
* Licensed under the GNU General Public License.
* See the COPYING file for more information.
*/
@@ -8,6 +8,8 @@
#include <string>
+#include <Swiften/Base/ByteArray.h>
+
struct lua_State;
namespace Swift {
@@ -15,6 +17,7 @@ namespace Swift {
void checkType(lua_State* L, int arg, int type);
int checkIntNumber(lua_State* L, int arg);
std::string checkString(lua_State* L, int arg);
+ ByteArray checkByteArray(lua_State* L, int arg);
void* checkUserDataRaw(lua_State* L, int arg);
diff --git a/Sluift/Lua/LuaUtils.cpp b/Sluift/Lua/LuaUtils.cpp
index 915f3cc..dbadaab 100644
--- a/Sluift/Lua/LuaUtils.cpp
+++ b/Sluift/Lua/LuaUtils.cpp
@@ -189,3 +189,11 @@ void Swift::Lua::registerExtraHelp(lua_State* L, int index, const std::string& n
}
lua_pop(L, 3);
}
+
+void Swift::Lua::pushStringArray(lua_State* L, const std::vector<std::string>& strings) {
+ lua_createtable(L, strings.size(), 0);
+ for (size_t i = 0; i < strings.size(); ++i) {
+ lua_pushstring(L, strings[i].c_str());
+ lua_rawseti(L, -2, boost::numeric_cast<int>(i+1));
+ }
+}
diff --git a/Sluift/Lua/LuaUtils.h b/Sluift/Lua/LuaUtils.h
index 105f249..ed4fcc1 100644
--- a/Sluift/Lua/LuaUtils.h
+++ b/Sluift/Lua/LuaUtils.h
@@ -37,5 +37,7 @@ namespace Swift {
boost::optional<std::string> getStringField(lua_State* L, int index, const std::string&);
boost::optional<bool> getBooleanField(lua_State* L, int index, const std::string&);
boost::optional<int> getIntField(lua_State* L, int index, const std::string&);
+
+ void pushStringArray(lua_State* L, const std::vector<std::string>& strings);
}
}