--beware this function does not allow "holes" in the table
function tableLength(atable)
	if atable==nil then
		return 0
	end
	local maxn=1
	while true do
		if atable[maxn]==nil then
			return maxn-1
		else
			maxn=maxn+1
		end
	end 	
end

function getMemoryInfo()
	return math.floor(System.getFreeMemory() / 1024).. " kb free"
end

function matchString(astring, apattern)
	return string.find(astring, apattern)
end

--function insertIntoTable(atable, anelement)
--	return tinsert(atable, anelement)
--end

function GC()
	collectgarbage()
end

--function getTextSize(afont, amessage)
--	
--end

function stringSize(astring)
	return string.len(astring)
end

function getFolderList(dir)
	local lfiles = System.listDirectory(dir)
	local directories = {}
	local lfi=1
	local di=1
	
	for lfi=1,tableLength(lfiles) do
		if lfiles[lfi].directory then --it is a directory
			if lfiles[lfi].name~="." and lfiles[lfi].name~=".." then
				directories[di]=lfiles[lfi].name
				di=di+1
			end
		end
	end
	return directories
end

function getFileList(dir)
	local lfiles = System.listDirectory(dir)
	local allfiles = {}
	local lfi=1
	local fi=1
	for lfi=1,tableLength(lfiles) do
		if lfiles[lfi].directory then --it is a directory
			--nothing
		else
			allfiles[fi]=lfiles[lfi].name
			fi=fi+1
		end
	end
	return allfiles
end

function getSnapshotFolder()
	return GAMEPREF["snapshotFolder"]
end
