| 34 | } |
| 35 | |
| 36 | void 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 | |
| 67 | void UMyGameInstance::CloseLuaState() |
| 68 | { |
nothing calls this directly
no test coverage detected