diff options
Diffstat (limited to 'lua.c')
| -rw-r--r-- | lua.c | 25 |
1 files changed, 16 insertions, 9 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lua.c,v 1.126 2004/05/31 18:51:50 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.127 2004/06/16 20:22:43 roberto Exp roberto $ |
| 3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
| 4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
| 5 | */ | 5 | */ |
| @@ -251,6 +251,14 @@ static void manual_input (void) { | |||
| 251 | } | 251 | } |
| 252 | 252 | ||
| 253 | 253 | ||
| 254 | static int checkvar (lua_State *l) { | ||
| 255 | const char *name = lua_tostring(l, 2); | ||
| 256 | if (name) | ||
| 257 | luaL_error(l, "attempt to access undefined variable `%s'", name); | ||
| 258 | return 0; | ||
| 259 | } | ||
| 260 | |||
| 261 | |||
| 254 | #define clearinteractive(i) (*i &= 2) | 262 | #define clearinteractive(i) (*i &= 2) |
| 255 | 263 | ||
| 256 | static int handle_argv (char *argv[], int *interactive) { | 264 | static int handle_argv (char *argv[], int *interactive) { |
| @@ -290,6 +298,13 @@ static int handle_argv (char *argv[], int *interactive) { | |||
| 290 | print_version(); | 298 | print_version(); |
| 291 | break; | 299 | break; |
| 292 | } | 300 | } |
| 301 | case 'w': { | ||
| 302 | if (lua_getmetatable(L, LUA_GLOBALSINDEX)) { | ||
| 303 | lua_pushcfunction(L, checkvar); | ||
| 304 | lua_setfield(L, -2, "__index"); | ||
| 305 | } | ||
| 306 | break; | ||
| 307 | } | ||
| 293 | case 'e': { | 308 | case 'e': { |
| 294 | const char *chunk = argv[i] + 2; | 309 | const char *chunk = argv[i] + 2; |
| 295 | clearinteractive(interactive); | 310 | clearinteractive(interactive); |
| @@ -313,14 +328,6 @@ static int handle_argv (char *argv[], int *interactive) { | |||
| 313 | return 1; /* stop if file fails */ | 328 | return 1; /* stop if file fails */ |
| 314 | break; | 329 | break; |
| 315 | } | 330 | } |
| 316 | case 'c': { | ||
| 317 | l_message(progname, "option `-c' is deprecated"); | ||
| 318 | break; | ||
| 319 | } | ||
| 320 | case 's': { | ||
| 321 | l_message(progname, "option `-s' is deprecated"); | ||
| 322 | break; | ||
| 323 | } | ||
| 324 | default: { | 331 | default: { |
| 325 | clearinteractive(interactive); | 332 | clearinteractive(interactive); |
| 326 | print_usage(); | 333 | print_usage(); |
