| 288 | } |
| 289 | |
| 290 | static bool getStringInTable(lua_State *L, const char * pKey, string &strValue) { |
| 291 | // 在table里,取指定pKey对应的string值 |
| 292 | |
| 293 | const char *pStr = nullptr; |
| 294 | //默认栈顶是table,将pKey入栈 |
| 295 | lua_pushstring(L, pKey); |
| 296 | lua_gettable(L, -2); //查找键值为key的元素,置于栈顶 |
| 297 | if (!lua_isstring(L, -1)) { |
| 298 | LogPrint(BCLog::LUAVM, "string get error! %s\n", lua_tostring(L, -1)); |
| 299 | } else { |
| 300 | pStr = lua_tostring(L, -1); |
| 301 | if (pStr && (strlen(pStr) <= LUA_C_BUFFER_SIZE)) { |
| 302 | string res(pStr); |
| 303 | strValue = res; |
| 304 | // LogPrint(BCLog::LUAVM, "getStringInTable:%s\n", pStr); |
| 305 | lua_pop(L, 1); //删掉产生的查找结果 |
| 306 | return true; |
| 307 | } else { |
| 308 | LogPrint(BCLog::LUAVM, "%s\n", "lua_tostring get fail"); |
| 309 | } |
| 310 | } |
| 311 | lua_pop(L, 1); //删掉产生的查找结果 |
| 312 | return false; |
| 313 | } |
| 314 | |
| 315 | template <typename ArrayType> |
| 316 | static bool getArrayInTable(lua_State *L, const char *pKey, uint16_t usLen, ArrayType &arrayOut) { |
no test coverage detected