Exemple #1
0
extern "C" Handle<Value> create_function(Persistent<Context> context,
                                         char* source_s,
                                         char* name) {

    // Create a stack-allocated handle scope.
    HandleScope handle_scope;

    Context::Scope context_scope(context);

    // Create a string containing the JavaScript source code.
    Handle<String> source = String::New(source_s);
    // Compile the source code.
    Handle<Script> script = Script::Compile(source);

    // Run the script to get the result.
    Handle<Value> result = script->Run();

    // magic
    Handle<Object> global = context->Global();
    Handle<Value> value = global->Get(String::New(name));

    Handle<Function> func = v8::Handle<Function>::Cast(value);
    func->SetName(String::New(name));

    Persistent<Function> persistent_func = Persistent<Function>::New(func);
    return persistent_func;
}
int LuaV6Chat3App::ChangeServerInfo(lua_State *luaState)
{
	V6Chat3App *App = GetV6Chat3App(luaState);
	if (App)
	{
		int id = lua_tointeger(luaState, 2);
		ServerList *list = ServerList::Instance();
		Handle<ServerInfo> server;

		if(list->GetServer(id, server))
		{
			size_t name_len=lua_objlen(luaState, 3);
			const char *name = lua_tolstring(luaState, 3, &name_len);
			size_t admain_len=lua_objlen(luaState, 4);
			const char *admain = lua_tolstring(luaState, 4, &admain_len);
			size_t account_len=lua_objlen(luaState, 5);
			const char *account = lua_tolstring(luaState, 5, &account_len);
			size_t password_len=lua_objlen(luaState, 6);
			const char *password = lua_tolstring(luaState, 6, &password_len);
			size_t introduction_len=lua_objlen(luaState, 7);
			const char *introduction = lua_tolstring(luaState, 7, &introduction_len);

			if(name)
				server->SetName(V6Util::Utf8ToUnicode(name));
			if(admain)
				server->SetIp(admain);
			if(account)
				server->SetUid(account);
			if(password)
				server->SetUpassword(password);
			if(introduction)
				server->SetDescription(V6Util::Utf8ToUnicode(introduction));

			if(server->HasChange())
			{
				server->DisConnect();
				server->Connect();
			}
		}
	}
	return 0;
}