blueloveTH 1 год назад
Родитель
Сommit
c60fdd29ab
2 измененных файлов с 5 добавлено и 14 удалено
  1. 0 1
      include/pocketpy/_generated.h
  2. 5 13
      prebuild.py

Разница между файлами не показана из-за своего большого размера
+ 0 - 1
include/pocketpy/_generated.h


+ 5 - 13
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()
-            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
     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
-        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
 }   // namespace pkpy
 '''
 '''
     return header
     return header

Некоторые файлы не были показаны из-за большого количества измененных файлов