|
@@ -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()
|
|
|
|
|
- const_array = ','.join([str(b) for b in value.encode('utf-8')])
|
|
|
|
|
- sources[key] = '(const char[]){' + const_array + '}'
|
|
|
|
|
|
|
+ # convert to char array (signed)
|
|
|
|
|
+ for c in f.read().encode('utf-8'):
|
|
|
|
|
+ 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'
|