Luce packages
LuceLuce BaseLuciaOS

dymokomi/luced-2d

Source of release 0.5.0

0.5.0 / tools / embed_api.py

#!/usr/bin/env python3
"""Embed scripting/luced.luc — the scripting API a script imports — and
scripting/luce.tmLanguage.json — the Script editor's highlighting, luced's
Luce grammar — into src/script_api_text.luc as string constants. The editor
writes the API beside each script it runs. Run after changing either.

    python3 tools/embed_api.py
"""
from pathlib import Path

root = Path(__file__).resolve().parent.parent


def literal(path):
    source = (root / 'scripting' / path).read_text(encoding='utf-8')
    return '"' + source.replace('\\', '\\\\').replace('"', '\\"').replace('\n', '\\n').replace('\t', '\\t') + '"'


text = ('## Generated by tools/embed_api.py from scripting/; do not edit.\n'
        '## The scripting API module every script imports as `luced`.\n'
        f'pub let api_source: str = {literal("luced.luc")}\n\n'
        '## The Luce grammar the Script editor highlights with.\n'
        f'pub let grammar_source: str = {literal("luce.tmLanguage.json")}\n')
(root / 'src' / 'script_api_text.luc').write_text(text, encoding='utf-8')
print('wrote src/script_api_text.luc')