summaryrefslogtreecommitdiff
path: root/src/scripting.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/scripting.c')
-rw-r--r--src/scripting.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/scripting.c b/src/scripting.c
index 64de1edcd..1ef91a4de 100644
--- a/src/scripting.c
+++ b/src/scripting.c
@@ -1147,11 +1147,26 @@ int redis_math_randomseed (lua_State *L) {
*
* f_<hex sha1 sum>
*
+ * If 'funcname' is NULL, the function name is created by the function
+ * on the fly doing the SHA1 of the body, this means that passing the funcname
+ * is just an optimization in case it's already at hand.
+ *
+ * The function increments the reference count of the 'body' object as a
+ * side effect of a successful call.
+ *
* On success C_OK is returned, and nothing is left on the Lua stack.
* On error C_ERR is returned and an appropriate error is set in the
* client context. */
int luaCreateFunction(client *c, lua_State *lua, char *funcname, robj *body) {
sds funcdef = sdsempty();
+ char fname[42];
+
+ if (funcname == NULL) {
+ fname[0] = 'f';
+ fname[1] = '_';
+ sha1hex(fname+2,body->ptr,sdslen(body->ptr));
+ funcname = fname;
+ }
funcdef = sdscat(funcdef,"function ");
funcdef = sdscatlen(funcdef,funcname,42);