diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1993-12-30 12:52:18 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1993-12-30 12:52:18 -0200 |
| commit | 8886f221bcb7eec0a629a072a211b498ef4dd92c (patch) | |
| tree | ef0dde3f53872344e528f163d84639c876d358d2 | |
| parent | 019aa98f806c499dc5d109610cd040206ae768ae (diff) | |
| download | lua-8886f221bcb7eec0a629a072a211b498ef4dd92c.tar.gz lua-8886f221bcb7eec0a629a072a211b498ef4dd92c.tar.bz2 lua-8886f221bcb7eec0a629a072a211b498ef4dd92c.zip | |
1) execute retorna resultado Unix da execucao do comando.
2) correcao parcial da read: retorna nil quando encontra EOF.
Diffstat (limited to '')
| -rw-r--r-- | iolib.c | 25 |
1 files changed, 14 insertions, 11 deletions
| @@ -3,7 +3,7 @@ | |||
| 3 | ** Input/output library to LUA | 3 | ** Input/output library to LUA |
| 4 | */ | 4 | */ |
| 5 | 5 | ||
| 6 | char *rcs_iolib="$Id: $"; | 6 | char *rcs_iolib="$Id: iolib.c,v 1.1 1993/12/17 18:41:19 celes Exp roberto $"; |
| 7 | 7 | ||
| 8 | #include <stdlib.h> | 8 | #include <stdlib.h> |
| 9 | #include <string.h> | 9 | #include <string.h> |
| @@ -272,22 +272,25 @@ static void io_read (void) | |||
| 272 | case 'i': | 272 | case 'i': |
| 273 | { | 273 | { |
| 274 | long int l; | 274 | long int l; |
| 275 | fscanf (in, "%ld", &l); | 275 | if (fscanf (in, "%ld", &l) == EOF) |
| 276 | lua_pushnumber(l); | 276 | lua_pushnil(); |
| 277 | else lua_pushnumber(l); | ||
| 277 | } | 278 | } |
| 278 | break; | 279 | break; |
| 279 | case 'f': case 'g': case 'e': | 280 | case 'f': case 'g': case 'e': |
| 280 | { | 281 | { |
| 281 | float f; | 282 | float f; |
| 282 | fscanf (in, "%f", &f); | 283 | if (fscanf (in, "%f", &f) == EOF) |
| 283 | lua_pushnumber(f); | 284 | lua_pushnil(); |
| 285 | else lua_pushnumber(f); | ||
| 284 | } | 286 | } |
| 285 | break; | 287 | break; |
| 286 | default: | 288 | default: |
| 287 | { | 289 | { |
| 288 | char s[256]; | 290 | char s[256]; |
| 289 | fscanf (in, "%s", s); | 291 | if (fscanf (in, "%s", s) == EOF) |
| 290 | lua_pushstring(s); | 292 | lua_pushnil(); |
| 293 | else lua_pushstring(s); | ||
| 291 | } | 294 | } |
| 292 | break; | 295 | break; |
| 293 | } | 296 | } |
| @@ -406,8 +409,8 @@ static void io_write (void) | |||
| 406 | } | 409 | } |
| 407 | 410 | ||
| 408 | /* | 411 | /* |
| 409 | ** Execute a executable program using "sustem". | 412 | ** Execute a executable program using "system". |
| 410 | ** On error put 0 on stack, otherwise put 1. | 413 | ** Return the result of execution. |
| 411 | */ | 414 | */ |
| 412 | void io_execute (void) | 415 | void io_execute (void) |
| 413 | { | 416 | { |
| @@ -419,8 +422,8 @@ void io_execute (void) | |||
| 419 | } | 422 | } |
| 420 | else | 423 | else |
| 421 | { | 424 | { |
| 422 | system(lua_getstring(o)); | 425 | int res = system(lua_getstring(o)); |
| 423 | lua_pushnumber (1); | 426 | lua_pushnumber (res); |
| 424 | } | 427 | } |
| 425 | return; | 428 | return; |
| 426 | } | 429 | } |
