def luaquote(string):
    """Quotes a python string as a Lua string literal."""
    replacements = [
        ('\\', '\\\\'),
        ('\'', '\\\''),
        ('\n', '\\n'),
    ]
    for old, new in replacements:
        string = string.replace(old, new)
    return '\'' + string + '\''