This commit is contained in:
blueloveTH 2024-03-24 17:48:19 +08:00
parent c60fdd29ab
commit efc5755d78
2 changed files with 25 additions and 18 deletions

File diff suppressed because one or more lines are too long

View File

@ -6,10 +6,17 @@ def generate_python_sources():
if not file.endswith(".py"): if not file.endswith(".py"):
continue continue
key = file.split(".")[0] key = file.split(".")[0]
const_char_array = []
with open("python/" + file) as f: with open("python/" + file) as f:
value = f.read() # convert to char array (signed)
const_array = ','.join([str(b) for b in value.encode('utf-8')]) for c in f.read().encode('utf-8'):
sources[key] = '(const char[]){' + const_array + '}' if c < 128:
const_char_array.append(str(c))
else:
const_char_array.append(str(c - 256))
const_char_array.append('0')
const_char_array = ','.join(const_char_array)
sources[key] = '(const char[]){' + const_char_array + '}'
header = '''#pragma once header = '''#pragma once
// generated by prebuild.py // generated by prebuild.py
@ -18,7 +25,7 @@ def generate_python_sources():
#include <string> #include <string>
namespace pkpy{ namespace pkpy{
inline const std::map<std::string, const char*> kPythonLibs = { inline std::map<std::string, const char*> kPythonLibs = {
''' '''
for key, value in sources.items(): for key, value in sources.items():
header += f' {{ "{key}", {value} }},\n' header += f' {{ "{key}", {value} }},\n'