Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
89f929b1
Commit
89f929b1
authored
Sep 17, 2019
by
antirez
Browse files
RESP3: RESP3 double -> Lua conversion.
parent
19aba4ac
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/scripting.c
View file @
89f929b1
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment