title: How to add function output to a variable using luasql
body: <p>I am trying to assign the output of a function to a variable, but I can’t do it. :(</p>
  
  <p>I use <strong>Lua 5.3.4</strong> and <strong>luarocks 3.2.1</strong> (+<strong>luasql-postgres</strong>)</p>
  
  <p>My script:</p>
  
  <pre><code>luasql = require "luasql.postgres"
  value=arg[1]
  current_time=os.date("%Y-%m-%d %H:%M:%S")
  env = luasql.postgres()
  con = assert (env:connect('postgres', 'postgres', 'postgres', '192.168.241.93','5432'))
  
  function printvalues(res)
      row = res:fetch ({}, "a")
      while row do
              print(string.format("%-12s", row.client_addr))
              row = res:fetch (row, "a")
      end
      print()
  end
  
  res = assert (con:execute('select client_addr from pg_stat_replication order by replay_lag asc limit 1'))
  
  
  --txn = res
  a = {myfunc = printvalues(res)}
  
  if a == '192.168.242.41' then
  print("backend1")
  elseif a == '192.168.241.76' then
  print("backend2")
  end
  
  print(string.format("%-12s",a))
  print(a)
  </code></pre>
  
  <p>Script result:</p>
  
  <pre><code>root@haproxy:/etc/haproxy# lua scripts/test.lua
  192.168.1.76
  
  table: 0x559fadf97080
  table: 0x559fadf97080
  </code></pre>
  
  <p>Please tell me:</p>
  
  <ol>
  <li><p>How can I assign the result of a function to a variable?</p></li>
  <li><p>How to remove the empty line in the output of the function <strong>printvalues(res)</strong></p></li>
  </ol>