Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Module:ValueToString( v )
- if "string" == type( v ) then
- v = string.gsub( v, "\n", "\\n" )
- if string.match( string.gsub(v,"[^'\"]",""), '^"+$' ) then
- return "'" .. v .. "'"
- end
- return '"' .. string.gsub(v,'"', '\\"' ) .. '"'
- else
- return "table" == type( v ) and self:TableToString( v ) or tostring( v )
- end
- end
- function Module:KeyToString( k )
- if "string" == type( k ) and string.match( k, "^[_%a][_%a%d]*$" ) then
- return k
- else
- return "[" .. self:ValueToString( k ) .. "]"
- end
- end
- function Module:TableToString( tbl )
- if not tbl then return "nil" end
- local result, done = {}, {}
- for k, v in ipairs( tbl ) do
- table.insert( result, self:ValueToString( v ) )
- done[ k ] = true
- end
- for k, v in pairs( tbl ) do
- if not done[ k ] then
- table.insert( result,
- self:KeyToString( k ) .. "=" .. self:ValueToString( v ) )
- end
- end
- return "{" .. table.concat( result, "," ) .. "}"
- end
Advertisement
Add Comment
Please, Sign In to add comment