diff options
Diffstat (limited to 'Sluift/Lua/Check.cpp')
-rw-r--r-- | Sluift/Lua/Check.cpp | 12 |
1 files changed, 11 insertions, 1 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,4 +1,4 @@ /* - * 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. @@ -13,4 +13,5 @@ #include <Sluift/Lua/Exception.h> +#include <Swiften/Base/ByteArray.h> using namespace Swift; @@ -44,4 +45,13 @@ std::string Lua::checkString(lua_State* L, int arg) { } +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); |