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

Function GetUserdataFast

Plugins/UnLua/Source/UnLua/Private/LuaCore.cpp:370–407  ·  view source on GitHub ↗

* Get the address of userdata, fast path */

Source from the content-addressed store, hash-verified

368 * Get the address of userdata, fast path
369 */
370void* GetUserdataFast(lua_State *L, int32 Index, bool *OutTwoLvlPtr)
371{
372 bool bTwoLvlPtr = false;
373 void* Userdata = nullptr;
374
375 TValue* Value = GetTValue(L, Index);
376 int32 Type = GetTValueType(Value);
377 if (Type == LUA_TUSERDATA)
378 {
379 Udata* U = GetUdata(Value);
380 uint8* Buffer = (uint8*)GetUdataMem(U);
381 FUserdataDesc* UserdataDesc = GetUserdataDesc(U);
382 if ((UserdataDesc)
383 && (UserdataDesc->tag & BIT_VARIANT_TAG))// if the userdata has a variant tag
384 {
385 bTwoLvlPtr = (UserdataDesc->tag & BIT_TWOLEVEL_PTR) != 0; // test if the userdata is a two level pointer
386 if (UserdataDesc->tag & BIT_RELEASED_TAG)
387 Userdata = nullptr;
388 else
389 Userdata = bTwoLvlPtr ? Buffer : Buffer + UserdataDesc->padding; // add padding to userdata if it's not a two level pointer
390 }
391 else
392 {
393 Userdata = Buffer;
394 }
395 }
396 else if (Type == LUA_TLIGHTUSERDATA)
397 {
398 Userdata = pvalue(Value); // get the light userdata
399 }
400
401 if (OutTwoLvlPtr)
402 {
403 *OutTwoLvlPtr = bTwoLvlPtr; // set two level pointer flag
404 }
405
406 return Userdata;
407}
408
409/**
410 * Set metatable for the userdata/table on the top of the stack

Callers 7

~FGuardMethod · 0.85
GetPointerFunction · 0.85
GetSmartPointerFunction · 0.85
GetUserdataFunction · 0.85
GetCppInstanceFastFunction · 0.85
ScriptStruct_DeleteFunction · 0.85
UnbindMethod · 0.85

Calls 5

GetTValueFunction · 0.85
GetTValueTypeFunction · 0.85
GetUdataFunction · 0.85
GetUdataMemFunction · 0.85
GetUserdataDescFunction · 0.85

Tested by

no test coverage detected