diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-21 19:41:09 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1994-11-21 19:41:09 -0200 |
commit | bba1ae427fa914d5b7e8fea7b3aa2ad91fb3a4f6 (patch) | |
tree | d8298287c55a3b86eba619d8091e9c8fac4d91e9 | |
parent | 609392ff2e02eb44fa48c8563faf5994fc55297c (diff) | |
download | lua-bba1ae427fa914d5b7e8fea7b3aa2ad91fb3a4f6.tar.gz lua-bba1ae427fa914d5b7e8fea7b3aa2ad91fb3a4f6.tar.bz2 lua-bba1ae427fa914d5b7e8fea7b3aa2ad91fb3a4f6.zip |
new lua functions 'getglobal' and 'setglobal'
-rw-r--r-- | table.c | 38 |
1 files changed, 32 insertions, 6 deletions
@@ -3,7 +3,7 @@ | |||
3 | ** Module to control static tables | 3 | ** Module to control static tables |
4 | */ | 4 | */ |
5 | 5 | ||
6 | char *rcs_table="$Id: table.c,v 2.20 1994/11/17 13:58:57 roberto Exp roberto $"; | 6 | char *rcs_table="$Id: table.c,v 2.21 1994/11/18 19:27:38 roberto Exp roberto $"; |
7 | 7 | ||
8 | #include <string.h> | 8 | #include <string.h> |
9 | 9 | ||
@@ -37,6 +37,8 @@ int lua_nfile; | |||
37 | #define MIN_GARBAGE_BLOCK 10 | 37 | #define MIN_GARBAGE_BLOCK 10 |
38 | 38 | ||
39 | static void lua_nextvar (void); | 39 | static void lua_nextvar (void); |
40 | static void setglobal (void); | ||
41 | static void getglobal (void); | ||
40 | 42 | ||
41 | /* | 43 | /* |
42 | ** Initialise symbol table with internal functions | 44 | ** Initialise symbol table with internal functions |
@@ -48,6 +50,12 @@ static void lua_initsymbol (void) | |||
48 | lua_table = newvector(lua_maxsymbol, Symbol); | 50 | lua_table = newvector(lua_maxsymbol, Symbol); |
49 | n = luaI_findsymbolbyname("next"); | 51 | n = luaI_findsymbolbyname("next"); |
50 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next; | 52 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_next; |
53 | n = luaI_findsymbolbyname("dofile"); | ||
54 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldofile; | ||
55 | n = luaI_findsymbolbyname("setglobal"); | ||
56 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = setglobal; | ||
57 | n = luaI_findsymbolbyname("getglobal"); | ||
58 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = getglobal; | ||
51 | n = luaI_findsymbolbyname("nextvar"); | 59 | n = luaI_findsymbolbyname("nextvar"); |
52 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_nextvar; | 60 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_nextvar; |
53 | n = luaI_findsymbolbyname("type"); | 61 | n = luaI_findsymbolbyname("type"); |
@@ -56,8 +64,6 @@ static void lua_initsymbol (void) | |||
56 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_obj2number; | 64 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_obj2number; |
57 | n = luaI_findsymbolbyname("print"); | 65 | n = luaI_findsymbolbyname("print"); |
58 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_print; | 66 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_print; |
59 | n = luaI_findsymbolbyname("dofile"); | ||
60 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldofile; | ||
61 | n = luaI_findsymbolbyname("dostring"); | 67 | n = luaI_findsymbolbyname("dostring"); |
62 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring; | 68 | s_tag(n) = LUA_T_CFUNCTION; s_fvalue(n) = lua_internaldostring; |
63 | n = luaI_findsymbolbyname("setfallback"); | 69 | n = luaI_findsymbolbyname("setfallback"); |
@@ -219,14 +225,14 @@ static void lua_nextvar (void) | |||
219 | TreeNode *next; | 225 | TreeNode *next; |
220 | lua_Object o = lua_getparam(1); | 226 | lua_Object o = lua_getparam(1); |
221 | if (o == 0) | 227 | if (o == 0) |
222 | lua_error ("too few arguments to function `nextvar'"); | 228 | lua_reportbug("too few arguments to function `nextvar'"); |
223 | if (lua_getparam(2) != NULL) | 229 | if (lua_getparam(2) != NULL) |
224 | lua_error ("too many arguments to function `nextvar'"); | 230 | lua_reportbug("too many arguments to function `nextvar'"); |
225 | if (lua_isnil(o)) | 231 | if (lua_isnil(o)) |
226 | varname = NULL; | 232 | varname = NULL; |
227 | else if (!lua_isstring(o)) | 233 | else if (!lua_isstring(o)) |
228 | { | 234 | { |
229 | lua_error ("incorrect argument to function `nextvar'"); | 235 | lua_reportbug("incorrect argument to function `nextvar'"); |
230 | return; /* to avoid warnings */ | 236 | return; /* to avoid warnings */ |
231 | } | 237 | } |
232 | else | 238 | else |
@@ -246,3 +252,23 @@ static void lua_nextvar (void) | |||
246 | luaI_pushobject(&s_object(next->varindex)); | 252 | luaI_pushobject(&s_object(next->varindex)); |
247 | } | 253 | } |
248 | } | 254 | } |
255 | |||
256 | |||
257 | static void setglobal (void) | ||
258 | { | ||
259 | lua_Object name = lua_getparam(1); | ||
260 | lua_Object value = lua_getparam(2); | ||
261 | if (!lua_isstring(name)) | ||
262 | lua_reportbug("incorrect argument to function `setglobal'"); | ||
263 | lua_pushobject(value); | ||
264 | lua_storeglobal(lua_getstring(name)); | ||
265 | } | ||
266 | |||
267 | |||
268 | static void getglobal (void) | ||
269 | { | ||
270 | lua_Object name = lua_getparam(1); | ||
271 | if (!lua_isstring(name)) | ||
272 | lua_reportbug("incorrect argument to function `getglobal'"); | ||
273 | lua_pushobject(lua_getglobal(lua_getstring(name))); | ||
274 | } | ||