mirror of
https://github.com/pocketpy/pocketpy
synced 2025-10-20 11:30:18 +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]
|
key = file.split(".")[0]
|
||||||
with open("python/" + file) as f:
|
with open("python/" + file) as f:
|
||||||
value = f.read()
|
value = f.read()
|
||||||
value = value.encode('utf-8').hex()
|
const_array = ','.join([str(b) for b in value.encode('utf-8')])
|
||||||
new_value = []
|
sources[key] = '(const char[]){' + const_array + '}'
|
||||||
for i in range(0, len(value), 2):
|
|
||||||
new_value.append("\\x" + value[i:i+2])
|
|
||||||
sources[key] = "".join(new_value)
|
|
||||||
|
|
||||||
header = '''#pragma once
|
header = '''#pragma once
|
||||||
// generated by prebuild.py
|
// generated by prebuild.py
|
||||||
@ -21,17 +18,12 @@ def generate_python_sources():
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace pkpy{
|
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():
|
for key, value in sources.items():
|
||||||
CHAR_LIMIT = 5000
|
header += f' {{ "{key}", {value} }},\n'
|
||||||
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 += '''
|
header += ''' };
|
||||||
};
|
|
||||||
} // namespace pkpy
|
} // namespace pkpy
|
||||||
'''
|
'''
|
||||||
return header
|
return header
|
||||||
|
Loading…
x
Reference in New Issue
Block a user