Skip to content
Snippets Groups Projects
Commit d18fd90f authored by Alexander Turenko's avatar Alexander Turenko Committed by Igor Munkin
Browse files

lua: define _G.arg earlier

We're going to provide an ability to override a built-in module. The
code of an override module will work in a bit unusual circumstances: a
part of tarantool's Lua runtime is initialized, but a part isn't.

However, nothing prevents us from providing the `arg` global variable at
this stage. It used to be accessible anywhere in a user defined code.
Let's keep this property by making it accessible from an override
module.

Part of #7774

NO_TEST=It will be tested as part of the override feature.
NO_CHANGELOG=It is not possible to execute any user provided code at
             this loading stage until modules overriding will be
             implemented. So this commit doesn't change any behavior
             that a user might observe before this commit.
NO_DOC=It spreads exiting runtime guarantee to a new stage, where a user
       defined code may appear. Nothing new is introduced.
parent 7e9051c4
No related branches found
No related tags found
No related merge requests found
......@@ -843,6 +843,18 @@ tarantool_lua_init(const char *tarantool_bin, int argc, char **argv)
}
luaL_openlibs(L);
/* Set _G.arg. */
lua_newtable(L);
lua_pushinteger(L, -1);
lua_pushstring(L, tarantool_bin);
lua_settable(L, -3);
for (int i = 0; i < argc; i++) {
lua_pushinteger(L, i);
lua_pushstring(L, argv[i]);
lua_settable(L, -3);
}
lua_setfield(L, LUA_GLOBALSINDEX, "arg");
/*
* Create a table for storing loaded built-in modules.
* Similar to _LOADED (package.loaded).
......@@ -941,17 +953,6 @@ tarantool_lua_init(const char *tarantool_bin, int argc, char **argv)
luaopen_tarantool(L);
lua_newtable(L);
lua_pushinteger(L, -1);
lua_pushstring(L, tarantool_bin);
lua_settable(L, -3);
for (int i = 0; i < argc; i++) {
lua_pushinteger(L, i);
lua_pushstring(L, argv[i]);
lua_settable(L, -3);
}
lua_setfield(L, LUA_GLOBALSINDEX, "arg");
#ifdef NDEBUG
/* Unload strict after boot in release mode */
if (luaL_dostring(L, "require('strict').off()") != 0)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment