/** ** Parse the construction. ** ** @param l Lua state. ** ** @note make this more flexible */ static int CclDefineConstruction(lua_State *l) { LuaCheckArgs(l, 2); if (!lua_istable(l, 2)) { LuaError(l, "incorrect argument"); } // Slot identifier const std::string str = LuaToString(l, 1); CConstruction *construction = ConstructionByIdent(str); std::vector<CConstruction *>::iterator i; if (construction == NULL) { construction = new CConstruction; Constructions.push_back(construction); } else { // redefine completely. construction->Clean(); } construction->Ident = str; // Parse the arguments, in tagged format. lua_pushnil(l); while (lua_next(l, 2)) { const char *value = LuaToString(l, -2); bool files = !strcmp(value, "Files"); if (files || !strcmp(value, "ShadowFiles")) { std::string file; int w = 0; int h = 0; if (!lua_istable(l, -1)) { LuaError(l, "incorrect argument"); } lua_pushnil(l); while (lua_next(l, -2)) { const char *value = LuaToString(l, -2); if (!strcmp(value, "File")) { file = LuaToString(l, -1); } else if (!strcmp(value, "Size")) { CclGetPos(l, &w, &h); } else { LuaError(l, "Unsupported tag: %s" _C_ value); } lua_pop(l, 1); } if (files) { construction->File.File = file; construction->File.Width = w; construction->File.Height = h; } else { construction->ShadowFile.File = file; construction->ShadowFile.Width = w; construction->ShadowFile.Height = h; } } else if (!strcmp(value, "Constructions")) { const unsigned int subargs = lua_rawlen(l, -1); for (unsigned int k = 0; k < subargs; ++k) { int percent = 0; ConstructionFileType file = ConstructionFileConstruction; int frame = 0; lua_rawgeti(l, -1, k + 1); if (!lua_istable(l, -1)) { LuaError(l, "incorrect argument"); } lua_pushnil(l); while (lua_next(l, -2)) { const char *value = LuaToString(l, -2); if (!strcmp(value, "Percent")) { percent = LuaToNumber(l, -1); } else if (!strcmp(value, "File")) { const char *value = LuaToString(l, -1); if (!strcmp(value, "construction")) { file = ConstructionFileConstruction; } else if (!strcmp(value, "main")) { file = ConstructionFileMain; } else { LuaError(l, "Unsupported tag: %s" _C_ value); } } else if (!strcmp(value, "Frame")) { frame = LuaToNumber(l, -1); } else { LuaError(l, "Unsupported tag: %s" _C_ value); } lua_pop(l, 1); } lua_pop(l, 1); CConstructionFrame **cframe = &construction->Frames; while (*cframe) { cframe = &((*cframe)->Next); } (*cframe) = new CConstructionFrame; (*cframe)->Percent = percent; (*cframe)->File = file; (*cframe)->Frame = frame; (*cframe)->Next = NULL; } } else { LuaError(l, "Unsupported tag: %s" _C_ value); } lua_pop(l, 1); } return 0; }
/** ** Get construction by original wc number. ** ** @param num Original number used in puds. */ global Construction* ConstructionByWcNum(int num) { return ConstructionByIdent(ConstructionWcNames[num]); }