Beispiel #1
0
int LuaV6Chat3App::GetUserInfoByID(lua_State *luaState)
{
	V6Chat3App *App = GetV6Chat3App(luaState);
	if (App)
	{
		int id = lua_tointeger(luaState, 2);
		UserList *list = UserList::Instance();
		wstring nick_name, group_name, introduction, location;
		unsigned short sex = 0;
		unsigned int age = 0;

		if(list->GetUser(id, nick_name, group_name, sex, age, introduction, location))
		{
			lua_newtable(luaState);
			lua_pushstring(luaState, "name");
			lua_pushstring(luaState, V6Util::UnicodeToUtf8(nick_name.c_str()).c_str());
			lua_settable(luaState,-3);
			lua_pushstring(luaState, "groupname");
			lua_pushstring(luaState, V6Util::UnicodeToUtf8(group_name.c_str()).c_str());
			lua_settable(luaState,-3);
			lua_pushstring(luaState, "sex");
			lua_pushnumber(luaState, sex);
			lua_settable(luaState,-3);
			lua_pushstring(luaState, "age");
			lua_pushnumber(luaState, age);
			lua_settable(luaState,-3);
			lua_pushstring(luaState, "introduction");
			lua_pushstring(luaState, V6Util::UnicodeToUtf8(introduction.c_str()).c_str());
			lua_settable(luaState,-3);
			lua_pushstring(luaState, "location");
			lua_pushstring(luaState, V6Util::UnicodeToUtf8(location.c_str()).c_str());
			lua_settable(luaState,-3);
			wstring headImagePath(USERHEAD_RELATIVE_PATH);
			wstringstream sid;
			sid<<id;
			headImagePath = headImagePath + L"\\" + sid.str();
			XL_BITMAP_HANDLE bmp = V6Util::GetUserDataImageHandle(headImagePath.c_str());
			if(bmp)
			{
				lua_pushstring(luaState, "head");
				if(!XLUE_PushBitmap(luaState, bmp))
			        lua_pushnil(luaState);
			    lua_settable(luaState,-3);   //弹出key,value,并设置到subtable里面去
			}
			return 1;
		}
	}
	lua_pushnil(luaState);
	return 1;
}