lua对象序列化

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

function serialize( pTable )
	local tp = type( pTable )
	if tp == 'string' then
		return string.format( '%q', pTable )
	elseif tp ~= 'table' then
		return tostring( pTable )
	end
	local kvPairs = {}
	local ks, vs
	for k, v in pairs( pTable ) do
		tp = type( k )
		vs = serialize( v )
		if vs == nil then return end
		ks = tp == 'number' and string.format( '[%d]', k ) or string.format( '["%s"]', k )
		table.insert( kvPairs, ks .. '=' .. vs )
	end
	return "{" .. table.concat( kvPairs, ',' ) .. "}"
end