summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEdwin Mons <edwin.mons@isode.com>2014-05-23 09:01:23 (GMT)
committerSwift Review <review@swift.im>2014-06-22 12:35:26 (GMT)
commitbd7f30aec53fc776be678577dbe4f9afec5898a6 (patch)
tree66afad4382dc16f7405a856dd0b5abc38db51653 /Sluift/sluift.cpp
parent1eb14b6bde145ca54ac9b981df339fb8c56d3930 (diff)
downloadswift-bd7f30aec53fc776be678577dbe4f9afec5898a6.zip
swift-bd7f30aec53fc776be678577dbe4f9afec5898a6.tar.bz2
Sluift component support
Change-Id: Ib8af01c04c866e198c04d35236dea4da464c9116
Diffstat (limited to 'Sluift/sluift.cpp')
-rw-r--r--Sluift/sluift.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp
index b55649b..2fd1e50 100644
--- a/Sluift/sluift.cpp
+++ b/Sluift/sluift.cpp
@@ -16,6 +16,7 @@
#include "Watchdog.h"
#include <Sluift/Lua/Check.h>
#include <Sluift/SluiftClient.h>
+#include <Sluift/SluiftComponent.h>
#include <Sluift/globals.h>
#include <Sluift/Lua/Exception.h>
#include <Sluift/Lua/LuaUtils.h>
@@ -88,6 +89,32 @@ SLUIFT_LUA_FUNCTION_WITH_HELP(
}
SLUIFT_LUA_FUNCTION_WITH_HELP(
+ Sluift, new_component,
+
+ "Creates a new component.\n\nReturns a @{Component} object.\n",
+
+ "jid The JID to connect as\n"
+ "passphrase The passphrase to use\n",
+
+ ""
+) {
+ Lua::checkString(L, 1);
+ JID jid(std::string(Lua::checkString(L, 1)));
+ std::string password(Lua::checkString(L, 2));
+
+ SluiftComponent** component = reinterpret_cast<SluiftComponent**>(lua_newuserdata(L, sizeof(SluiftComponent*)));
+
+ lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.coreLibIndex);
+ lua_getfield(L, -1, "Component");
+ lua_setmetatable(L, -3);
+ lua_pop(L, 1);
+
+ *component = new SluiftComponent(jid, password, &Sluift::globals.networkFactories, &Sluift::globals.eventLoop);
+ (*component)->setTraceEnabled(getGlobalDebug(L));
+ return 1;
+}
+
+SLUIFT_LUA_FUNCTION_WITH_HELP(
Sluift, sha1,
"Compute the SHA-1 hash of given data",
"data the data to hash",
@@ -408,6 +435,16 @@ SLUIFT_API int luaopen_sluift(lua_State* L) {
}
lua_pop(L, 1);
+ // Load component metatable
+ lua_rawgeti(L, LUA_REGISTRYINDEX, Sluift::globals.coreLibIndex);
+ std::vector<std::string> comp_tables = boost::assign::list_of("Component");
+ foreach(const std::string& table, comp_tables) {
+ lua_getfield(L, -1, table.c_str());
+ Lua::FunctionRegistry::getInstance().addFunctionsToTable(L, table);
+ lua_pop(L, 1);
+ }
+ lua_pop(L, 1);
+
// Register documentation for all elements
foreach (boost::shared_ptr<LuaElementConvertor> convertor, Sluift::globals.elementConvertor.getConvertors()) {
boost::optional<LuaElementConvertor::Documentation> documentation = convertor->getDocumentation();