Пример #1
0
int LuaArchive::GetArchiveInfo(lua_State* L)
{
	const std::string archiveName = luaL_checksstring(L, 1);
	CArchiveScanner::ArchiveData archiveData = archiveScanner->GetArchiveData(archiveName);
	if (archiveData.IsEmpty()) {
		return 0;
	}

	lua_createtable(L, 0, archiveData.GetInfo().size());

	for (const auto& pair: archiveData.GetInfo()) {
		const std::string& itemName = pair.first;
		const InfoItem&    itemData = pair.second;

		lua_pushsstring(L, itemName);
		switch (itemData.valueType) {
			case INFO_VALUE_TYPE_STRING: {
				lua_pushsstring(L, itemData.valueTypeString);
			} break;
			case INFO_VALUE_TYPE_INTEGER: {
				lua_pushinteger(L, itemData.value.typeInteger);
			} break;
			case INFO_VALUE_TYPE_FLOAT: {
				lua_pushnumber(L,  itemData.value.typeFloat);
			} break;
			case INFO_VALUE_TYPE_BOOL: {
				lua_pushboolean(L, itemData.value.typeBool);
			} break;
			default: assert(false);
		}
		lua_rawset(L, -3);
	}

	return 1;
}
Пример #2
0
int LuaFonts::meta_index(lua_State* L)
{
	//! first check if there is a function
	luaL_getmetatable(L, "Font");
	lua_pushvalue(L, 2);
	lua_rawget(L, -2);
	if (!lua_isnil(L, -1)) {
		return 1;
	}
	lua_pop(L, 1);

	//! couldn't find a function, so check properties
	CglFont* font = tofont(L, 1);

	if (lua_israwstring(L, 2)) {
		const string key = lua_tostring(L, 2);

		if (key == "size") {
			lua_pushnumber(L, font->GetSize());
			return 1;
		//} else if (key == "outlinecolor") {
		//} else if (key == "textcolor") {
		} else if (key == "path") {
			const std::string& filepath = font->GetFilePath();
			lua_pushsstring(L, filepath);
			return 1;
		} else if (key == "height" || key == "lineheight") {
			lua_pushnumber(L, font->GetLineHeight());
			return 1;
		} else if (key == "descender") {
			lua_pushnumber(L, font->GetDescender());
			return 1;
		} else if (key == "outlinewidth") {
			lua_pushnumber(L, font->GetOutlineWidth());
			return 1;
		} else if (key == "outlineweight") {
			lua_pushnumber(L, font->GetOutlineWeight());
			return 1;
		} else if (key == "family") {
			const std::string& family = font->GetFamily();
			lua_pushsstring(L, family);
			return 1;
		} else if (key == "style") {
			const std::string& style = font->GetStyle();
			lua_pushsstring(L, style);
			return 1;
		} else if (key == "texturewidth") {
			lua_pushnumber(L, font->GetTexWidth());
			return 1;
		} else if (key == "textureheight") {
			lua_pushnumber(L, font->GetTexHeight());
			return 1;
		}
	}

	return 0;
}
Пример #3
0
int LuaArchive::GetArchiveChecksum(lua_State* L)
{
	const std::string archiveName = luaL_checksstring(L, 1);
	const unsigned int checksumSingl = archiveScanner->GetSingleArchiveChecksum(archiveName);
	const unsigned int checksumAccum = archiveScanner->GetArchiveCompleteChecksum(archiveName);
	lua_pushsstring(L, IntToString(checksumSingl, "%X"));
	lua_pushsstring(L, IntToString(checksumAccum, "%X"));
	return 2;
}
Пример #4
0
void LuaLobby::JoinFailed(const std::string& channame, const std::string& reason)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 4);

	lua_pushsstring(L, channame);
	lua_pushsstring(L, reason);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 2, 0);
}
Пример #5
0
void LuaLobby::ServerMessageBox(const std::string& text, const std::string& url)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 4);

	lua_pushsstring(L, text);
	lua_pushsstring(L, url);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 2, 0);
}
Пример #6
0
void LuaLobby::ChannelMessage(const std::string& channel, const std::string& text)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 4);

	lua_pushsstring(L, channel);
	lua_pushsstring(L, text);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 2, 0);
}
Пример #7
0
void LuaLobby::SaidPrivate(const std::string& user, const std::string& text)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 4);

	lua_pushsstring(L, user);
	lua_pushsstring(L, text);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 2, 0);
}
Пример #8
0
void LuaLobby::AddUser(const std::string& name, const std::string& country, int cpu)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 5);

	lua_pushsstring(L, name);
	lua_pushsstring(L, country);
	lua_pushnumber(L, cpu);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 3, 0);
}
Пример #9
0
void LuaLobby::ChannelMember(const std::string& channame, const std::string& name, bool joined)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 5);

	lua_pushsstring(L, channame);
	lua_pushsstring(L, name);
	lua_pushboolean(L, joined);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 3, 0);
}
Пример #10
0
void LuaLobby::SaidEx(const std::string& channel, const std::string& user, const std::string& text)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 5);

	lua_pushsstring(L, channel);
	lua_pushsstring(L, user);
	lua_pushsstring(L, text);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 3, 0);
}
Пример #11
0
void LuaLobby::ChannelMemberKicked(const std::string& channame, const std::string& user, const std::string& reason)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 5);

	lua_pushsstring(L, channame);
	lua_pushsstring(L, user);
	lua_pushsstring(L, reason);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 3, 0);
}
Пример #12
0
void LuaLobby::ServerGreeting(const std::string& serverVer, const std::string& springVer, int udpport, int mode)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 6);

	lua_pushsstring(L, serverVer);
	lua_pushsstring(L, springVer);
	lua_pushnumber(L, udpport);
	lua_pushnumber(L, mode);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 4, 0);
}
Пример #13
0
void LuaLobby::ChannelTopic(const std::string& channame, const std::string& author, long unsigned time, const std::string& topic)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 6);

	lua_pushsstring(L, channame);
	lua_pushsstring(L, author);
	lua_pushnumber(L, time/1000);
	lua_pushsstring(L, topic);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 4, 0);
}
Пример #14
0
static int CustomParamsTable(lua_State* L, const void* data)
{
	const map<string, string>& params = *((const map<string, string>*)data);
	lua_newtable(L);
	map<string, string>::const_iterator it;
	for (it = params.begin(); it != params.end(); ++it) {
		lua_pushsstring(L, it->first);
		lua_pushsstring(L, it->second);
		lua_rawset(L, -3);
	}
	return 1;
}
Пример #15
0
static bool LowerKeysReal(lua_State* L, int depth)
{
	lua_checkstack(L, lowerKeysTable + 8 + (depth * 3));

	const int table = lua_gettop(L);
	if (LowerKeysCheck(L, table)) {
		return true;
	}

	// a new table for changed values
	const int changed = table + 1;
	lua_newtable(L);

	for (lua_pushnil(L); lua_next(L, table) != 0; lua_pop(L, 1)) {
		if (lua_istable(L, -1)) {
			LowerKeysReal(L, depth + 1);
		}
		if (lua_israwstring(L, -2)) {
			const string rawKey = lua_tostring(L, -2);
			const string lowerKey = StringToLower(rawKey);
			if (rawKey != lowerKey) {
				// removed the mixed case entry
				lua_pushvalue(L, -2); // the key
				lua_pushnil(L);
				lua_rawset(L, table);
				// does the lower case key alread exist in the table?
				lua_pushsstring(L, lowerKey);
				lua_rawget(L, table);
				if (lua_isnil(L, -1)) {
					// lower case does not exist, add it to the changed table
					lua_pushsstring(L, lowerKey);
					lua_pushvalue(L, -3); // the value
					lua_rawset(L, changed);
				}
				lua_pop(L, 1);
			}
		}
	}

	// copy the changed values into the table
	for (lua_pushnil(L); lua_next(L, changed) != 0; lua_pop(L, 1)) {
		lua_pushvalue(L, -2); // copy the key to the top
		lua_pushvalue(L, -2); // copy the value to the top
		lua_rawset(L, table);
	}

	lua_pop(L, 1); // pop the changed table

	return true;
}
Пример #16
0
int LuaUtils::Next(const ParamMap& paramMap, lua_State* L)
{
	luaL_checktype(L, 1, LUA_TTABLE);
	lua_settop(L, 2); // create a 2nd argument if there isn't one

	// internal parameters first
	if (lua_isnil(L, 2)) {
		const string& nextKey = paramMap.begin()->first;
		lua_pushsstring(L, nextKey); // push the key
		lua_pushvalue(L, 3);         // copy the key
		lua_gettable(L, 1);          // get the value
		return 2;
	}

	// all internal parameters use strings as keys
	if (lua_isstring(L, 2)) {
		const char* key = lua_tostring(L, 2);
		ParamMap::const_iterator it = paramMap.find(key);
		if ((it != paramMap.end()) && (it->second.type != READONLY_TYPE)) {
			// last key was an internal parameter
			++it;
			while ((it != paramMap.end()) && (it->second.type == READONLY_TYPE)) {
				++it; // skip read-only parameters
			}
			if ((it != paramMap.end()) && (it->second.type != READONLY_TYPE)) {
				// next key is an internal parameter
				const string& nextKey = it->first;
				lua_pushsstring(L, nextKey); // push the key
				lua_pushvalue(L, 3);         // copy the key
				lua_gettable(L, 1);          // get the value (proxied)
				return 2;
			}
			// start the user parameters,
			// remove the internal key and push a nil
			lua_settop(L, 1);
			lua_pushnil(L);
		}
	}

	// user parameter
	if (lua_next(L, 1)) {
		return 2;
	}

	// end of the line
	lua_pushnil(L);
	return 1;
}
Пример #17
0
bool CLuaRules::AllowResourceTransfer(int oldTeam, int newTeam,
                                      const string& type, float amount)
{
	if (!haveAllowResourceTransfer)
		return true; // the call is not defined

	LUA_CALL_IN_CHECK(L, true);
	lua_checkstack(L, 6);
	static const LuaHashString cmdStr("AllowResourceTransfer");
	if (!cmdStr.GetGlobalFunc(L))
		return true; // the call is not defined

	lua_pushnumber(L, oldTeam);
	lua_pushnumber(L, newTeam);
	lua_pushsstring(L, type);
	lua_pushnumber(L, amount);

	// call the function
	if (!RunCallIn(cmdStr, 4, 1))
		return true;

	// get the results
	if (!lua_isboolean(L, -1)) {
		LOG_L(L_WARNING, "%s() bad return value", cmdStr.GetString().c_str());
		lua_pop(L, 1);
		return true;
	}

	const bool retval = !!lua_toboolean(L, -1);
	lua_pop(L, 1);
	return retval;
}
Пример #18
0
bool CLuaRules::AllowResourceLevel(int teamID, const string& type, float level)
{
	if (!haveAllowResourceLevel)
		return true; // the call is not defined

	LUA_CALL_IN_CHECK(L, true);
	lua_checkstack(L, 5);
	static const LuaHashString cmdStr("AllowResourceLevel");
	if (!cmdStr.GetGlobalFunc(L))
		return true; // the call is not defined

	lua_pushnumber(L, teamID);
	lua_pushsstring(L, type);
	lua_pushnumber(L, level);

	// call the function
	if (!RunCallIn(cmdStr, 3, 1))
		return true;

	// get the results
	if (!lua_isboolean(L, -1)) {
		LOG_L(L_WARNING, "%s() bad return value", cmdStr.GetString().c_str());
		lua_pop(L, 1);
		return true;
	}

	const bool retval = !!lua_toboolean(L, -1);
	lua_pop(L, 1);
	return retval;
}
Пример #19
0
void LuaLobby::Mutelist(const std::string& channel, std::list<std::string> list)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 4);

	lua_pushsstring(L, channel);
	lua_newtable(L);
	int i = 1;
	for (std::list<std::string>::const_iterator it = list.begin(); it != list.end(); ++it)
	{
		lua_pushsstring(L, *it);
		lua_rawseti(L, -2, i++);
	}

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 2, 0);
}
Пример #20
0
void LuaUtils::PushCommandDesc(lua_State* L, const CommandDescription& cd)
{
	const int numParams = cd.params.size();
	const int numTblKeys = 12;

	lua_checkstack(L, 1 + 1 + 1 + 1);
	lua_createtable(L, 0, numTblKeys);

	HSTR_PUSH_NUMBER(L, "id",          cd.id);
	HSTR_PUSH_NUMBER(L, "type",        cd.type);
	HSTR_PUSH_STRING(L, "name",        cd.name);
	HSTR_PUSH_STRING(L, "action",      cd.action);
	HSTR_PUSH_STRING(L, "tooltip",     cd.tooltip);
	HSTR_PUSH_STRING(L, "texture",     cd.iconname);
	HSTR_PUSH_STRING(L, "cursor",      cd.mouseicon);
	HSTR_PUSH_BOOL(L,   "hidden",      cd.hidden);
	HSTR_PUSH_BOOL(L,   "disabled",    cd.disabled);
	HSTR_PUSH_BOOL(L,   "showUnique",  cd.showUnique);
	HSTR_PUSH_BOOL(L,   "onlyTexture", cd.onlyTexture);

	HSTR_PUSH(L, "params");

	lua_createtable(L, 0, numParams);

	for (int p = 0; p < numParams; p++) {
		lua_pushsstring(L, cd.params[p]);
		lua_rawseti(L, -2, p + 1);
	}

	// CmdDesc["params"] = {[1] = "string1", [2] = "string2", ...}
	lua_settable(L, -3);
}
Пример #21
0
bool CLuaHandleSynced::Initialize(const string& syncData)
{
	LUA_CALL_IN_CHECK(L, true);
	lua_checkstack(L, 3);
	static const LuaHashString cmdStr("Initialize");
	if (!cmdStr.GetGlobalFunc(L)) {
		return true;
	}

	int errfunc = SetupTraceback(L) ? -2 : 0;
	LOG("Initialize errfunc=%d", errfunc);

	lua_pushsstring(L, syncData);

	// call the routine
	if (!RunCallInTraceback(cmdStr, 1, 1, errfunc)) {
		return false;
	}

	// get the results
	if (!lua_isboolean(L, -1)) {
		lua_pop(L, 1);
		return true;
	}
	const bool retval = !!lua_toboolean(L, -1);
	lua_pop(L, 1);
	return retval;
}
Пример #22
0
void LuaLobby::LoginDenied(const std::string& reason)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 3);

	lua_pushsstring(L, reason);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 1, 0);
}
Пример #23
0
void LuaUtils::PushStringVector(lua_State* L, const vector<string>& vec)
{
	lua_createtable(L, vec.size(), 0);
	for (size_t i = 0; i < vec.size(); i++) {
		lua_pushnumber(L, (int) (i + 1));
		lua_pushsstring(L, vec[i]);
		lua_rawset(L, -3);
	}
}
Пример #24
0
static int WeaponDefToName(lua_State* L, const void* data)
{
	const WeaponDef* wd = *((const WeaponDef**)data);
	if (wd == NULL) {
		return 0;
	}
	lua_pushsstring(L, wd->name);
	return 1;
}
Пример #25
0
void LuaLobby::Motd(const std::string& text)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 3);

	lua_pushsstring(L, text);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 1, 0);
}
Пример #26
0
void LuaLobby::Joined(const std::string& channame)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 3);

	lua_pushsstring(L, channame);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 1, 0);
}
Пример #27
0
void LuaLobby::NetworkError(const std::string& msg)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 3);

	lua_pushsstring(L, msg);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 1, 0);
}
Пример #28
0
void LuaLobby::ChannelInfo(const std::string& channel, unsigned users)
{
	LUA_LOBBY_CALL_IN_CHECK(L, 4);

	lua_pushsstring(L, channel);
	lua_pushnumber(L, users);

	// call the routine
	luaUI->RunCallInUnsynced(cmdStr, 2, 0);
}
Пример #29
0
static int SafeIconType(lua_State* L, const void* data)
{
	// the iconType is unsynced because LuaUI has SetUnitDefIcon()
	if (!CLuaHandle::GetHandleSynced(L)) {
		const icon::CIcon& iconType = *((const icon::CIcon*)data);
		lua_pushsstring(L, iconType->GetName());
		return 1;
	}
	return 0;
}
Пример #30
0
static void LuaPushNamedColor(lua_State* L,
                              const string& name, const float3& color)
{
	lua_pushsstring(L, name);
	lua_newtable(L);
	lua_pushnumber(L, color.x); lua_rawseti(L, -2, 1);
	lua_pushnumber(L, color.y); lua_rawseti(L, -2, 2);
	lua_pushnumber(L, color.z); lua_rawseti(L, -2, 3);
	lua_rawset(L, -3);
}