Initialize the scripting environment. * * This function is called the first time at server startup with * the 'setup' argument set to 1. * * It can be called again multiple times during the lifetime of the Redis * process, with 'setup' set to 0, and following a scriptingRelease() call, * in order to reset the Lua scripting environment. * * However it is simpler to just call scriptingReset
| 1145 | * |
| 1146 | * However it is simpler to just call scriptingReset() that does just that. */ |
| 1147 | void scriptingInit(int setup) { |
| 1148 | lua_State *lua = lua_open(); |
| 1149 | |
| 1150 | if (setup) { |
| 1151 | for (int iel = 0; iel < cserver.cthreads; ++iel) |
| 1152 | { |
| 1153 | g_pserver->rgthreadvar[iel].lua_client = createClient(nullptr, iel); |
| 1154 | g_pserver->rgthreadvar[iel].lua_client->flags |= CLIENT_LUA; |
| 1155 | /* We do not want to allow blocking commands inside Lua */ |
| 1156 | g_pserver->rgthreadvar[iel].lua_client->flags |= CLIENT_DENY_BLOCKING; |
| 1157 | } |
| 1158 | g_pserver->lua_timedout = 0; |
| 1159 | g_pserver->lua_caller = NULL; |
| 1160 | g_pserver->lua_cur_script = NULL; |
| 1161 | ldbInit(); |
| 1162 | } |
| 1163 | |
| 1164 | luaLoadLibraries(lua); |
| 1165 | luaRemoveUnsupportedFunctions(lua); |
| 1166 | |
| 1167 | /* Initialize a dictionary we use to map SHAs to scripts. |
| 1168 | * This is useful for replication, as we need to replicate EVALSHA |
| 1169 | * as EVAL, so we need to remember the associated script. */ |
| 1170 | g_pserver->lua_scripts = dictCreate(&shaScriptObjectDictType,NULL); |
| 1171 | g_pserver->lua_scripts_mem = 0; |
| 1172 | |
| 1173 | /* Register the redis commands table and fields */ |
| 1174 | lua_newtable(lua); |
| 1175 | |
| 1176 | /* redis.call */ |
| 1177 | lua_pushstring(lua,"call"); |
| 1178 | lua_pushcfunction(lua,luaRedisCallCommand); |
| 1179 | lua_settable(lua,-3); |
| 1180 | |
| 1181 | /* redis.pcall */ |
| 1182 | lua_pushstring(lua,"pcall"); |
| 1183 | lua_pushcfunction(lua,luaRedisPCallCommand); |
| 1184 | lua_settable(lua,-3); |
| 1185 | |
| 1186 | /* redis.log and log levels. */ |
| 1187 | lua_pushstring(lua,"log"); |
| 1188 | lua_pushcfunction(lua,luaLogCommand); |
| 1189 | lua_settable(lua,-3); |
| 1190 | |
| 1191 | /* redis.setresp */ |
| 1192 | lua_pushstring(lua,"setresp"); |
| 1193 | lua_pushcfunction(lua,luaSetResp); |
| 1194 | lua_settable(lua,-3); |
| 1195 | |
| 1196 | lua_pushstring(lua,"LOG_DEBUG"); |
| 1197 | lua_pushnumber(lua,LL_DEBUG); |
| 1198 | lua_settable(lua,-3); |
| 1199 | |
| 1200 | lua_pushstring(lua,"LOG_VERBOSE"); |
| 1201 | lua_pushnumber(lua,LL_VERBOSE); |
| 1202 | lua_settable(lua,-3); |
| 1203 | |
| 1204 | lua_pushstring(lua,"LOG_NOTICE"); |
no test coverage detected