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
| 1129 | * |
| 1130 | * However it is simpler to just call scriptingReset() that does just that. */ |
| 1131 | void scriptingInit(int setup) { |
| 1132 | lua_State *lua = lua_open(); |
| 1133 | |
| 1134 | if (setup) { |
| 1135 | server.lua_client = NULL; |
| 1136 | server.lua_caller = NULL; |
| 1137 | server.lua_cur_script = NULL; |
| 1138 | server.lua_timedout = 0; |
| 1139 | ldbInit(); |
| 1140 | } |
| 1141 | |
| 1142 | luaLoadLibraries(lua); |
| 1143 | luaRemoveUnsupportedFunctions(lua); |
| 1144 | |
| 1145 | /* Initialize a dictionary we use to map SHAs to scripts. |
| 1146 | * This is useful for replication, as we need to replicate EVALSHA |
| 1147 | * as EVAL, so we need to remember the associated script. */ |
| 1148 | server.lua_scripts = dictCreate(&shaScriptObjectDictType,NULL); |
| 1149 | server.lua_scripts_mem = 0; |
| 1150 | |
| 1151 | /* Register the redis commands table and fields */ |
| 1152 | lua_newtable(lua); |
| 1153 | |
| 1154 | /* redis.call */ |
| 1155 | lua_pushstring(lua,"call"); |
| 1156 | lua_pushcfunction(lua,luaRedisCallCommand); |
| 1157 | lua_settable(lua,-3); |
| 1158 | |
| 1159 | /* redis.pcall */ |
| 1160 | lua_pushstring(lua,"pcall"); |
| 1161 | lua_pushcfunction(lua,luaRedisPCallCommand); |
| 1162 | lua_settable(lua,-3); |
| 1163 | |
| 1164 | /* redis.log and log levels. */ |
| 1165 | lua_pushstring(lua,"log"); |
| 1166 | lua_pushcfunction(lua,luaLogCommand); |
| 1167 | lua_settable(lua,-3); |
| 1168 | |
| 1169 | /* redis.setresp */ |
| 1170 | lua_pushstring(lua,"setresp"); |
| 1171 | lua_pushcfunction(lua,luaSetResp); |
| 1172 | lua_settable(lua,-3); |
| 1173 | |
| 1174 | lua_pushstring(lua,"LOG_DEBUG"); |
| 1175 | lua_pushnumber(lua,LL_DEBUG); |
| 1176 | lua_settable(lua,-3); |
| 1177 | |
| 1178 | lua_pushstring(lua,"LOG_VERBOSE"); |
| 1179 | lua_pushnumber(lua,LL_VERBOSE); |
| 1180 | lua_settable(lua,-3); |
| 1181 | |
| 1182 | lua_pushstring(lua,"LOG_NOTICE"); |
| 1183 | lua_pushnumber(lua,LL_NOTICE); |
| 1184 | lua_settable(lua,-3); |
| 1185 | |
| 1186 | lua_pushstring(lua,"LOG_WARNING"); |
| 1187 | lua_pushnumber(lua,LL_WARNING); |
| 1188 | lua_settable(lua,-3); |
no test coverage detected