* Get the address of userdata, fast path */
| 368 | * Get the address of userdata, fast path |
| 369 | */ |
| 370 | void* 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 |
no test coverage detected