[docs]defget_script(name:str,templates:dict[str,str]=None)->str:""" Get the script for the given name and replace templates with the given replacements. :param str name: The name of the script. :param dict[str, str] templates: The templates to replace. """script=os.path.join(os.path.dirname(__file__),"scripts",f"{name}.lua")ifnotos.path.exists(script):raiseFileNotFoundError(f"Script {name} not found.")withopen(script,"r")asf:script=f.read()iftemplates:forkey,valueintemplates.items():script=script.replace(key,value)returnscript
[docs]defto_lua_map(data:dict[str,str])->str:""" Convert a Python dictionary to a Lua map. :param data: The dictionary to convert. """lua_map="{"forkey,valueindata.items():lua_map+=f'"{key}" = "{value}", 'lua_map=lua_map.rstrip(", ")+"}"returnlua_map