コード例 #1
0
ファイル: gameconfigs.cpp プロジェクト: Javivi/amxmodx
// native GameConfig:LoadGameConfigFile(const file[]);
static cell AMX_NATIVE_CALL LoadGameConfigFile(AMX *amx, cell *params)
{
	int length;
	const char *filename = get_amxstring(amx, params[1], 0, length);

	IGameConfig *config = nullptr;
	char error[128];

	if (!ConfigManager.LoadGameConfigFile(filename, &config, error, sizeof(error)))
	{
		LogError(amx, AMX_ERR_NATIVE, "Unable to open %s: %s", filename, error);
		return 0;
	}

	int handle = GameConfigHandle.create();

	auto configHandle = GameConfigHandle.lookup(handle);
	
	if (!configHandle)
	{
		return 0;
	}

	configHandle->m_config = config;

	return handle;
}
コード例 #2
0
ファイル: datastructs.cpp プロジェクト: Javivi/amxmodx
// Array:ArrayCreate(cellsize=1, reserved=32);
static cell AMX_NATIVE_CALL ArrayCreate(AMX* amx, cell* params)
{
	// params[1] (cellsize) is how big in cells each element is.
	// this MUST be greater than 0!
	int cellsize = params[1];

	// params[2] (reserved) is how many elements to allocate
	// immediately when the list is created.
	int reserved = params[2];

	if (cellsize <= 0)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid array size (%d)", cellsize);
		return -1;
	}

	if (reserved < 0)
	{
		reserved = 0;
	}

	return ArrayHandles.create(cellsize, reserved);
}
コード例 #3
0
static cell AMX_NATIVE_CALL TrieSnapshotCreate(AMX *amx, cell *params)
{
	CellTrie *t = TrieHandles.lookup(params[1]);

	if (!t)
	{
		LogError(amx, AMX_ERR_NATIVE, "Invalid map handle provided (%d)", params[1]);
		return 0;
	}

	int index = TrieSnapshotHandles.create();
	TrieSnapshot *snapshot = TrieSnapshotHandles.lookup(index);
	snapshot->length = t->map.elements();
	snapshot->keys = new int[snapshot->length];

	size_t i = 0;
	for (StringHashMap<Entry>::iterator iter = t->map.iter(); !iter.empty(); iter.next(), i++)
	{
		snapshot->keys[i] = snapshot->strings.AddString(iter->key.chars(), iter->key.length());
	}
	assert(i == snapshot->length);

	return static_cast<cell>(index);
}
コード例 #4
0
// native Trie:TrieCreate();
static cell AMX_NATIVE_CALL TrieCreate(AMX *amx, cell *params)
{
	return static_cast<cell>(TrieHandles.create());
}
コード例 #5
0
ファイル: textparse.cpp プロジェクト: Misiaczek/amxmodx
cell createParser()
{
	return TextParsersHandles.create();
}