示例#1
0
static CContentType *CclParseContent(lua_State *l)
{
	Assert(lua_istable(l, -1));

	CContentType *content = NULL;
	ConditionPanel *condition = NULL;
	PixelPos pos(0, 0);

	for (lua_pushnil(l); lua_next(l, -2); lua_pop(l, 1)) {
		const char *key = LuaToString(l, -2);
		if (!strcmp(key, "Pos")) {
			CclGetPos(l, &pos.x, &pos.y);
		} else if (!strcmp(key, "More")) {
			Assert(lua_istable(l, -1));
			lua_rawgeti(l, -1, 1); // Method name
			lua_rawgeti(l, -2, 2); // Method data
			key = LuaToString(l, -2);
			if (!strcmp(key, "Text")) {
				content = new CContentTypeText;
			} else if (!strcmp(key, "FormattedText")) {
				content = new CContentTypeFormattedText;
			} else if (!strcmp(key, "FormattedText2")) {
				content = new CContentTypeFormattedText2;
			} else if (!strcmp(key, "Icon")) {
				content = new CContentTypeIcon;
			} else if (!strcmp(key, "LifeBar")) {
				content = new CContentTypeLifeBar;
			} else if (!strcmp(key, "CompleteBar")) {
				content = new CContentTypeCompleteBar;
			} else {
				LuaError(l, "Invalid drawing method '%s' in DefinePanelContents" _C_ key);
			}
			content->Parse(l);
			lua_pop(l, 2); // Pop Variable Name and Method
		} else if (!strcmp(key, "Condition")) {
			condition = ParseConditionPanel(l);
		} else {
			LuaError(l, "'%s' invalid for Contents in DefinePanelContents" _C_ key);
		}
	}
	content->Pos = pos;
	content->Condition = condition;
	return content;
}