MCPcopy Create free account
hub / github.com/WaykiChain/WaykiChain / getStringInTable

Function getStringInTable

src/vm/luavm/lmylib.cpp:290–313  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

288}
289
290static 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
315template <typename ArrayType>
316static bool getArrayInTable(lua_State *L, const char *pKey, uint16_t usLen, ArrayType &arrayOut) {

Callers 5

GetDataTableWriteDataDBFunction · 0.85
ExGetAccountAssetFuncFunction · 0.85
ExGetAssetPriceFuncFunction · 0.85

Calls 3

lua_pushstringFunction · 0.85
lua_gettableFunction · 0.85
lua_isstringFunction · 0.85

Tested by

no test coverage detected