| 334 | } |
| 335 | |
| 336 | ScriptBuildResult ScriptLoader::Build() |
| 337 | { |
| 338 | std::int32_t r = _module->Build(); |
| 339 | if (r < 0) { |
| 340 | return (ScriptBuildResult)r; |
| 341 | } |
| 342 | |
| 343 | // After the script has been built, the metadata strings should be stored for later lookup |
| 344 | for (auto& decl : _foundDeclarations) { |
| 345 | _module->SetDefaultNamespace(decl.Namespace.data()); |
| 346 | switch (decl.Type) { |
| 347 | case MetadataType::Type: { |
| 348 | std::int32_t typeId = _module->GetTypeIdByDecl(decl.Declaration.data()); |
| 349 | if (typeId >= 0) { |
| 350 | auto entry = _typeMetadataMap.emplace(typeId, Array<String>(NoInit, decl.Metadata.size())).first; |
| 351 | std::uninitialized_move(decl.Metadata.begin(), decl.Metadata.end(), entry->second.data()); |
| 352 | } |
| 353 | break; |
| 354 | } |
| 355 | case MetadataType::Function: { |
| 356 | if (decl.ParentClass.empty()) { |
| 357 | asIScriptFunction* func = _module->GetFunctionByDecl(decl.Declaration.data()); |
| 358 | if (func != nullptr) { |
| 359 | auto entry = _funcMetadataMap.emplace(func->GetId(), Array<String>(NoInit, decl.Metadata.size())).first; |
| 360 | std::uninitialized_move(decl.Metadata.begin(), decl.Metadata.end(), entry->second.data()); |
| 361 | } |
| 362 | } else { |
| 363 | std::int32_t typeId = _module->GetTypeIdByDecl(decl.ParentClass.data()); |
| 364 | asITypeInfo* type = _engine->GetTypeInfoById(typeId); |
| 365 | asIScriptFunction* func = type->GetMethodByDecl(decl.Declaration.data()); |
| 366 | if (func != nullptr) { |
| 367 | auto it = _classMetadataMap.find(typeId); |
| 368 | if (it == _classMetadataMap.end()) { |
| 369 | it = _classMetadataMap.emplace(typeId, ClassMetadata()).first; |
| 370 | } |
| 371 | |
| 372 | auto entry = it->second.FuncMetadataMap.emplace(func->GetId(), Array<String>(NoInit, decl.Metadata.size())).first; |
| 373 | std::uninitialized_move(decl.Metadata.begin(), decl.Metadata.end(), entry->second.data()); |
| 374 | } |
| 375 | } |
| 376 | break; |
| 377 | } |
| 378 | case MetadataType::VirtualProperty: { |
| 379 | if (decl.ParentClass.empty()) { |
| 380 | asIScriptFunction* func = _module->GetFunctionByName(String("get_"_s + decl.Declaration).data()); |
| 381 | if (func != nullptr) { |
| 382 | auto entry = _funcMetadataMap.emplace(func->GetId(), Array<String>(NoInit, decl.Metadata.size())).first; |
| 383 | std::uninitialized_copy(decl.Metadata.begin(), decl.Metadata.end(), entry->second.data()); |
| 384 | } |
| 385 | func = _module->GetFunctionByName(String("set_"_s + decl.Declaration).data()); |
| 386 | if (func != nullptr) { |
| 387 | auto entry = _funcMetadataMap.emplace(func->GetId(), Array<String>(NoInit, decl.Metadata.size())).first; |
| 388 | std::uninitialized_move(decl.Metadata.begin(), decl.Metadata.end(), entry->second.data()); |
| 389 | } |
| 390 | } else { |
| 391 | std::int32_t typeId = _module->GetTypeIdByDecl(decl.ParentClass.data()); |
| 392 | auto it = _classMetadataMap.find(typeId); |
| 393 | if (it == _classMetadataMap.end()) { |