This repository has been archived by the owner on May 23, 2023. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Python script to prepare a lua code for reloading
Removes all comments and escapes '<'. Usage: cd courseplay\reload python reload.py ..\mode6.lua Then, in the dev console: cpLoadFile reload.xml
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,10 @@ | |
*.gitattributes | ||
*.idea | ||
*.iml | ||
out | ||
reload/venv | ||
reload.xml | ||
|
||
|
||
# Windows image file caches | ||
Thumbs.db | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import sys | ||
import os | ||
|
||
|
||
def escape_and_write(outfile, c): | ||
if c == '<': | ||
outfile.write('<') | ||
else: | ||
outfile.write(c) | ||
|
||
|
||
def read_until_end_of_comment(infile, outfile): | ||
c =infile.read(1) | ||
if c == '-': | ||
# this is the second - character, start of a comment | ||
in_block_comment = False | ||
while c and (in_block_comment or not c == '\n'): | ||
prevC = c | ||
c = infile.read(1) | ||
if c == '[' and prevC == '[': | ||
in_block_comment = True | ||
if c == ']' and prevC == ']': | ||
in_block_comment = False | ||
else: | ||
# write the - which triggered this call | ||
escape_and_write(outfile, '-') | ||
# and write the character we read afterwards (non -) | ||
escape_and_write(outfile, c) | ||
|
||
|
||
luaFile = sys.argv[1] | ||
dirName = os.path.dirname(luaFile) | ||
|
||
in_string = False | ||
open_string = '' | ||
|
||
with open(luaFile, mode='r') as infile, open('../reload.xml', 'w') as outfile: | ||
outfile.write('<code>') | ||
while True: | ||
c = infile.read(1) | ||
if not c: | ||
break | ||
if c == '"' or c == "'": | ||
if not in_string: | ||
open_string = c | ||
in_string = True | ||
elif open_string == c: | ||
in_string = False | ||
|
||
if c == '-' and not in_string: | ||
read_until_end_of_comment(infile, outfile) | ||
else: | ||
escape_and_write(outfile, c) | ||
|
||
outfile.write('</code>') |