Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
ruanhaishen
redis
Commits
6255a5ae
"vscode:/vscode.git/clone" did not exist on "f2aa84bd638b8d18e80531abfd7191f5d0a58c71"
Commit
6255a5ae
authored
Apr 13, 2012
by
antirez
Browse files
Globals protection global() function modified for speed and correctness.
parent
e387dc52
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/scripting.c
View file @
6255a5ae
...
@@ -427,7 +427,7 @@ void scriptingEnableGlobalsProtection(lua_State *lua) {
...
@@ -427,7 +427,7 @@ void scriptingEnableGlobalsProtection(lua_State *lua) {
/* strict.lua from: http://metalua.luaforge.net/src/lib/strict.lua.html.
/* strict.lua from: http://metalua.luaforge.net/src/lib/strict.lua.html.
* Modified to be adapted to Redis. */
* Modified to be adapted to Redis. */
s
[
j
++
]
=
"mt = {}
\n
"
;
s
[
j
++
]
=
"
local
mt = {}
\n
"
;
s
[
j
++
]
=
"setmetatable(_G, mt)
\n
"
;
s
[
j
++
]
=
"setmetatable(_G, mt)
\n
"
;
s
[
j
++
]
=
"mt.declared = {}
\n
"
;
s
[
j
++
]
=
"mt.declared = {}
\n
"
;
s
[
j
++
]
=
"mt.__newindex = function (t, n, v)
\n
"
;
s
[
j
++
]
=
"mt.__newindex = function (t, n, v)
\n
"
;
...
@@ -447,7 +447,11 @@ void scriptingEnableGlobalsProtection(lua_State *lua) {
...
@@ -447,7 +447,11 @@ void scriptingEnableGlobalsProtection(lua_State *lua) {
s
[
j
++
]
=
" return rawget(t, n)
\n
"
;
s
[
j
++
]
=
" return rawget(t, n)
\n
"
;
s
[
j
++
]
=
"end
\n
"
;
s
[
j
++
]
=
"end
\n
"
;
s
[
j
++
]
=
"function global(...)
\n
"
;
s
[
j
++
]
=
"function global(...)
\n
"
;
s
[
j
++
]
=
" for _, v in ipairs{...} do mt.declared[v] = true end
\n
"
;
s
[
j
++
]
=
" local nargs = select(
\"
#
\"
,...)
\n
"
;
s
[
j
++
]
=
" for i = 1, nargs do
\n
"
;
s
[
j
++
]
=
" local v = select(i,...)
\n
"
;
s
[
j
++
]
=
" mt.declared[v] = true
\n
"
;
s
[
j
++
]
=
" end
\n
"
;
s
[
j
++
]
=
"end
\n
"
;
s
[
j
++
]
=
"end
\n
"
;
s
[
j
++
]
=
NULL
;
s
[
j
++
]
=
NULL
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment