MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / redisProtocolToLuaType_Double

Function redisProtocolToLuaType_Double

src/scripting.cpp:263–282  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

261}
262
263char *redisProtocolToLuaType_Double(lua_State *lua, char *reply) {
264 char *p = strchr(reply+1,'\r');
265 char buf[MAX_LONG_DOUBLE_CHARS+1];
266 size_t len = p-reply-1;
267 double d;
268
269 if (len <= MAX_LONG_DOUBLE_CHARS) {
270 memcpy(buf,reply+1,len);
271 buf[len] = '\0';
272 d = strtod(buf,NULL); /* We expect a valid representation. */
273 } else {
274 d = 0;
275 }
276
277 lua_newtable(lua);
278 lua_pushstring(lua,"double");
279 lua_pushnumber(lua,d);
280 lua_settable(lua,-3);
281 return p+2;
282}
283
284/* This function is used in order to push an error on the Lua stack in the
285 * format used by redis.pcall to return errors, which is a lua table

Callers 1

redisProtocolToLuaTypeFunction · 0.85

Calls 3

lua_pushstringFunction · 0.85
lua_pushnumberFunction · 0.85
lua_settableFunction · 0.85

Tested by

no test coverage detected