mirror of
https://github.com/Redot-Engine/redot-engine.git
synced 2025-12-06 15:21:56 -05:00
SCons: Add method to generate raw cstrings
This commit is contained in:
@@ -1,25 +1,9 @@
|
||||
"""Functions used to generate source files during build time"""
|
||||
|
||||
import os.path
|
||||
from typing import Iterable, Optional
|
||||
from typing import Optional
|
||||
|
||||
from methods import print_error
|
||||
|
||||
|
||||
def generate_inline_code(input_lines: Iterable[str], insert_newline: bool = True):
|
||||
"""Take header data and generate inline code
|
||||
|
||||
:param: input_lines: values for shared inline code
|
||||
:return: str - generated inline value
|
||||
"""
|
||||
output = []
|
||||
for line in input_lines:
|
||||
if line:
|
||||
output.append(",".join(str(ord(c)) for c in line))
|
||||
if insert_newline:
|
||||
output.append("%s" % ord("\n"))
|
||||
output.append("0")
|
||||
return ",".join(output)
|
||||
from methods import print_error, to_raw_cstring
|
||||
|
||||
|
||||
class RDHeaderStruct:
|
||||
@@ -127,13 +111,13 @@ def build_rd_header(
|
||||
|
||||
if header_data.compute_lines:
|
||||
body_parts = [
|
||||
"static const char _compute_code[] = {\n%s\n\t\t};" % generate_inline_code(header_data.compute_lines),
|
||||
"static const char _compute_code[] = {\n%s\n\t\t};" % to_raw_cstring(header_data.compute_lines),
|
||||
f'setup(nullptr, nullptr, _compute_code, "{out_file_class}");',
|
||||
]
|
||||
else:
|
||||
body_parts = [
|
||||
"static const char _vertex_code[] = {\n%s\n\t\t};" % generate_inline_code(header_data.vertex_lines),
|
||||
"static const char _fragment_code[] = {\n%s\n\t\t};" % generate_inline_code(header_data.fragment_lines),
|
||||
"static const char _vertex_code[] = {\n%s\n\t\t};" % to_raw_cstring(header_data.vertex_lines),
|
||||
"static const char _fragment_code[] = {\n%s\n\t\t};" % to_raw_cstring(header_data.fragment_lines),
|
||||
f'setup(_vertex_code, _fragment_code, nullptr, "{out_file_class}");',
|
||||
]
|
||||
|
||||
@@ -211,7 +195,7 @@ def build_raw_header(
|
||||
#define {out_file_ifdef}_RAW_H
|
||||
|
||||
static const char {out_file_base}[] = {{
|
||||
{generate_inline_code(header_data.code, insert_newline=False)}
|
||||
{to_raw_cstring(header_data.code)}
|
||||
}};
|
||||
#endif
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user