diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-11-27 13:59:44 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1997-11-27 13:59:44 -0200 |
commit | 024528e0c2ce75ac28ebbbc1220d4ae4045d3adf (patch) | |
tree | 5f147fede3540cfac8ef98c1bfeac5d99cf6157c /lbuiltin.c | |
parent | ef37c87e9333d825838d421e4652076b70c83a72 (diff) | |
download | lua-024528e0c2ce75ac28ebbbc1220d4ae4045d3adf.tar.gz lua-024528e0c2ce75ac28ebbbc1220d4ae4045d3adf.tar.bz2 lua-024528e0c2ce75ac28ebbbc1220d4ae4045d3adf.zip |
global variables starting with '.' are protected in Lua (temporarily at
least...)
Diffstat (limited to 'lbuiltin.c')
-rw-r--r-- | lbuiltin.c | 16 |
1 files changed, 13 insertions, 3 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbuiltin.c,v 1.9 1997/11/26 18:53:45 roberto Exp roberto $ | 2 | ** $Id: lbuiltin.c,v 1.10 1997/11/26 19:40:27 roberto Exp roberto $ |
3 | ** Built-in functions | 3 | ** Built-in functions |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -217,19 +217,29 @@ static void luaI_assert (void) | |||
217 | } | 217 | } |
218 | 218 | ||
219 | 219 | ||
220 | static void check_globalname (char *n) | ||
221 | { | ||
222 | if (n[0] == '.') | ||
223 | luaL_verror("cannot change variable `%.50s' (starts with `.')", n); | ||
224 | } | ||
225 | |||
220 | static void setglobal (void) | 226 | static void setglobal (void) |
221 | { | 227 | { |
228 | char *n = luaL_check_string(1); | ||
222 | lua_Object value = luaL_nonnullarg(2); | 229 | lua_Object value = luaL_nonnullarg(2); |
230 | check_globalname(n); | ||
223 | lua_pushobject(value); | 231 | lua_pushobject(value); |
224 | lua_setglobal(luaL_check_string(1)); | 232 | lua_setglobal(n); |
225 | lua_pushobject(value); /* return given value */ | 233 | lua_pushobject(value); /* return given value */ |
226 | } | 234 | } |
227 | 235 | ||
228 | static void rawsetglobal (void) | 236 | static void rawsetglobal (void) |
229 | { | 237 | { |
238 | char *n = luaL_check_string(1); | ||
230 | lua_Object value = luaL_nonnullarg(2); | 239 | lua_Object value = luaL_nonnullarg(2); |
240 | check_globalname(n); | ||
231 | lua_pushobject(value); | 241 | lua_pushobject(value); |
232 | lua_rawsetglobal(luaL_check_string(1)); | 242 | lua_rawsetglobal(n); |
233 | lua_pushobject(value); /* return given value */ | 243 | lua_pushobject(value); /* return given value */ |
234 | } | 244 | } |
235 | 245 | ||