MCPcopy Create free account
hub / github.com/Tencent/sluaunreal / CreateLuaState

Method CreateLuaState

Source/democpp/MyGameInstance.cpp:36–65  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34}
35
36void UMyGameInstance::CreateLuaState()
37{
38 NS_SLUA::LuaState::onInitEvent.AddUObject(this, &UMyGameInstance::LuaStateInitCallback);
39
40 CloseLuaState();
41 state = new NS_SLUA::LuaState("SLuaMainState", this);
42 state->setLoadFileDelegate([](const char* fn, FString& filepath)->TArray<uint8> {
43
44 IPlatformFile& PlatformFile = FPlatformFileManager::Get().GetPlatformFile();
45 FString path = FPaths::ProjectContentDir();
46 FString filename = UTF8_TO_TCHAR(fn);
47 path /= "Lua";
48 path /= filename.Replace(TEXT("."), TEXT("/"));
49
50 TArray<uint8> Content;
51 TArray<FString> luaExts = { UTF8_TO_TCHAR(".lua"), UTF8_TO_TCHAR(".luac") };
52 for (auto& it : luaExts) {
53 auto fullPath = path + *it;
54
55 FFileHelper::LoadFileToArray(Content, *fullPath);
56 if (Content.Num() > 0) {
57 filepath = fullPath;
58 return MoveTemp(Content);
59 }
60 }
61
62 return MoveTemp(Content);
63 });
64 state->init();
65}
66
67void UMyGameInstance::CloseLuaState()
68{

Callers

nothing calls this directly

Calls 3

setLoadFileDelegateMethod · 0.80
NumMethod · 0.45
initMethod · 0.45

Tested by

no test coverage detected