mirror of
https://github.com/Sei-Lisa/LSL-PyOptimizer
synced 2024-11-21 14:18:57 -07:00
Add command-line options to change default builtins and SEF table files.
This commit is contained in:
parent
2d78239d23
commit
0af2349ef9
2 changed files with 23 additions and 6 deletions
|
@ -2668,13 +2668,19 @@ list lazy_list_set(list L, integer i, list v)
|
|||
|
||||
return self.parse(script, options)
|
||||
|
||||
def __init__(self, builtins = 'builtins.txt', seftable = 'seftable.txt'):
|
||||
def __init__(self, builtins = None, seftable = None):
|
||||
"""Reads the library."""
|
||||
|
||||
self.events = {}
|
||||
self.constants = {}
|
||||
self.funclibrary = {}
|
||||
|
||||
if builtins is None:
|
||||
builtins = lslcommon.DataPath + 'builtins.txt'
|
||||
|
||||
if seftable is None:
|
||||
seftable = lslcommon.DataPath + 'seftable.txt'
|
||||
|
||||
self.parse_directive_re = None
|
||||
|
||||
# Library read code
|
||||
|
@ -2694,7 +2700,7 @@ list lazy_list_set(list L, integer i, list v)
|
|||
parse_num_re = re.compile(r'^\s*(-?(?=[0-9]|\.[0-9])[0-9]*((?:\.[0-9]*)?(?:[Ee][+-]?[0-9]+)?))\s*$')
|
||||
parse_str_re = re.compile(ur'^"((?:[^"\\]|\\.)*)"$')
|
||||
|
||||
f = open(lslcommon.DataPath + builtins, 'rb')
|
||||
f = open(builtins, 'rb')
|
||||
try:
|
||||
linenum = 0
|
||||
try:
|
||||
|
@ -2850,7 +2856,7 @@ list lazy_list_set(list L, integer i, list v)
|
|||
# that includes domain data (min, max) and possibly input
|
||||
# parameter transformations e.g.
|
||||
# llSensor(..., PI, ...) -> llSensor(..., 4, ...).
|
||||
f = open(lslcommon.DataPath + seftable, 'rb')
|
||||
f = open(seftable, 'rb')
|
||||
try:
|
||||
while True:
|
||||
line = f.readline()
|
||||
|
|
17
main.py
17
main.py
|
@ -172,6 +172,8 @@ Usage: {progname}
|
|||
[-h|--help] print this help
|
||||
[--version] print this program's version
|
||||
[-o|--output=<filename>] output to file rather than stdout
|
||||
[-b|--builtins=<filename>] use a builtins file other than builtins.txt
|
||||
[-S|--seftable=<filename>] use a SEF table file other than seftable.txt
|
||||
[-H|--header] add the script as a comment in Firestorm format
|
||||
[-T|--timestamp] add a timestamp as a comment at the beginning
|
||||
[-y|--python-exceptions] when an exception is raised, show a stack trace
|
||||
|
@ -343,11 +345,12 @@ def main(argv):
|
|||
% (b"', '".join(options - validoptions)).decode('utf8'))
|
||||
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(argv[1:], 'hO:o:p:P:HTy',
|
||||
opts, args = getopt.gnu_getopt(argv[1:], 'hO:o:p:P:HTyb:S:',
|
||||
('optimizer-options=', 'help', 'version', 'output=', 'header',
|
||||
'timestamp','python-exceptions',
|
||||
'preproc=', 'precmd=', 'prearg=', 'prenodef', 'preshow',
|
||||
'avid=', 'avname=', 'assetid=', 'shortname='))
|
||||
'avid=', 'avname=', 'assetid=', 'shortname=', 'builtins='
|
||||
'seftable='))
|
||||
except getopt.GetoptError as e:
|
||||
Usage(argv[0])
|
||||
sys.stderr.write(u"\nError: " + str(e).decode('utf8') + u"\n")
|
||||
|
@ -366,6 +369,8 @@ def main(argv):
|
|||
mcpp_mode = False
|
||||
preshow = False
|
||||
raise_exception = False
|
||||
builtins = None
|
||||
seftable = None
|
||||
|
||||
for opt, arg in opts:
|
||||
if type(opt) is unicode:
|
||||
|
@ -409,6 +414,12 @@ def main(argv):
|
|||
elif opt in ('-o', '--output'):
|
||||
outfile = arg
|
||||
|
||||
elif opt in ('-b', '--builtins'):
|
||||
builtins = arg
|
||||
|
||||
elif opt in ('-S', '--seftable'):
|
||||
seftable = arg
|
||||
|
||||
elif opt in ('-y', '--python-exceptions'):
|
||||
raise_exception = True
|
||||
|
||||
|
@ -597,7 +608,7 @@ def main(argv):
|
|||
|
||||
if not preshow:
|
||||
|
||||
p = parser()
|
||||
p = parser(builtins, seftable)
|
||||
try:
|
||||
ts = p.parse(script, options)
|
||||
except EParse as e:
|
||||
|
|
Loading…
Reference in a new issue