Skip to content

Commit

Permalink
added ULuaState::LuaGetLocals and LuaTableFromMap
Browse files Browse the repository at this point in the history
  • Loading branch information
rdeioris committed Feb 24, 2020
1 parent 0d57ff0 commit 445225e
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LuaMachine.uplugin
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"FileVersion": 3,
"Version": 1,
"VersionName": "20200220",
"VersionName": "20200224",
"FriendlyName": "LuaMachine",
"Description": "Expose a Lua api for your project",
"Category": "Scripting",
Expand Down
17 changes: 17 additions & 0 deletions Source/LuaMachine/Private/LuaBlueprintFunctionLibrary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1153,6 +1153,23 @@ FLuaValue ULuaBlueprintFunctionLibrary::LuaTableMergePack(UObject* WorldContextO
return ReturnValue;
}

FLuaValue ULuaBlueprintFunctionLibrary::LuaTableFromMap(UObject* WorldContextObject, TSubclassOf<ULuaState> State, TMap<FString, FLuaValue> Map)
{
FLuaValue ReturnValue;
ULuaState* L = FLuaMachineModule::Get().GetLuaState(State, WorldContextObject->GetWorld());
if (!L)
return ReturnValue;

ReturnValue = L->CreateLuaTable();

for (TPair<FString, FLuaValue>& Pair : Map)
{
ReturnValue.SetField(Pair.Key, Pair.Value);
}

return ReturnValue;
}

TArray<FLuaValue> ULuaBlueprintFunctionLibrary::LuaTableRange(FLuaValue InTable, int32 First, int32 Last)
{
TArray<FLuaValue> ReturnValue;
Expand Down
20 changes: 20 additions & 0 deletions Source/LuaMachine/Private/LuaState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,26 @@ FLuaDebug ULuaState::LuaGetInfo(int32 Level)
return LuaDebug;
}

TMap<FString, FLuaValue> ULuaState::LuaGetLocals(int32 Level)
{
TMap<FString, FLuaValue> ReturnValue;

lua_Debug ar;
if (lua_getstack(L, Level, &ar) != 1)
return ReturnValue;

int Index = 1;
const char* name = lua_getlocal(L, &ar, Index);
while(name)
{
FLuaValue LuaValue = ToLuaValue(-1);
ReturnValue.Add(ANSI_TO_TCHAR(name), LuaValue);
Pop();
name = lua_getlocal(L, &ar, ++Index);
}
return ReturnValue;
}

void ULuaState::Debug_Hook(lua_State* L, lua_Debug* ar)
{
ULuaState* LuaState = ULuaState::GetFromExtraSpace(L);
Expand Down
3 changes: 3 additions & 0 deletions Source/LuaMachine/Public/LuaBlueprintFunctionLibrary.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,9 @@ class LUAMACHINE_API ULuaBlueprintFunctionLibrary : public UBlueprintFunctionLib
UFUNCTION(BlueprintCallable, Category = "Lua")
static void LuaTableFillObject(FLuaValue InTable, UObject* InObject);

UFUNCTION(BlueprintCallable, meta = (WorldContext = "WorldContextObject"), Category = "Lua")
static FLuaValue LuaTableFromMap(UObject* WorldContextObject, TSubclassOf<ULuaState> State, TMap<FString, FLuaValue> Map);

UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Lua")
static TArray<FLuaValue> LuaTableRange(FLuaValue InTable, int32 First, int32 Last);

Expand Down
3 changes: 3 additions & 0 deletions Source/LuaMachine/Public/LuaState.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,9 @@ class LUAMACHINE_API ULuaState : public UObject
UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Lua")
FLuaDebug LuaGetInfo(int32 Level);

UFUNCTION(BlueprintCallable, BlueprintPure, Category = "Lua")
TMap<FString, FLuaValue> LuaGetLocals(int32 Level);

template<class T>
FLuaValue NewLuaUserDataObject(bool bTrackObject = true)
{
Expand Down

0 comments on commit 445225e

Please sign in to comment.