Index: code/branches/pch/src/tolua/lua/basic.lua
===================================================================
--- code/branches/pch/src/tolua/lua/basic.lua	(revision 3128)
+++ code/branches/pch/src/tolua/lua/basic.lua	(revision 3129)
@@ -377,6 +377,6 @@
 
 -- called to output an error message
-function output_error_hook(...)
-    return string.format(...)
+function output_error_hook(str, arg)
+    return string.format(str, arg)
 end
 
Index: code/branches/pch/src/tolua/lua/package.lua
===================================================================
--- code/branches/pch/src/tolua/lua/package.lua	(revision 3128)
+++ code/branches/pch/src/tolua/lua/package.lua	(revision 3129)
@@ -42,5 +42,6 @@
                                                return "\n#["..getn(L).."]#"
                                            end
-    )    -- avoid preprocessing embedded C code
+    )
+    -- avoid preprocessing embedded C code
     local C = {}
     self.code = gsub(self.code,"\n%s*%$%<","\3") -- deal with embedded C code
@@ -50,5 +51,6 @@
                                                return "\n#<"..getn(C)..">#"
                                            end
-    )    -- avoid preprocessing embedded C code
+    )
+    -- avoid preprocessing embedded C code
     self.code = gsub(self.code,"\n%s*%$%{","\5") -- deal with embedded C code
     self.code = gsub(self.code,"\n%s*%$%}","\6")
@@ -58,4 +60,5 @@
                                            end
     )
+
     --self.code = gsub(self.code,"\n%s*#[^d][^\n]*\n", "\n\n") -- eliminate preprocessor directives that don't start with 'd'
     self.code = gsub(self.code,"\n[ \t]*#[ \t]*[^d%<%[]", "\n//") -- eliminate preprocessor directives that don't start with 'd'
@@ -68,4 +71,5 @@
                                                          end
     )
+
     -- perform global substitution
 
@@ -90,18 +94,23 @@
                                                     return L[tonumber(n)]
                                                 end
-    )    -- restore embedded C code
+    )
+    -- restore embedded C code
     self.code = gsub(self.code,"%#%<(%d+)%>%#", function (n)
                                                     return C[tonumber(n)]
                                                 end
-    )    -- restore verbatim lines
+    )
+    -- restore verbatim lines
     self.code = gsub(self.code,"%#(%d+)%#", function (n)
                                                 return V[tonumber(n)]
                                             end
     )
+
     self.code = string.gsub(self.code, "\n%s*%$([^\n]+)", function (l)
                                                               Verbatim(l.."\n")
                                                               return "\n"
                                                           end
-    )end
+    )
+end
+
 -- translate verbatim
 function classPackage:preamble ()
@@ -160,5 +169,5 @@
         end
     end)
-    output('}')
+ output('}')
     output('\n')
 end
@@ -189,5 +198,5 @@
     output(pre.."int luaopen_"..self.name.." (lua_State* tolua_S) {")
     output(pre.." return tolua_"..self.name.."_open(tolua_S);")
-    output(pre.."}")
+    output(pre.."};")
     output("#endif\n\n")
 
@@ -202,7 +211,10 @@
 
     if flags.H then
-        local package_lower = string.lower(self.name)        output('#include "'..package_lower..'/'..self.name..'Prereqs.h"\n')        output('/* Exported function */')
+        local package_lower = string.lower(self.name)
+        output('#include "'..package_lower..'/'..self.name..'Prereqs.h"\n')
+        output('/* Exported function */')
         output('_'..self.name..'Export')
-        output('int  tolua_'..self.name..'_open (lua_State* tolua_S);')        output('\n')
+        output('int  tolua_'..self.name..'_open (lua_State* tolua_S);')
+        output('\n')
     end
 end
@@ -219,5 +231,9 @@
     local code = '\n$#include "'..string.lower(flags.n)..'/'..fn..'"\n'
     s= "\n" .. s .. "\n" -- add blank lines as sentinels
-    -- eliminate export macro problems in class declarations    s = gsub(s, ' _%w*Export ', ' ')    local _,e,c,t = strfind(s, "\n([^\n]-)[Tt][Oo][Ll][Uu][Aa]_([^%s]*)[^\n]*\n")
+
+    -- eliminate export macro problems in class declarations
+    s = gsub(s, ' _%w*Export ', ' ')
+
+    local _,e,c,t = strfind(s, "\n([^\n]-)[Tt][Oo][Ll][Uu][Aa]_([^%s]*)[^\n]*\n")
     while e do
         t = strlower(t)
@@ -243,5 +259,15 @@
     if fn then
         local file
-        if flags.f then            if string.sub(flags.f, 1, 1) == '/' or string.sub(flags.f, 1, 1) == '\\' or (string.len(flags.f) > 1 and string.sub(flags.f, 2, 2) == ':') then                file = flags.f            else                file = flags.w..'/'..flags.f            end        else            file = flags.f        end        st, msg = readfrom(flags.f)        if not st then
+        if flags.f then
+            if string.sub(flags.f, 1, 1) == '/' or string.sub(flags.f, 1, 1) == '\\' or (string.len(flags.f) > 1 and string.sub(flags.f, 2, 2) == ':') then
+                file = flags.f
+            else
+                file = flags.w..'/'..flags.f
+            end
+        else
+            file = flags.f
+        end
+        st, msg = readfrom(file)
+        if not st then
             error('#'..msg..' path: '..flags.f)
         end
@@ -263,5 +289,19 @@
     end
 
-    -- prepare working directory    local current_path    if not flags.w and flags.f then        current_path = gsub(flags.f, '(/)[^/]*%.?[^/]*$', '%1')    elseif flags.w then        if not (string.sub(flags.w, string.len(flags.w)) == '/') then            current_path = flags.w..'/'        else            current_path = flags.w        end    else        current_path = ''    end    -- deal with include directive
+    -- prepare working directory
+    local current_path
+    if not flags.w and flags.f then
+        current_path = gsub(flags.f, '(/)[^/]*%.?[^/]*$', '%1')
+    elseif flags.w then
+        if not (string.sub(flags.w, string.len(flags.w)) == '/') then
+            current_path = flags.w..'/'
+        else
+            current_path = flags.w
+        end
+    else
+        current_path = ''
+    end
+
+    -- deal with include directive
     local nsubst
     repeat
@@ -294,5 +334,6 @@
                 end
             end
-        )    until nsubst==0
+        )
+    until nsubst==0
 
     -- deal with renaming directive
@@ -318,18 +359,18 @@
     local chunk = {'local __ret = {"\\n"}\n'}
     for line in file:lines() do
-       if string.find(line, "^##") then
-           table.insert(chunk, string.sub(line, 3) .. "\n")
-       else
-           local last = 1
-           for text, expr, index in string.gfind(line, "(.-)$(%b())()") do 
-               last = index
-               if text ~= "" then
-                   table.insert(chunk, string.format('table.insert(__ret, %q )', text))
-               end
-               table.insert(chunk, string.format('table.insert(__ret, %s )', expr))
-           end
-           table.insert(chunk, string.format('table.insert(__ret, %q)\n',
-                               string.sub(line, last).."\n"))
-       end
+        if string.find(line, "^##") then
+            table.insert(chunk, string.sub(line, 3) .. "\n")
+        else
+            local last = 1
+            for text, expr, index in string.gfind(line, "(.-)$(%b())()") do 
+                last = index
+                if text ~= "" then
+                    table.insert(chunk, string.format('table.insert(__ret, %q )', text))
+                end
+                table.insert(chunk, string.format('table.insert(__ret, %s )', expr))
+            end
+            table.insert(chunk, string.format('table.insert(__ret, %q)\n',
+                                string.sub(line, last).."\n"))
+        end
     end
     table.insert(chunk, '\nreturn table.concat(__ret)\n')
