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

Function CacheScriptContainer

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

* Find a cached script container or create a new one * * @return - null if container is already cached, or the new created userdata otherwise */

Source from the content-addressed store, hash-verified

494 * @return - null if container is already cached, or the new created userdata otherwise
495 */
496void* CacheScriptContainer(lua_State *L, void *Key, const FScriptContainerDesc &Desc)
497{
498 if (!Key)
499 {
500 UNLUA_LOGERROR(L, LogUnLua, Warning, TEXT("%s, Invalid key!"), ANSI_TO_TCHAR(__FUNCTION__));
501 return nullptr;
502 }
503
504 // return null if container is already cached, or create/cache/return a new ud
505 void *Userdata = nullptr;
506 lua_getfield(L, LUA_REGISTRYINDEX, "ScriptContainerMap");
507 lua_pushlightuserdata(L, Key);
508 int32 Type = lua_rawget(L, -2);
509 if (Type == LUA_TNIL)
510 {
511 lua_pop(L, 1);
512
513 Userdata = NewUserdataWithContainerTag(L, Desc.GetSize()); // create new userdata
514 luaL_setmetatable(L, Desc.GetName()); // set metatable
515 lua_pushlightuserdata(L, Key);
516 lua_pushvalue(L, -2);
517 lua_rawset(L, -4); // cache it in 'ScriptContainerMap'
518 UnLua::FLuaEnv::FindEnv(L)->GetDanglingCheck()->CaptureContainer(L, Key);
519 }
520#if UE_BUILD_DEBUG
521 else
522 {
523 check(Type == LUA_TUSERDATA);
524 }
525#endif
526 lua_remove(L, -2);
527 return Userdata; // return null if container is already cached, or the new created userdata otherwise
528}
529
530/**
531 * Get a script container at the given stack index

Callers 1

FindOrAddMethod · 0.85

Calls 11

lua_getfieldFunction · 0.85
lua_pushlightuserdataFunction · 0.85
lua_rawgetFunction · 0.85
luaL_setmetatableFunction · 0.85
lua_pushvalueFunction · 0.85
lua_rawsetFunction · 0.85
checkFunction · 0.85
CaptureContainerMethod · 0.80
GetSizeMethod · 0.45
GetNameMethod · 0.45

Tested by

no test coverage detected