Refactor luagenerator

- cleaned up the generation
- created special class to handle the serialization
- improved string escaping: Replace OS Path separator with normal slash and allow the usage of a single quote in unit names by changing the delimiter to double quote instead (1797)
- adjusted unit_name generation to prevent scripting errors with unescaped characters
This commit is contained in:
RndName
2021-06-27 17:46:39 +02:00
parent 8f16f242b1
commit 138e48dc2d
3 changed files with 224 additions and 197 deletions

View File

@@ -466,3 +466,11 @@ def interpolate(value1: float, value2: float, factor: float, clamp: bool) -> flo
def dcs_to_shapely_point(point: Point) -> ShapelyPoint:
return ShapelyPoint(point.x, point.y)
def escape_string_for_lua(value: str) -> str:
"""Escapes special characters from a string.
This prevents scripting errors in lua scripts"""
value = value.replace('"', "'") # Replace Double Quote as this is the delimiter
value = value.replace(os.sep, "/") # Replace Backslash as path separator
return "{0}".format(value)