Advertisement
Cjreek

ModRequire (VBScript)

Jan 17th, 2017
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Set rex = New RegExp
  2. rex.IgnoreCase = True
  3. rex.Global = True
  4. rex.Pattern = "((?:require(?:\(|\ )(?:\""|\'))(.+)(?:\""|\')(?:\))?)"
  5.  
  6. Set fso = CreateObject("Scripting.FileSystemObject")
  7. basedir = fso.GetParentFolderName(fso.GetAbsolutePathName(WScript.Arguments(1))) & "\"
  8.  
  9. Sub parsefile(path, outfile)
  10.     Set inFile = fso.GetFile(path)
  11.     Set inStream = inFile.OpenAsTextStream(1, -2)
  12.    
  13.     Do Until inStream.AtEndOfStream
  14.         strLine = inStream.ReadLine
  15.        
  16.         Set matches = rex.Execute(strLine)
  17.         If (matches.Count > 0)  Then
  18.             Set match = matches(0)
  19.             splitArr = Split(strLine, match.SubMatches(0))
  20.             outfile.WriteLine(splitArr(0) & "(function()" & vbCrLf)
  21.            
  22.             requFilePath = basedir & Replace(match.SubMatches(1), ".", "\") & ".lua"
  23.             parsefile requFilePath, outfile
  24.  
  25.             outfile.WriteLine(vbCrLf & "end)() " & splitArr(1))
  26.         Else
  27.            outFile.WriteLine(strLine)
  28.         End If
  29.     Loop
  30.     inStream.Close
  31. End Sub
  32.  
  33.  
  34. Set outFile = fso.CreateTextFile(WScript.Arguments(1), True)
  35. parsefile WScript.Arguments(0), outFile
  36. outFile.Close
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement