RESP3: RESP3 double -> Lua conversion.
This commit is contained in:
parent
f3ac144115
commit
11678504f7
@ -45,6 +45,7 @@ char *redisProtocolToLuaType_Error(lua_State *lua, char *reply);
|
||||
char *redisProtocolToLuaType_Aggregate(lua_State *lua, char *reply, int atype);
|
||||
char *redisProtocolToLuaType_Null(lua_State *lua, char *reply);
|
||||
char *redisProtocolToLuaType_Bool(lua_State *lua, char *reply, int tf);
|
||||
char *redisProtocolToLuaType_Double(lua_State *lua, char *reply);
|
||||
int redis_math_random (lua_State *L);
|
||||
int redis_math_randomseed (lua_State *L);
|
||||
void ldbInit(void);
|
||||
@ -139,6 +140,7 @@ char *redisProtocolToLuaType(lua_State *lua, char* reply) {
|
||||
case '~': p = redisProtocolToLuaType_Aggregate(lua,reply,*p); break;
|
||||
case '_': p = redisProtocolToLuaType_Null(lua,reply); break;
|
||||
case '#': p = redisProtocolToLuaType_Bool(lua,reply,p[1]);
|
||||
case ',': p = redisProtocolToLuaType_Double(lua,reply);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@ -239,6 +241,27 @@ char *redisProtocolToLuaType_Bool(lua_State *lua, char *reply, int tf) {
|
||||
return p+2;
|
||||
}
|
||||
|
||||
char *redisProtocolToLuaType_Double(lua_State *lua, char *reply) {
|
||||
char *p = strchr(reply+1,'\r');
|
||||
char buf[MAX_LONG_DOUBLE_CHARS+1];
|
||||
size_t len = p-reply-1;
|
||||
double d;
|
||||
|
||||
if (len <= MAX_LONG_DOUBLE_CHARS) {
|
||||
memcpy(buf,reply+1,len);
|
||||
buf[len] = '\0';
|
||||
d = strtod(buf,NULL); /* We expect a valid representation. */
|
||||
} else {
|
||||
d = 0;
|
||||
}
|
||||
|
||||
lua_newtable(lua);
|
||||
lua_pushstring(lua,"double");
|
||||
lua_pushnumber(lua,d);
|
||||
lua_settable(lua,-3);
|
||||
return p+2;
|
||||
}
|
||||
|
||||
/* This function is used in order to push an error on the Lua stack in the
|
||||
* format used by redis.pcall to return errors, which is a lua table
|
||||
* with a single "err" field set to the error string. Note that this
|
||||
|
Loading…
x
Reference in New Issue
Block a user