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