MCPcopy Create free account
hub / github.com/Tencent/UnLua / PushMap

Function PushMap

Plugins/UnLua/Source/UnLua/Private/UnLuaBase.cpp:437–470  ·  view source on GitHub ↗

* Push an untyped map (same memory layout with TMap). see PushArray */

Source from the content-addressed store, hash-verified

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

Callers 1

PushFunction · 0.85

Calls 9

NewMapMethod · 0.80
FindOrAddMethod · 0.80
NumMethod · 0.45
ClearMethod · 0.45
IsValidIndexMethod · 0.45
GetDataMethod · 0.45
CopyMethod · 0.45
RehashMethod · 0.45

Tested by

no test coverage detected