Console overhaul, part 2. New console is mostly working.

This commit is contained in:
2025-12-09 15:51:35 -05:00
parent 2d1def8dc6
commit a0703effc3
10 changed files with 51 additions and 21 deletions

View File

@@ -202,37 +202,44 @@ FString UlxLuaCallLibrary::AllFunctionsWithPrefix(const TCHAR *Prefix)
//
/////////////////////////////////////////////////////////////////
void UlxLuaCallLibrary::ValidateLua(
ElxLuaSyntaxCheck &Result, FString &ErrorMessage, UObject *context, const FString &Code)
void UlxLuaCallLibrary::ValidateLuaExpr(
ElxLuaSyntaxCheck &Status, FString &ErrorMessage, UObject *context, const FString &Code)
{
if (Code.StartsWith(TEXT("/")))
{
ErrorMessage = "SlashCommand";
Result = ElxLuaSyntaxCheck::SlashCommand;
Status = ElxLuaSyntaxCheck::SlashCommand;
return;
}
if (Code.TrimStart().IsEmpty())
{
ErrorMessage = "";
Result = ElxLuaSyntaxCheck::Whitespace;
Status = ElxLuaSyntaxCheck::Whitespace;
return;
}
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
ErrorMessage = mode->LuaValidate(Code);
ErrorMessage = mode->ValidateLuaExpr(Code);
if (ErrorMessage.IsEmpty())
{
Result = ElxLuaSyntaxCheck::ValidLua;
Status = ElxLuaSyntaxCheck::ValidLua;
}
else if (ErrorMessage.Contains(TEXT("<eof>")))
{
Result = ElxLuaSyntaxCheck::TruncatedLua;
Status = ElxLuaSyntaxCheck::TruncatedLua;
}
else
{
Result = ElxLuaSyntaxCheck::InvalidLua;
Status = ElxLuaSyntaxCheck::InvalidLua;
}
}
void UlxLuaCallLibrary::InvokeLuaExpr(UObject *context, const FString &Code)
{
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);
mode->InvokeLuaExpr(Code);
}
void UlxLuaCallLibrary::LuaCallBegin(UObject *context, const FString &cname, const FString &fname)
{
ALuprexGameModeBase *mode = ALuprexGameModeBase::FromContext(context);

View File

@@ -139,8 +139,11 @@ public:
// returns an error message. If the code is error-free, the
// error message is the empty string.
//
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", ExpandEnumAsExecs="Result"), Category = "Luprex|Call Lua Function")
static void ValidateLua(ElxLuaSyntaxCheck &Result, FString &ErrorMessage, UObject *context, const FString &Code);
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
static void ValidateLuaExpr(ElxLuaSyntaxCheck &Status, FString &ErrorMessage, UObject *context, const FString &Code);
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context"), Category = "Luprex|Call Lua Function")
static void InvokeLuaExpr(UObject *context, const FString &Code);
UFUNCTION(BlueprintCallable, meta = (WorldContext = "context", BlueprintInternalUseOnly = "true"), Category = "Luprex|Call Lua Function")
static void LuaCallBegin(UObject *context, const FString &ClassName, const FString &FunctionName);

View File

@@ -223,17 +223,26 @@ UlxLuaValues *ALuprexGameModeBase::LuaCallEnd(AccessKind kind, AActor *place) {
}
}
FString ALuprexGameModeBase::LuaValidate(const FString &Code)
FString ALuprexGameModeBase::ValidateLuaExpr(const FString &Code)
{
FTCHARToUTF8 UCode(*Code);
FlxLockedWrapper w(LockableWrapper);
uint32_t retpklen;
const char *retpk;
w->play_access(w.Get(), AccessKind::VALIDATE_LUA, 0, UCode.Length(), UCode.Get(), &retpklen, &retpk);
w->play_access(w.Get(), AccessKind::VALIDATE_LUA_EXPR, 0, UCode.Length(), UCode.Get(), &retpklen, &retpk);
FString Result(retpklen, (const UTF8CHAR*)retpk);
return Result;
}
void ALuprexGameModeBase::InvokeLuaExpr(const FString &Code)
{
FTCHARToUTF8 UCode(*Code);
FlxLockedWrapper w(LockableWrapper);
uint32_t retpklen;
const char *retpk;
w->play_access(w.Get(), AccessKind::INVOKE_LUA_EXPR, 0, UCode.Length(), UCode.Get(), &retpklen, &retpk);
}
void ALuprexGameModeBase::OnWorldPreActorTick(UWorld* InWorld, ELevelTick InLevelTick, float deltaseconds)
{
if(Playing && TickEnabled && (GetWorld() == InWorld) && (InLevelTick == LEVELTICK_All))

View File

@@ -116,7 +116,11 @@ public:
// an otherwise empty lua interpreter, so this is purely
// a syntax check.
//
FString LuaValidate(const FString &Code);
FString ValidateLuaExpr(const FString &Code);
// Invoke some lua code.
//
void InvokeLuaExpr(const FString &Code);
// Get the Asset Lookup table.
const UlxAssetLookup *GetAssetLookup() const { return AssetLookup; }