diff options
Diffstat (limited to 'Sluift/sluift.cpp')
| -rw-r--r-- | Sluift/sluift.cpp | 37 | 
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 @@ -17,4 +17,5 @@  #include <Sluift/Lua/Check.h>  #include <Sluift/SluiftClient.h> +#include <Sluift/SluiftComponent.h>  #include <Sluift/globals.h>  #include <Sluift/Lua/Exception.h> @@ -89,4 +90,30 @@ 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", @@ -409,4 +436,14 @@ 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()) { | 
 Swift
 Swift