mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-19 19:10:17 +00:00
update prebuild.py
This commit is contained in:
parent
881fbb01dd
commit
c60fdd29ab
File diff suppressed because one or more lines are too long
18
prebuild.py
18
prebuild.py
@ -8,11 +8,8 @@ def generate_python_sources():
|
||||
key = file.split(".")[0]
|
||||
with open("python/" + file) as f:
|
||||
value = f.read()
|
||||
value = value.encode('utf-8').hex()
|
||||
new_value = []
|
||||
for i in range(0, len(value), 2):
|
||||
new_value.append("\\x" + value[i:i+2])
|
||||
sources[key] = "".join(new_value)
|
||||
const_array = ','.join([str(b) for b in value.encode('utf-8')])
|
||||
sources[key] = '(const char[]){' + const_array + '}'
|
||||
|
||||
header = '''#pragma once
|
||||
// generated by prebuild.py
|
||||
@ -21,17 +18,12 @@ def generate_python_sources():
|
||||
#include <string>
|
||||
|
||||
namespace pkpy{
|
||||
inline static std::map<std::string, const char*> kPythonLibs = {
|
||||
inline const std::map<std::string, const char*> kPythonLibs = {
|
||||
'''
|
||||
for key, value in sources.items():
|
||||
CHAR_LIMIT = 5000
|
||||
value = ['"' + value[i:i+CHAR_LIMIT] + '" ' for i in range(0, len(value), CHAR_LIMIT)]
|
||||
value = ''.join(value)
|
||||
header += ' '*8 + '{"' + key + '", ' + value + '},'
|
||||
header += '\n'
|
||||
header += f' {{ "{key}", {value} }},\n'
|
||||
|
||||
header += '''
|
||||
};
|
||||
header += ''' };
|
||||
} // namespace pkpy
|
||||
'''
|
||||
return header
|
||||
|
Loading…
x
Reference in New Issue
Block a user