global variables starting with '.' are protected in Lua (temporarily at

least...)
This commit is contained in:
Roberto Ierusalimschy
1997-11-27 13:59:44 -02:00
parent ef37c87e93
commit 024528e0c2
2 changed files with 41 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
/*
** $Id: lbuiltin.c,v 1.9 1997/11/26 18:53:45 roberto Exp roberto $
** $Id: lbuiltin.c,v 1.10 1997/11/26 19:40:27 roberto Exp roberto $
** Built-in functions
** See Copyright Notice in lua.h
*/
@@ -217,19 +217,29 @@ static void luaI_assert (void)
}
static void check_globalname (char *n)
{
if (n[0] == '.')
luaL_verror("cannot change variable `%.50s' (starts with `.')", n);
}
static void setglobal (void)
{
char *n = luaL_check_string(1);
lua_Object value = luaL_nonnullarg(2);
check_globalname(n);
lua_pushobject(value);
lua_setglobal(luaL_check_string(1));
lua_setglobal(n);
lua_pushobject(value); /* return given value */
}
static void rawsetglobal (void)
{
char *n = luaL_check_string(1);
lua_Object value = luaL_nonnullarg(2);
check_globalname(n);
lua_pushobject(value);
lua_rawsetglobal(luaL_check_string(1));
lua_rawsetglobal(n);
lua_pushobject(value); /* return given value */
}