-- use like this: local err, res = parseToURLArgs() -- thanks golang for this idea function parseToURLArgs(tb) function Err(err) return err, nil end function Ok(res) return nil, res end -- err checking if not tb then return Err('got nothing') end if type(tb) ~= 'table' then return Err('expected table, got '..type(tb)) end local str = '?' local index = 1 for key, value in pairs(tb) do if index == 1 then str = str..key..'='..t(value) else str = str..'&'..key..'='..t(value) end index = index + 1 end return Ok(str) end