Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does RunString work without a LuaCode asset? #74

Open
bingqiao opened this issue Mar 11, 2025 · 3 comments
Open

Does RunString work without a LuaCode asset? #74

bingqiao opened this issue Mar 11, 2025 · 3 comments

Comments

@bingqiao
Copy link

bingqiao commented Mar 11, 2025

I'm trying to run a simple script using LuaMachine but it keeps crashing.

FLuaValue Result = LuaState->RunString(TEXT("print('LuaMachine initialized in SampleGameActor!')"), TEXT("SampleGameTest"));

RunString has two arguments. Does the second one have to be the name of a LuaCode asset?

Or am I doing something that's just not meant to work?

Thanks!

@rdeioris
Copy link
Owner

Hi, how you are creating the LuaState?

@bingqiao
Copy link
Author

Thanks Roberto, I did suspect the initialization was not right.

void ASampleGameActor::BeginPlay()
{
	Super::BeginPlay();

	LuaState = NewObject<ULuaState>(this, ULuaState::StaticClass(), FName("SampleLuaState"));
    if (LuaState)
    {
        // Test Lua execution
        FString TestScript = TEXT("print('LuaMachine initialized in SampleGameActor!')");
        RunLuaScript(TestScript);
    }	
}

@rdeioris
Copy link
Owner

Yes, you cannot initialize states in that way. The first step is inheriting from ULuaState (it is an abstract class). If you want to create multiple states dinamically use the luau branch and follow the various provided unit tests: https://github.com/rdeioris/LuaMachine/tree/luau/Source/LuaMachineEditor/Private/Tests

Otherwise follow the classic path and just use the functiona library: https://github.com/rdeioris/LuaMachine/blob/master/Source/LuaMachine/Public/LuaBlueprintFunctionLibrary.h

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants