| 40 | } |
| 41 | |
| 42 | void FLuaDebugValue::Build(lua_State *L, int32 Index, int32 Level) |
| 43 | { |
| 44 | // #lizard forgives |
| 45 | |
| 46 | if (!L || bAlreadyBuilt) |
| 47 | { |
| 48 | return; |
| 49 | } |
| 50 | |
| 51 | int32 ValueType = lua_type(L, Index); |
| 52 | Type = lua_typename(L, ValueType); |
| 53 | switch (ValueType) |
| 54 | { |
| 55 | case LUA_TNIL: |
| 56 | ReadableValue = TEXT("nil"); |
| 57 | break; |
| 58 | case LUA_TBOOLEAN: |
| 59 | ReadableValue = lua_toboolean(L, Index) > 0 ? TEXT("true") : TEXT("false"); |
| 60 | break; |
| 61 | case LUA_TLIGHTUSERDATA: |
| 62 | ReadableValue = FString::Printf(TEXT("light userdata: 0x%p"), lua_topointer(L, Index)); |
| 63 | break; |
| 64 | case LUA_TNUMBER: |
| 65 | if (lua_isinteger(L, Index)) |
| 66 | { |
| 67 | ReadableValue = FString::Printf(TEXT("%d"), lua_tointeger(L, Index)); |
| 68 | } |
| 69 | else |
| 70 | { |
| 71 | ReadableValue = FString::Printf(TEXT("%f"), lua_tonumber(L, Index)); |
| 72 | } |
| 73 | break; |
| 74 | case LUA_TSTRING: |
| 75 | ReadableValue = UTF8_TO_TCHAR(lua_tostring(L, Index)); |
| 76 | break; |
| 77 | case LUA_TTABLE: |
| 78 | { |
| 79 | const void *TableAddress = lua_topointer(L, Index); |
| 80 | int32 TableSize = 0; |
| 81 | if (Level > 0) |
| 82 | { |
| 83 | // filter out weak table. |
| 84 | if (lua_getmetatable(L, Index)) |
| 85 | { |
| 86 | lua_pushstring(L, "__mode"); |
| 87 | if( lua_rawget(L, -2) != LUA_TNIL) |
| 88 | { |
| 89 | ReadableValue = FString::Printf(TEXT("weak table: 0x%p"), TableAddress); |
| 90 | lua_pop(L, 2); |
| 91 | break; |
| 92 | } |
| 93 | lua_pop(L, 2); |
| 94 | } |
| 95 | |
| 96 | // traverse all elements |
| 97 | Index = (Index < 0 && Index > LUA_REGISTRYINDEX) ? lua_gettop(L) + Index + 1 : Index; |
| 98 | lua_pushnil(L); |
| 99 | while (lua_next(L, Index) != 0) |
no test coverage detected