#!/usr/bin/python

from __future__ import print_function
import sys
import os

indentsize = int(sys.argv[1].split('=')[1])

line = sys.stdin.readline()
indent = 0
nextindent = 0
last_line = None
while line:
  line = line.strip()
  if(line.startswith('if') or line.startswith('for') or line.startswith('while') or line.startswith('function')
      or line.startswith('local function') or line.find(' = function(') >= 0):
    nextindent += 1
  elif line.startswith('elseif') or line.startswith('else'):
    indent -= 1
  if line.startswith('end') or line.endswith('end'):
    indent -= 1
    nextindent -= 1
  # handle brackets...
  nextindent += line.count('(') - line.count(')')
  sys.stdout.write(' ' * (indentsize * indent) + line + '\n')
  indent = nextindent
  last_line = line
  line = sys.stdin.readline()
if last_line != '':
  sys.stdout.write('\n')


@@ -228,15 +228,170 @@
 )%0A  
-if(line
+comment_pos = line.find('--')%0A  if comment_pos %3E= 0:%0A    pc = line%5B:comment_pos%5D%0A    comments = line%5Bcomment_pos:%5D%0A  else:%0A    pc = line%0A    comments = ''%0A  if(pc
 .sta
@@ -399,36 +399,34 @@
 tswith('if') or 
-line
+pc
 .startswith('for
@@ -427,28 +427,26 @@
 h('for') or 
-line
+pc
 .startswith(
@@ -453,28 +453,26 @@
 'while') or 
-line
+pc
 .startswith(
@@ -488,28 +488,26 @@
 ')%0A      or 
-line
+pc
 .startswith(
@@ -527,20 +527,18 @@
 on') or 
-line
+pc
 .find(' 
@@ -585,20 +585,18 @@
 %0A  elif 
-line
+pc
 .startsw
@@ -612,20 +612,18 @@
 if') or 
-line
+pc
 .startsw
@@ -656,20 +656,18 @@
  1%0A  if 
-line
+pc
 .startsw
@@ -680,20 +680,18 @@
 nd') or 
-line
+pc
 .endswit
@@ -775,20 +775,18 @@
 dent += 
-line
+pc
 .count('
@@ -791,20 +791,18 @@
 ('(') - 
-line
+pc
 .count('
@@ -854,20 +854,29 @@
 dent) + 
-line
+pc + comments
  + '%5Cn')

handle comments