| 314 | |
| 315 | template <typename ArrayType> |
| 316 | static bool getArrayInTable(lua_State *L, const char *pKey, uint16_t usLen, ArrayType &arrayOut) { |
| 317 | // 在table里,取指定pKey对应的数组 |
| 318 | if ((usLen <= 0) || (usLen > LUA_C_BUFFER_SIZE)) { |
| 319 | LogPrint(BCLog::LUAVM, "usLen error\n"); |
| 320 | return false; |
| 321 | } |
| 322 | uint8_t value = 0; |
| 323 | arrayOut.clear(); |
| 324 | //默认栈顶是table,将key入栈 |
| 325 | lua_pushstring(L, pKey); |
| 326 | lua_gettable(L, -2); |
| 327 | if (!lua_istable(L, -1)) { |
| 328 | lua_pop(L, 1); |
| 329 | LogPrint(BCLog::LUAVM, "getTableInTable is not table\n"); |
| 330 | return false; |
| 331 | } |
| 332 | for (int32_t i = 0; i < usLen; ++i) { |
| 333 | lua_pushnumber(L, i + 1); //将索引入栈 |
| 334 | lua_gettable(L, -2); |
| 335 | if (!lua_isnumber(L, -1)) { |
| 336 | LogPrint(BCLog::LUAVM, "getTableInTable is not number\n"); |
| 337 | return false; |
| 338 | } |
| 339 | value = 0; |
| 340 | value = lua_tonumber(L, -1); |
| 341 | arrayOut.insert(arrayOut.end(), value); |
| 342 | lua_pop(L, 1); |
| 343 | } |
| 344 | lua_pop(L, 1); //删掉产生的查找结果 |
| 345 | return true; |
| 346 | } |
| 347 | |
| 348 | static bool getStringLogPrint(lua_State *L, char *pKey, uint16_t usLen, vector<uint8_t> &vOut) { |
| 349 | //从栈里取 table的值是一串字符串 |
no test coverage detected