Skip to content

Commit

Permalink
added switch cases to StageLuaParse
Browse files Browse the repository at this point in the history
hope this helps Jank!!
  • Loading branch information
BombasticTom committed May 26, 2024
1 parent e5071f6 commit 0d077f3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 17 deletions.
1 change: 1 addition & 0 deletions psychtobase/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@ def convert(psych_mod_folder, result_folder, options):
luaProps = StageLuaParse.parseStage(stageLua)
except Exception as e:
logging.error(f'Could not complete parsing of {stageLua}: {e}')
continue

logging.info(f'Converting Stage JSON')
stageJSONConverted = json.dumps(StageTool.convert(stageJSON, os.path.basename(asset), luaProps), indent=4)
Expand Down
40 changes: 23 additions & 17 deletions psychtobase/src/tools/StageLuaParse.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,37 +28,43 @@ def parseStage(lua_script_path):
logging.error(f'Couldn\'t get the current Function name: {e}')
else:
curFunc = None
if calls.get(curFunc, None) == None:

if not curFunc in calls:
calls[curFunc] = {}

if isinstance(node, Call):
try:
if node.func.id in allowedMethods and curFunc in allowedFuncs:
arguments = [node.func.id]

for arg in node.args:
#idk what this used to do but i know how to make switch cases so
#hopefully it does the same thing
try:
if isinstance(arg, String):
arguments.append(arg.s)
elif isinstance(arg, Number):
arguments.append(arg.n)
elif isinstance(arg, Name):
arguments.append(arg.id)
elif isinstance(arg, UMinusOp):
arguments.append('-' + str(arg.operand.n))
elif isinstance(arg, FalseExpr):
arguments.append(False)
elif isinstance(arg, TrueExpr):
arguments.append(True)
else:
logging.warn(f'Unsupported type of lua node: {type(arg)}')
match(type(arg)):
case ast.String:
arguments.append(arg.s)
case ast.Number:
arguments.append(arg.n)
case ast.Name:
arguments.append(arg.id)
case ast.UMinusOp:
arguments.append('-' + str(arg.operand.n))
case ast.FalseExpr:
arguments.append(False)
case ast.TrueExpr:
arguments.append(True)
case _:
logging.warn(f'Unsupported type of lua node: {type(arg)}')

except Exception as e:
logging.error(f'Could not append arguments of this call: {e}')
if calls[curFunc].get(node.func.id, None) == None:

if not node.func.id in calls[curFunc]:
calls[curFunc][node.func.id] = []

calls[curFunc][node.func.id].append(arguments)

except Exception as e:
logging.error(f'Failed to asign arguments of this call: {e}')

Expand Down

0 comments on commit 0d077f3

Please sign in to comment.