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

Function LoadFile

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

* Load a Lua file without running it */

Source from the content-addressed store, hash-verified

64 * Load a Lua file without running it
65 */
66 bool LoadFile(lua_State *L, const FString &RelativeFilePath, const char *Mode, int32 Env)
67 {
68 FString FullFilePath = GetFullPathFromRelativePath(RelativeFilePath);
69 if (FullFilePath.IsEmpty())
70 {
71 UE_LOG(LogUnLua, Warning, TEXT("the lua file try to load does not exist! : %s"), *RelativeFilePath);
72 return false;
73 }
74
75 if (FullFilePath != GLuaSrcFullPath + RelativeFilePath)
76 {
77 UE_LOG(LogUnLua, Log, TEXT("Load lua file from DownloadDir : %s"), *FullFilePath);
78 }
79
80 TArray<uint8> Data;
81 bool bSuccess = FFileHelper::LoadFileToArray(Data, *FullFilePath, 0);
82 if (!bSuccess)
83 {
84 UE_LOG(LogUnLua, Warning, TEXT("%s: Failed to load lua file!"), ANSI_TO_TCHAR(__FUNCTION__));
85 return false;
86 }
87
88 int32 SkipLen = (3 < Data.Num()) && (0xEF == Data[0]) && (0xBB == Data[1]) && (0xBF == Data[2]) ? 3 : 0; // skip UTF-8 BOM mark
89 return LoadChunk(L, (const char*)(Data.GetData() + SkipLen), Data.Num() - SkipLen, TCHAR_TO_UTF8(*RelativeFilePath), Mode, Env); // loads the buffer as a Lua chunk
90 }
91
92 /**
93 * Load a Lua chunk without running it

Callers

nothing calls this directly

Calls 4

LoadChunkFunction · 0.85
NumMethod · 0.45
GetDataMethod · 0.45

Tested by

no test coverage detected