* A few modification needs to be made to glue.cpp because of limitations * of the IDL language/binder.
(cb)
| 57 | * of the IDL language/binder. |
| 58 | */ |
| 59 | function patchGlueCppFile(cb) { |
| 60 | var file = 'Bindings/glue.cpp'; |
| 61 | var classesToErase = [ |
| 62 | 'ArbitraryResourceWorkerJS', |
| 63 | 'AbstractFileSystemJS', |
| 64 | 'BehaviorJsImplementation', |
| 65 | 'ObjectJsImplementation', |
| 66 | 'BehaviorSharedDataJsImplementation', |
| 67 | 'ReadOnlyArbitraryEventsWorkerWithContextJS', |
| 68 | ]; |
| 69 | var functionsToErase = [ |
| 70 | 'emscripten_bind_ArbitraryResourceWorkerJS_ExposeImage_1', |
| 71 | 'emscripten_bind_ArbitraryResourceWorkerJS_ExposeShader_1', |
| 72 | 'emscripten_bind_ArbitraryResourceWorkerJS_ExposeFile_1', |
| 73 | 'emscripten_bind_ReadOnlyArbitraryEventsWorkerWithContextJS_DoVisitEvent_1', |
| 74 | 'emscripten_bind_ReadOnlyArbitraryEventsWorkerWithContextJS_DoVisitInstruction_3', |
| 75 | ]; |
| 76 | fs.readFile(file, function(err, data) { |
| 77 | if (err) cb(err); |
| 78 | |
| 79 | var patchedFile = ''; |
| 80 | var insideReturnStringFunction = false; |
| 81 | var erasingClass = false; |
| 82 | var erasingFunction = false; |
| 83 | data |
| 84 | .toString() |
| 85 | .split('\n') |
| 86 | .forEach(function(line) { |
| 87 | //When declaring a function returning "[Const, Ref] DOMString" |
| 88 | //or "[Const, Value] DOMString" |
| 89 | //in the IDL file, the return type is const char*. We are using |
| 90 | //std::string in GDevelop and need to call c_str. |
| 91 | if (insideReturnStringFunction) { |
| 92 | //[Const, Value] DOMString |
| 93 | if (line.indexOf('static char*') !== -1) { |
| 94 | line = line.replace('static char*', 'static gd::String'); |
| 95 | } else if (line.indexOf(', &temp);') !== -1) { |
| 96 | line = line.replace(', &temp);', ', temp.c_str());'); |
| 97 | //[Const, Ref] DOMString |
| 98 | } else { |
| 99 | if (debug) { |
| 100 | //For debugging, use a temporary useless reference |
| 101 | //to check the return type is a reference and not a value. |
| 102 | //Could generate false positive. |
| 103 | line = line |
| 104 | .replace(';', '); return ref.c_str();') |
| 105 | .replace( |
| 106 | 'return &', |
| 107 | 'gd::String & ref = const_cast<gd::String&>(' |
| 108 | ); |
| 109 | } else { |
| 110 | line = line.replace(';', '.c_str();').replace('&', ''); |
| 111 | } |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | //Make sure free functions are called properly. |
| 116 | var freeCallPos = line.indexOf('self->FREE_'); |
no test coverage detected