* Push an untyped map (same memory layout with TMap). see PushArray */
| 435 | * Push an untyped map (same memory layout with TMap). see PushArray |
| 436 | */ |
| 437 | int32 PushMap(lua_State *L, const FScriptMap *ScriptMap, TSharedPtr<ITypeInterface> KeyInterface, TSharedPtr<ITypeInterface> ValueInterface, bool bCreateCopy) |
| 438 | { |
| 439 | if (!L || !ScriptMap || !KeyInterface || !ValueInterface) |
| 440 | { |
| 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | const auto Registry = FLuaEnv::FindEnvChecked(L).GetContainerRegistry(); |
| 445 | if (bCreateCopy) |
| 446 | { |
| 447 | int32 Num = ScriptMap->Num(); |
| 448 | FLuaMap SrcMap(ScriptMap, KeyInterface, ValueInterface, FLuaMap::OwnedByOther); |
| 449 | FLuaMap *DestMap = Registry->NewMap(L, KeyInterface, ValueInterface, FLuaMap::OwnedBySelf); |
| 450 | DestMap->Clear(Num); |
| 451 | for (int32 SrcIndex = 0; Num; ++SrcIndex) |
| 452 | { |
| 453 | if (ScriptMap->IsValidIndex(SrcIndex)) |
| 454 | { |
| 455 | int32 DestIndex = DestMap->AddDefaultValue_Invalid_NeedsRehash(); |
| 456 | uint8 *SrcData = SrcMap.GetData(SrcIndex); |
| 457 | uint8 *DestData = DestMap->GetData(DestIndex); |
| 458 | KeyInterface->Copy(DestData, SrcData); |
| 459 | ValueInterface->Copy(DestData + DestMap->MapLayout.ValueOffset, SrcData + SrcMap.MapLayout.ValueOffset); |
| 460 | --Num; |
| 461 | } |
| 462 | } |
| 463 | DestMap->Rehash(); |
| 464 | } |
| 465 | else |
| 466 | { |
| 467 | Registry->FindOrAdd(L, (FScriptMap*)ScriptMap, KeyInterface, ValueInterface); |
| 468 | } |
| 469 | return 1; |
| 470 | } |
| 471 | |
| 472 | /** |
| 473 | * Get an untyped dynamic array at the given stack index |
no test coverage detected