title: lua recursion vs python recursion
body: <p>I wrote a simple program to learn the basics of lua but it created a stack overflow. Writing the exact same program in python though did the job perfectly. 
  Lua code:</p>
  
  <pre><code>function tprint (tbl, indent)
    if not indent then indent = 0 end
    for k, v in pairs(tbl) do
      formatting = string.rep("  ", indent) .. k .. ": "
      if type(v) == "table" then
        print(formatting)
        tprint(v, indent+1)
      else
        print(formatting .. v)
      end
    end
  end
  
  function encryptNumber(num)
      return 3 * num + 2
  end
  
  function decryptNumber(num)
      return (num - 2) / 3
  end
  
  function encryptString(str)
      enstr = ""
      for i = 1,string.len(str) do
          enstr = enstr..string.char((string.byte(str,i) + 19) % 255)
      end
      return enstr
  end
  
  function decryptString(str)
      destr = ""
      for i = 1,string.len(str) do
          destr = destr..string.char((string.byte(str,i) - 19) % 255)
      end
      return destr
  end
  
  function encryptTable(t)
      newt = {}
      for i,j in pairs(t) do
          newi = encrypt(i)
          newj = encrypt(j)
          newt[newi] = newj
      end
      return newt
  end
  
  function decryptTable(t)
      newt = {}
      for i,j in pairs(t) do
          newi = decrypt(i)
          newj = decrypt(j)
          newt[newi] = newj
      end
      return newt
  end
  
  function encrypt(obj)
      if type(obj) == "number" then
          return encryptNumber(obj)
      end
      if type(obj) == "string" then
          return encryptString(obj)
      end
      if type(obj) == "table" then
          retval = encryptTable(obj)
          return retval
      end
  end
  
  function decrypt(obj)
      if type(obj) == "number" then
          return decryptNumber(obj)
      end
      if type(obj) == "string" then
          return decryptString(obj)
      end
      if type(obj) == "table" then
          retval = decryptTable(obj)
          return retval
      end
  end
  
  test = {1, {'a'}, '3'}
  tprint(test)
  tprint(encrypt(test))
  tprint(decrypt(encrypt(test)))
  </code></pre>
  
  <p>The same exact code in python that works perfectly well:</p>
  
  <pre><code>def encryptNumber(num):
      return 3 * num + 2
  
  
  def decryptNumber(num):
      return (num - 2) / 3
  
  
  def encryptString(str):
      enstr = ""
      for i in range(len(str)): 
          enstr = enstr + chr((ord(str[i]) + 19) % 255)
      return enstr
  
  
  def decryptString(str):
      destr = ""
      for i in range(len(str)): 
          destr = destr + chr((ord(str[i]) - 19) % 255)
      return destr
  
  
  def encryptTable(t):
      newt = {}
      for i in t: 
          newi = encrypt(i)
          newj = encrypt(t[i])
          newt[newi] = newj
      return newt
  
  
  def decryptTable(t):
      newt = {}
      for i in t: 
          newi = decrypt(i)
          newj = decrypt(t[i])
          newt[newi] = newj
      return newt
  
  
  def encrypt(obj):
      if type(obj) == int:
          return encryptNumber(obj)
  
      if type(obj) == str:
          return encryptString(obj)
  
      if type(obj) == dict:
          return encryptTable(obj)
  
  
  
  def decrypt(obj):
      if type(obj) == int:
          return decryptNumber(obj)
  
      if type(obj) == str:
          return decryptString(obj)
  
      if type(obj) == dict:
          return decryptTable(obj)
  
  test = {2: {1:2}, 1: {'a': {'c':'d'}}}
  print test
  print encrypt(test)
  print decrypt(encrypt(test))
  </code></pre>
  
  <p>is there a difference between recursion in lua vs recursion in python and the problem exists because of that? Or is the logic mistaken?</p>