diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-02-02 16:54:58 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1995-02-02 16:54:58 -0200 |
commit | 61986261385344e176faa2a06d0351954b89cff9 (patch) | |
tree | 9f07f5c76abf1586789e72455ce2a4a5c727619f | |
parent | 8795aab83ed89f6a93d71d36c8cc37a4887581b2 (diff) | |
download | lua-61986261385344e176faa2a06d0351954b89cff9.tar.gz lua-61986261385344e176faa2a06d0351954b89cff9.tar.bz2 lua-61986261385344e176faa2a06d0351954b89cff9.zip |
libs should not use Lua internal functions (like mem.h).
a null lua_Object is LUA_NOOBJECT, not NULL.
-rw-r--r-- | iolib.c | 25 |
1 files changed, 12 insertions, 13 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: iolib.c,v 1.17 1994/12/13 15:55:41 roberto Exp $"; | 6 | char *rcs_iolib="$Id: iolib.c,v 1.19 1995/01/03 13:14:13 celes Exp roberto $"; |
7 | 7 | ||
8 | #include <stdio.h> | 8 | #include <stdio.h> |
9 | #include <ctype.h> | 9 | #include <ctype.h> |
@@ -12,7 +12,6 @@ char *rcs_iolib="$Id: iolib.c,v 1.17 1994/12/13 15:55:41 roberto Exp $"; | |||
12 | #include <time.h> | 12 | #include <time.h> |
13 | #include <stdlib.h> | 13 | #include <stdlib.h> |
14 | 14 | ||
15 | #include "mem.h" | ||
16 | #include "lua.h" | 15 | #include "lua.h" |
17 | #include "lualib.h" | 16 | #include "lualib.h" |
18 | 17 | ||
@@ -29,7 +28,7 @@ static FILE *in=stdin, *out=stdout; | |||
29 | static void io_readfrom (void) | 28 | static void io_readfrom (void) |
30 | { | 29 | { |
31 | lua_Object o = lua_getparam (1); | 30 | lua_Object o = lua_getparam (1); |
32 | if (o == NULL) /* restore standart input */ | 31 | if (o == LUA_NOOBJECT) /* restore standart input */ |
33 | { | 32 | { |
34 | if (in != stdin) | 33 | if (in != stdin) |
35 | { | 34 | { |
@@ -74,7 +73,7 @@ static void io_readfrom (void) | |||
74 | static void io_writeto (void) | 73 | static void io_writeto (void) |
75 | { | 74 | { |
76 | lua_Object o = lua_getparam (1); | 75 | lua_Object o = lua_getparam (1); |
77 | if (o == NULL) /* restore standart output */ | 76 | if (o == LUA_NOOBJECT) /* restore standart output */ |
78 | { | 77 | { |
79 | if (out != stdout) | 78 | if (out != stdout) |
80 | { | 79 | { |
@@ -120,7 +119,7 @@ static void io_writeto (void) | |||
120 | static void io_appendto (void) | 119 | static void io_appendto (void) |
121 | { | 120 | { |
122 | lua_Object o = lua_getparam (1); | 121 | lua_Object o = lua_getparam (1); |
123 | if (o == NULL) /* restore standart output */ | 122 | if (o == LUA_NOOBJECT) /* restore standart output */ |
124 | { | 123 | { |
125 | if (out != stdout) | 124 | if (out != stdout) |
126 | { | 125 | { |
@@ -177,7 +176,7 @@ static void io_appendto (void) | |||
177 | static void io_read (void) | 176 | static void io_read (void) |
178 | { | 177 | { |
179 | lua_Object o = lua_getparam (1); | 178 | lua_Object o = lua_getparam (1); |
180 | if (o == NULL || !lua_isstring(o)) /* free format */ | 179 | if (o == LUA_NOOBJECT || !lua_isstring(o)) /* free format */ |
181 | { | 180 | { |
182 | int c; | 181 | int c; |
183 | char s[256]; | 182 | char s[256]; |
@@ -323,20 +322,20 @@ static void io_readuntil (void) | |||
323 | else | 322 | else |
324 | d = *lua_getstring(lo); | 323 | d = *lua_getstring(lo); |
325 | 324 | ||
326 | s = newvector(n+1, char); | 325 | s = (char *)malloc(n+1); |
327 | while((c = fgetc(in)) != EOF && c != d) | 326 | while((c = fgetc(in)) != EOF && c != d) |
328 | { | 327 | { |
329 | if (m==n) | 328 | if (m==n) |
330 | { | 329 | { |
331 | n *= 2; | 330 | n *= 2; |
332 | s = growvector(s, n+1, char); | 331 | s = (char *)realloc(s, n+1); |
333 | } | 332 | } |
334 | s[m++] = c; | 333 | s[m++] = c; |
335 | } | 334 | } |
336 | if (c != EOF) ungetc(c,in); | 335 | if (c != EOF) ungetc(c,in); |
337 | s[m] = 0; | 336 | s[m] = 0; |
338 | lua_pushstring(s); | 337 | lua_pushstring(s); |
339 | luaI_free(s); | 338 | free(s); |
340 | } | 339 | } |
341 | 340 | ||
342 | 341 | ||
@@ -443,12 +442,12 @@ static void io_write (void) | |||
443 | { | 442 | { |
444 | lua_Object o1 = lua_getparam (1); | 443 | lua_Object o1 = lua_getparam (1); |
445 | lua_Object o2 = lua_getparam (2); | 444 | lua_Object o2 = lua_getparam (2); |
446 | if (o1 == NULL) /* new line */ | 445 | if (o1 == LUA_NOOBJECT) /* new line */ |
447 | { | 446 | { |
448 | fprintf (out, "\n"); | 447 | fprintf (out, "\n"); |
449 | lua_pushnumber(1); | 448 | lua_pushnumber(1); |
450 | } | 449 | } |
451 | else if (o2 == NULL) /* free format */ | 450 | else if (o2 == LUA_NOOBJECT) /* free format */ |
452 | { | 451 | { |
453 | int status=0; | 452 | int status=0; |
454 | if (lua_isnumber(o1)) | 453 | if (lua_isnumber(o1)) |
@@ -476,7 +475,7 @@ static void io_write (void) | |||
476 | static void io_execute (void) | 475 | static void io_execute (void) |
477 | { | 476 | { |
478 | lua_Object o = lua_getparam (1); | 477 | lua_Object o = lua_getparam (1); |
479 | if (o == NULL || !lua_isstring (o)) | 478 | if (o == LUA_NOOBJECT || !lua_isstring (o)) |
480 | { | 479 | { |
481 | lua_error ("incorrect argument to function 'execute`"); | 480 | lua_error ("incorrect argument to function 'execute`"); |
482 | lua_pushnumber (0); | 481 | lua_pushnumber (0); |
@@ -496,7 +495,7 @@ static void io_execute (void) | |||
496 | static void io_remove (void) | 495 | static void io_remove (void) |
497 | { | 496 | { |
498 | lua_Object o = lua_getparam (1); | 497 | lua_Object o = lua_getparam (1); |
499 | if (o == NULL || !lua_isstring (o)) | 498 | if (o == LUA_NOOBJECT || !lua_isstring (o)) |
500 | { | 499 | { |
501 | lua_error ("incorrect argument to function 'execute`"); | 500 | lua_error ("incorrect argument to function 'execute`"); |
502 | lua_pushnumber (0); | 501 | lua_pushnumber (0); |