Need help with Lua machine's Mapping BlueprintFunctionLibrary to UserData guide not working

Hi I’ve been trying to get this guide to work https://github.com/rdeioris/LuaMachine/blob/master/Docs/TipsAndTricks.md#mapping-blueprintfunctionlibrary-to-userdata but no matter what I do I can’t get it to work. The problem is when ever I try to call one of the BlueprintFunctionLibrary functions it says attempted to call a nil value. below is what I did while following the guide. Is there some extra step I have to do? If anyone was able to get this to work please let me know what I’m doing wrong.

The error

My setup
C++ code
BPFLLuaBlueprintPackage.h

#pragma once

#include "CoreMinimal.h"
#include "LuaBlueprintPackage.h"
#include "UBPFLLuaBlueprintPackage.generated.h"

/**
 * 
 */
UCLASS()
class LUAMACHINE_TEST_API UBPFLLuaBlueprintPackage : public ULuaBlueprintPackage
{
	GENERATED_BODY()
	
public:
	UBPFLLuaBlueprintPackage();

	UFUNCTION()
	FLuaValue RequireBlueprintFunctionLibrary(FLuaValue LibraryName);
};

.cpp

UBPFLLuaBlueprintPackage::UBPFLLuaBlueprintPackage()
{
	Table.Add("require", FLuaValue::Function(GET_FUNCTION_NAME_CHECKED(UBPFLLuaBlueprintPackage, RequireBlueprintFunctionLibrary)));
}

FLuaValue UBPFLLuaBlueprintPackage::RequireBlueprintFunctionLibrary(FLuaValue LibraryName)
{
	FWorldContext* world = GEngine->GetWorldContextFromGameViewport(GEngine->GameViewport);

	UWorld* W = world->World();

	ULuaState* L = FLuaMachineModule::Get().GetLuaState(GetLuaState(), W->GetWorld());

	if (L != nullptr) {
		if (GEngine)
			GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, L->GetClass()->GetName());
	}

	UClass* FoundClass = Cast<UClass>(StaticFindObject(UClass::StaticClass(), ANY_PACKAGE, *LibraryName.ToString()));
	if (FoundClass)
	{
		ULuaUserDataBPFL* UserDataBPFL = NewObject<ULuaUserDataBPFL>(L);
		UserDataBPFL->InitializeWithClass(FoundClass);
		return FLuaValue(UserDataBPFL);
	}
	return FLuaValue();
}

LuaUserDataBPFL.h

#pragma once

#include "CoreMinimal.h"
#include "LuaUserDataObject.h"
#include "ULuaUserDataBPFL.generated.h"

/**
 * 
 */
UCLASS()
class LUAMACHINE_TEST_API ULuaUserDataBPFL : public ULuaUserDataObject
{
	GENERATED_BODY()

public:
	void InitializeWithClass(UClass* InClass);

	virtual FLuaValue ReceiveLuaMetaIndex_Implementation(FLuaValue Key) override;

protected:
	UPROPERTY()
	UClass* BPFLClass;
};

.cpp

void ULuaUserDataBPFL::InitializeWithClass(UClass* InClass)
{
	BPFLClass = InClass;
}

FLuaValue ULuaUserDataBPFL::ReceiveLuaMetaIndex_Implementation(FLuaValue Key)
{
	UFunction* Function = BPFLClass->FindFunctionByName(*Key.ToString());
	if (Function)
	{
		return FLuaValue::FunctionOfObject(BPFLClass->GetDefaultObject(), Function->GetFName());
	}

	return FLuaValue();
}

Lua code

Lua state config

I’m having a very similar problem, the exact actually. Did you ever find a fix?

Hey sorry for the late reply. Yes I did find a way to make it work as long as you don’t mind deviating from the tutorial. So I looked though the code and I’m pretty sure the issue I found was that, because the BFL functions weren’t own by the user data it wouldn’t call them (This was a bit ago so the specifics are a bit fuzzy).

I was able to get it to work but I had use a table instead of user data here’s my code

int ULuaModBoxState::BPFLSearcher(lua_State* InL)
{
	UObject* ClassPackage = ANY_PACKAGE;
	FString Str = lua_tostring(InL, 1);

	UClass* C = FindObject<UClass>(ClassPackage, *Str, true);
	
	if(!C) return 1;

	
	if(!C->IsChildOf(UBlueprintFunctionLibrary::StaticClass())) return 1;

	
	lua_pushcfunction(InL, BPFLReturnFunc);
	
	
	return 1;
}

int ULuaModBoxState::BPFLReturnFunc(lua_State* InL)
{
	//Find Class And Get ULuaState Object
	UObject* ClassPackage = ANY_PACKAGE;
	FString Str = lua_tostring(InL, 1);

	UClass* FoundClass = FindObject<UClass>(ClassPackage, *Str, true);

	ULuaState* LuaState = ULuaState::GetFromExtraSpace(InL);


	//Construct Package
	FLuaValue NewTable = LuaState->CreateLuaTable();

    for(TFieldIterator<UFunction> It(FoundClass); It; ++It)
    {
    	UFunction* Func = *It;

    	if(!Func->HasAnyFunctionFlags(FUNC_Static)) continue;
    	
	    if(LuaState->bRawLuaFunctionCall)
	    {
	    	NewTable.SetField(Func->GetName(), FLuaValue::FunctionOfObject(FoundClass->GetDefaultObject(), Func->GetFName()));
		    continue;
	    }

    	
    }

	
	LuaState->FromLuaValue(NewTable);
	
	return 1;
}

This code is quite different from the tutorial since I’m not making the Require function from the tutorial, but instead inserting a new searcher function into package.searchers which allows the normal require to search for and expose the BFL’s instead. There a bit more to getting this to work, But the basics of the function are that it populates a table with lua values of UFunction which can be used to call said function.

I hope this helps, and sorry that I can’t help with following the tutorial as is. All attempts I made to ask people on discord how they got it to work ended in them going silent.