* Build value based on a userdata */
| 203 | * Build value based on a userdata |
| 204 | */ |
| 205 | void FLuaDebugValue::BuildFromUserdata(lua_State *L, int32 Index) |
| 206 | { |
| 207 | if (lua_type(L, Index) != LUA_TUSERDATA) |
| 208 | { |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | // get class name |
| 213 | void *ContainerPtr = UnLua::GetPointer(L, Index); |
| 214 | const char *ClassNamePtr = nullptr; |
| 215 | if (lua_getmetatable(L, Index) > 0) |
| 216 | { |
| 217 | lua_pushstring(L, "__name"); |
| 218 | lua_rawget(L, -2); |
| 219 | if (lua_isstring(L, -1)) |
| 220 | { |
| 221 | ClassNamePtr = lua_tostring(L, -1); |
| 222 | } |
| 223 | lua_pop(L, 2); |
| 224 | } |
| 225 | |
| 226 | if (ClassNamePtr) |
| 227 | { |
| 228 | FString ClassName(ClassNamePtr); |
| 229 | UStruct *Struct = FindObject<UStruct>(ANY_PACKAGE, *ClassName + 1); |
| 230 | if (Struct) |
| 231 | { |
| 232 | // the userdata is a struct instance |
| 233 | UObjectBaseUtility *ContainerObject = GetContainerObject(Struct, ContainerPtr); |
| 234 | BuildFromUStruct(Struct, ContainerPtr, ContainerObject); |
| 235 | } |
| 236 | else |
| 237 | { |
| 238 | if (!ContainerPtr) |
| 239 | { |
| 240 | ReadableValue = FString::Printf(TEXT("userdata (%s): 0x%p"), *ClassName, ContainerPtr); |
| 241 | return; |
| 242 | } |
| 243 | |
| 244 | if (ClassName == TEXT("TArray")) |
| 245 | { |
| 246 | // the userdata is a TArray instance |
| 247 | FLuaArray *Array = (FLuaArray*)ContainerPtr; |
| 248 | FProperty *InnerProperty = Array->Inner->GetUProperty(); |
| 249 | if (InnerProperty) |
| 250 | { |
| 251 | FScriptArrayHelper ArrayHelper = FScriptArrayHelper::CreateHelperFormInnerProperty(InnerProperty, Array->ScriptArray); |
| 252 | BuildFromTArray(ArrayHelper, InnerProperty); |
| 253 | } |
| 254 | else |
| 255 | { |
| 256 | ReadableValue = FString::Printf(TEXT("TArray<UnknownType> Num=%d, Not Support Expand"), Array->Num()); |
| 257 | } |
| 258 | } |
| 259 | else if (ClassName == TEXT("TMap")) |
| 260 | { |
| 261 | // the userdata is a TMap instance |
| 262 | FLuaMap *Map = (FLuaMap*)ContainerPtr; |
nothing calls this directly
no test coverage detected