Other minor fixes to lslloadlib

Fix many comparisons of unicode to str.
This commit is contained in:
Sei Lisa 2023-01-09 11:12:20 +01:00
parent e3c1634724
commit 8e20a06912

View file

@ -84,18 +84,18 @@ def LoadLibrary(builtins = None, fndata = None):
if match.group(1): if match.group(1):
# event or function # event or function
typ = match.group(1) typ = match.group(1)
if typ == 'quaternion': if typ == u'quaternion':
typ = 'rotation' typ = u'rotation'
if typ == 'void': if typ == u'void':
typ = None typ = None
elif typ != 'event' and typ not in types: elif typ != u'event' and typ not in types:
warning(u"Invalid type in %s, line %d: %s" warning(u"Invalid type in %s, line %d: %s"
% (ubuiltins, linenum, typ)) % (ubuiltins, linenum, typ))
continue continue
args = [] args = []
arglist = match.group(3) arglist = match.group(3)
if arglist: if arglist:
arglist = arglist.split(',') arglist = arglist.split(u',')
bad = False bad = False
for arg in arglist: for arg in arglist:
argtyp = parse_arg_re.search(arg).group(1) argtyp = parse_arg_re.search(arg).group(1)
@ -108,7 +108,7 @@ def LoadLibrary(builtins = None, fndata = None):
if bad: if bad:
continue continue
name = match.group(2) name = match.group(2)
if typ == 'event': if typ == u'event':
if name in events: if name in events:
warning(u"Event at line %d was already defined in %s," warning(u"Event at line %d was already defined in %s,"
u" overwriting: %s" u" overwriting: %s"
@ -139,14 +139,14 @@ def LoadLibrary(builtins = None, fndata = None):
warning(u"Invalid type in %s, line %d: %s" warning(u"Invalid type in %s, line %d: %s"
% (ubuiltins, linenum, typ)) % (ubuiltins, linenum, typ))
continue continue
if typ == 'quaternion': if typ == u'quaternion':
typ = 'rotation' typ = u'rotation'
value = match.group(6) value = match.group(6)
if typ == 'integer': if typ == u'integer':
value = int(value, 0) value = int(value, 0)
elif typ == 'float': elif typ == u'float':
value = lslfuncs.F32(float(value)) value = lslfuncs.F32(float(value))
elif typ == 'string': elif typ == u'string':
if parse_str_re.search(value): if parse_str_re.search(value):
esc = False esc = False
tmp = value[1:-1] tmp = value[1:-1]
@ -169,15 +169,15 @@ def LoadLibrary(builtins = None, fndata = None):
warning(u"Invalid string in %s line %d: %s" warning(u"Invalid string in %s line %d: %s"
% (ubuiltins, linenum, line)) % (ubuiltins, linenum, line))
value = None value = None
elif typ == 'key': elif typ == u'key':
warning(u"Key constants not supported in %s, line %d: %s" warning(u"Key constants not supported in %s, line %d: %s"
% (ubuiltins, linenum, line)) % (ubuiltins, linenum, line))
value = None value = None
elif typ in ('vector', 'rotation'): elif typ in (u'vector', u'rotation'):
try: try:
if value[0:1] != '<' or value[-1:] != '>': if value[0:1] != u'<' or value[-1:] != u'>':
raise ValueError raise ValueError
value = value[1:-1].split(',') value = value[1:-1].split(u',')
if len(value) != (3 if typ == 'vector' else 4): if len(value) != (3 if typ == 'vector' else 4):
raise ValueError raise ValueError
num = parse_fp_re.search(value[0]) num = parse_fp_re.search(value[0])
@ -192,7 +192,7 @@ def LoadLibrary(builtins = None, fndata = None):
if not num: if not num:
raise ValueError raise ValueError
value[2] = lslfuncs.F32(float(num.group(1))) value[2] = lslfuncs.F32(float(num.group(1)))
if typ == 'vector': if typ == u'vector':
value = Vector(value) value = Vector(value)
else: else:
num = parse_fp_re.search(value[3]) num = parse_fp_re.search(value[3])
@ -204,8 +204,8 @@ def LoadLibrary(builtins = None, fndata = None):
warning(u"Invalid vector/rotation syntax in %s" warning(u"Invalid vector/rotation syntax in %s"
u" line %d: %s" % (ubuiltins, linenum, line)) u" line %d: %s" % (ubuiltins, linenum, line))
else: else:
assert typ == 'list' assert typ == u'list'
if value[0:1] != '[' or value[-1:] != ']': if value[0:1] != u'[' or value[-1:] != u']':
warning(u"Invalid list value in %s, line %d: %s" warning(u"Invalid list value in %s, line %d: %s"
% (ubuiltins, linenum, line)) % (ubuiltins, linenum, line))
elif value[1:-1].strip() != '': elif value[1:-1].strip() != '':