MCPcopy Create free account
hub / github.com/Tencent/Tendis / initLua

Method initLua

src/tendisplus/script/lua_state.cpp:714–850  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

712 *
713 * However it is simpler to just call scriptingReset() that does just that. */
714lua_State* LuaState::initLua(int setup) {
715 lua_State* lua = lua_open();
716
717 if (setup) {
718 _sess = nullptr;
719 _fakeSess = nullptr;
720 lua_timedout = 0;
721 }
722
723 luaLoadLibraries(lua);
724 luaRemoveUnsupportedFunctions(lua);
725
726 /* NOTE(takenliu): dont support lua_scripts dictionary*/
727
728 /* Register the redis commands table and fields */
729 lua_newtable(lua);
730
731 /* redis.call */
732 lua_pushstring(lua, "call");
733 lua_pushcfunction(lua, luaRedisCallCommand);
734 lua_settable(lua, -3);
735
736 /* redis.pcall */
737 lua_pushstring(lua, "pcall");
738 lua_pushcfunction(lua, luaRedisPCallCommand);
739 lua_settable(lua, -3);
740
741 /* redis.log and log levels. */
742 lua_pushstring(lua, "log");
743 lua_pushcfunction(lua, luaLogCommand);
744 lua_settable(lua, -3);
745
746 lua_pushstring(lua, "LOG_DEBUG");
747 lua_pushnumber(lua, LL_DEBUG);
748 lua_settable(lua, -3);
749
750 lua_pushstring(lua, "LOG_VERBOSE");
751 lua_pushnumber(lua, LL_VERBOSE);
752 lua_settable(lua, -3);
753
754 lua_pushstring(lua, "LOG_NOTICE");
755 lua_pushnumber(lua, LL_NOTICE);
756 lua_settable(lua, -3);
757
758 lua_pushstring(lua, "LOG_WARNING");
759 lua_pushnumber(lua, LL_WARNING);
760 lua_settable(lua, -3);
761
762 /* redis.sha1hex */
763 lua_pushstring(lua, "sha1hex");
764 lua_pushcfunction(lua, luaRedisSha1hexCommand);
765 lua_settable(lua, -3);
766
767 /* redis.error_reply and redis.status_reply */
768 lua_pushstring(lua, "error_reply");
769 lua_pushcfunction(lua, luaRedisErrorReplyCommand);
770 lua_settable(lua, -3);
771 lua_pushstring(lua, "status_reply");

Callers

nothing calls this directly

Calls 2

luaLoadLibrariesFunction · 0.85

Tested by

no test coverage detected