summaryrefslogtreecommitdiffstats
path: root/Sluift
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2011-03-03 21:11:18 (GMT)
committerRemko Tronçon <git@el-tramo.be>2011-03-03 22:14:49 (GMT)
commit12024229138787d7df91cb8101d0986996880e3d (patch)
tree575ef4bd2104ce4a0531580ac78381dbb94f6c6e /Sluift
parenta8cd6a5cbf74d0db4df0b7daa8e4b1b0e0bc00d0 (diff)
downloadswift-contrib-12024229138787d7df91cb8101d0986996880e3d.zip
swift-contrib-12024229138787d7df91cb8101d0986996880e3d.tar.bz2
Some more Sluift tweaks.
Diffstat (limited to 'Sluift')
-rw-r--r--Sluift/.gitignore1
-rw-r--r--Sluift/Lua/Value.cpp9
-rw-r--r--Sluift/SConscript14
-rw-r--r--Sluift/sluift.cpp93
4 files changed, 82 insertions, 35 deletions
diff --git a/Sluift/.gitignore b/Sluift/.gitignore
index e343aca..35a18c0 100644
--- a/Sluift/.gitignore
+++ b/Sluift/.gitignore
@@ -1,3 +1,4 @@
lua.c
sluift_dll.cpp
sluift
+dll.c
diff --git a/Sluift/Lua/Value.cpp b/Sluift/Lua/Value.cpp
index b612bd9..8dd8fcc 100644
--- a/Sluift/Lua/Value.cpp
+++ b/Sluift/Lua/Value.cpp
@@ -36,11 +36,10 @@ namespace {
lua_pushstring(state, s.c_str());
}
- void operator()(const std::vector<Value>& list) const {
- lua_newtable(state);
- int i = 0;
- foreach(const Value& value, list) {
- boost::apply_visitor(PushVisitor(state), value);
+ void operator()(const std::vector<Value>& values) const {
+ lua_createtable(state, values.size(), 0);
+ for(size_t i = 0; i < values.size(); ++i) {
+ boost::apply_visitor(PushVisitor(state), values[i]);
lua_rawseti(state, -2, i + 1);
}
}
diff --git a/Sluift/SConscript b/Sluift/SConscript
index ec9f690..6f38693 100644
--- a/Sluift/SConscript
+++ b/Sluift/SConscript
@@ -1,3 +1,5 @@
+import Version
+
Import(["env", "conf_env"])
if env["SCONS_STAGE"] == "build" :
@@ -21,17 +23,22 @@ if env["SCONS_STAGE"] == "build" :
elif myenv["PLATFORM"] == "darwin" :
myenv["SHLIBSUFFIX"] = ".so"
+ myenv["SLUIFT_VERSION"] = Version.getBuildVersion("sluift")
def patchLua(env, target, source) :
f = open(source[0].abspath, "r")
contents = f.read()
f.close()
- contents = contents.replace("LUA_RELEASE", "\"== Sluift XMPP Console ==\"")
+ if env["PLATFORM"] == "windows" :
+ key = "Z"
+ else :
+ key = "D"
+ contents = contents.replace("LUA_RELEASE", "\"== Sluift XMPP Console (%(version)s) == \\nPress Ctrl-%(key)s to exit\"" % {"version": source[1].get_contents(), "key" : key})
contents = contents.replace("LUA_COPYRIGHT", "")
f = open(target[0].abspath, "w")
f.write(contents)
f.close()
- myenv.Command("lua.c", ["#/3rdParty/Lua/src/lua.c"], env.Action(patchLua, cmdstr = "$GENCOMSTR"))
+ myenv.Command("lua.c", ["#/3rdParty/Lua/src/lua.c", myenv.Value(myenv["SLUIFT_VERSION"])], env.Action(patchLua, cmdstr = "$GENCOMSTR"))
if myenv.get("HAVE_READLINE", False) :
myenv.Append(CPPDEFINES = ["LUA_USE_READLINE"])
myenv.MergeFlags(myenv["READLINE_FLAGS"])
@@ -40,4 +47,5 @@ if env["SCONS_STAGE"] == "build" :
"linit.c",
])
- myenv.SharedLibrary("sluift", []);
+ myenv.WriteVal("dll.c", myenv.Value(""))
+ myenv.SharedLibrary("sluift", ["dll.c"])
diff --git a/Sluift/sluift.cpp b/Sluift/sluift.cpp
index 5d24276..324c94e 100644
--- a/Sluift/sluift.cpp
+++ b/Sluift/sluift.cpp
@@ -320,35 +320,45 @@ static int sluift_client_send_presence(lua_State *L) {
}
static int sluift_client_get(lua_State *L) {
- SluiftClient* client = getClient(L);
- JID jid;
- std::string data;
- if (lua_type(L, 3) != LUA_TNONE) {
- jid = JID(std::string(luaL_checkstring(L, 2)));
- data = std::string(luaL_checkstring(L, 3));
+ try {
+ SluiftClient* client = getClient(L);
+ JID jid;
+ std::string data;
+ if (lua_type(L, 3) != LUA_TNONE) {
+ jid = JID(std::string(luaL_checkstring(L, 2)));
+ data = std::string(luaL_checkstring(L, 3));
+ }
+ else {
+ data = std::string(luaL_checkstring(L, 2));
+ }
+ std::string result = client->sendQuery(jid, IQ::Get, data);
+ lua_pushstring(L, result.c_str());
+ return 1;
}
- else {
- data = std::string(luaL_checkstring(L, 2));
+ catch (const SluiftException& e) {
+ return luaL_error(L, e.getReason().c_str());
}
- std::string result = client->sendQuery(jid, IQ::Get, data);
- lua_pushstring(L, result.c_str());
- return 1;
}
static int sluift_client_set(lua_State *L) {
- SluiftClient* client = getClient(L);
- JID jid;
- std::string data;
- if (lua_type(L, 3) != LUA_TNONE) {
- jid = JID(std::string(luaL_checkstring(L, 2)));
- data = std::string(luaL_checkstring(L, 3));
+ try {
+ SluiftClient* client = getClient(L);
+ JID jid;
+ std::string data;
+ if (lua_type(L, 3) != LUA_TNONE) {
+ jid = JID(std::string(luaL_checkstring(L, 2)));
+ data = std::string(luaL_checkstring(L, 3));
+ }
+ else {
+ data = std::string(luaL_checkstring(L, 2));
+ }
+ std::string result = client->sendQuery(jid, IQ::Set, data);
+ lua_pushstring(L, result.c_str());
+ return 1;
}
- else {
- data = std::string(luaL_checkstring(L, 2));
+ catch (const SluiftException& e) {
+ return luaL_error(L, e.getReason().c_str());
}
- std::string result = client->sendQuery(jid, IQ::Set, data);
- lua_pushstring(L, result.c_str());
- return 1;
}
static int sluift_client_send(lua_State *L) {
@@ -452,12 +462,41 @@ static int sluift_client_add_contact(lua_State* L) {
try {
eventLoop.runOnce();
SluiftClient* client = getClient(L);
- JID jid(luaL_checkstring(L, 2));
+ RosterItemPayload item;
+ if (lua_type(L, 2) == LUA_TTABLE) {
+ lua_getfield(L, 2, "jid");
+ const char* rawJID = lua_tostring(L, -1);
+ if (rawJID) {
+ item.setJID(std::string(rawJID));
+ }
+ lua_getfield(L, 2, "name");
+ const char* rawName = lua_tostring(L, -1);
+ if (rawName) {
+ item.setName(rawName);
+ }
+ lua_getfield(L, 2, "groups");
+ if (!lua_isnil(L, -1)) {
+ if (lua_type(L, -1) == LUA_TTABLE) {
+ for (size_t i = 1; i <= lua_objlen(L, -1); ++i) {
+ lua_rawgeti(L, -1, i);
+ const char* rawGroup = lua_tostring(L, -1);
+ if (rawGroup) {
+ item.addGroup(rawGroup);
+ }
+ lua_pop(L, 1);
+ }
+ }
+ else {
+ return luaL_error(L, "Groups should be a table");
+ }
+ }
+ }
+ else {
+ item.setJID(luaL_checkstring(L, 2));
+ }
client->getRoster();
- if (!client->getClient()->getRoster()->containsJID(jid)) {
- RosterItemPayload item;
- item.setJID(jid);
+ if (!client->getClient()->getRoster()->containsJID(item.getJID())) {
RosterPayload::ref roster = boost::make_shared<RosterPayload>();
roster->addItem(item);
@@ -473,7 +512,7 @@ static int sluift_client_add_contact(lua_State* L) {
return 1;
}
}
- client->getClient()->getSubscriptionManager()->requestSubscription(jid);
+ client->getClient()->getSubscriptionManager()->requestSubscription(item.getJID());
lua_pushboolean(L, true);
return 1;
}