diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-22 15:40:00 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 1996-01-22 15:40:00 -0200 |
| commit | a19f9056f3194332b22fe9ae96cd7f24d39c7d82 (patch) | |
| tree | e334ef64896c393d27a1bd11b1c4bc551ad488da /inout.c | |
| parent | 5b71ab780cbe225548c3a741434b60e26ecb26be (diff) | |
| download | lua-a19f9056f3194332b22fe9ae96cd7f24d39c7d82.tar.gz lua-a19f9056f3194332b22fe9ae96cd7f24d39c7d82.tar.bz2 lua-a19f9056f3194332b22fe9ae96cd7f24d39c7d82.zip | |
new function "tostring".
Diffstat (limited to 'inout.c')
| -rw-r--r-- | inout.c | 51 |
1 files changed, 32 insertions, 19 deletions
| @@ -5,7 +5,7 @@ | |||
| 5 | ** Also provides some predefined lua functions. | 5 | ** Also provides some predefined lua functions. |
| 6 | */ | 6 | */ |
| 7 | 7 | ||
| 8 | char *rcs_inout="$Id: inout.c,v 2.24 1995/10/23 13:54:11 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.25 1995/10/25 13:05:51 roberto Exp roberto $"; |
| 9 | 9 | ||
| 10 | #include <stdio.h> | 10 | #include <stdio.h> |
| 11 | #include <stdlib.h> | 11 | #include <stdlib.h> |
| @@ -132,27 +132,40 @@ void lua_internaldofile (void) | |||
| 132 | lua_pushnil(); | 132 | lua_pushnil(); |
| 133 | } | 133 | } |
| 134 | 134 | ||
| 135 | /* | 135 | |
| 136 | ** Internal function: print object values | 136 | static char *tostring (lua_Object obj) |
| 137 | */ | ||
| 138 | void lua_print (void) | ||
| 139 | { | 137 | { |
| 140 | int i=1; | 138 | static char buff[20]; |
| 141 | lua_Object obj; | 139 | if (lua_isstring(obj)) |
| 142 | while ((obj=lua_getparam (i++)) != LUA_NOOBJECT) | 140 | return lua_getstring(obj); |
| 143 | { | 141 | if (lua_isnumber(obj)) |
| 144 | if (lua_isnumber(obj)) printf("%g\n",lua_getnumber(obj)); | 142 | sprintf(buff, "%g", lua_getnumber(obj)); |
| 145 | else if (lua_isstring(obj)) printf("%s\n",lua_getstring(obj)); | 143 | else if (lua_isfunction(obj)) |
| 146 | else if (lua_isfunction(obj)) printf("function: %p\n",(luaI_Address(obj))->value.tf); | 144 | sprintf(buff, "function: %p", (luaI_Address(obj))->value.tf); |
| 147 | else if (lua_iscfunction(obj)) printf("cfunction: %p\n",lua_getcfunction(obj) | 145 | else if (lua_iscfunction(obj)) |
| 148 | ); | 146 | sprintf(buff, "cfunction: %p", lua_getcfunction(obj)); |
| 149 | else if (lua_isuserdata(obj)) printf("userdata: %p\n",lua_getuserdata(obj)); | 147 | else if (lua_isuserdata(obj)) |
| 150 | else if (lua_istable(obj)) printf("table: %p\n",avalue(luaI_Address(obj))); | 148 | sprintf(buff, "userdata: %p", lua_getuserdata(obj)); |
| 151 | else if (lua_isnil(obj)) printf("nil\n"); | 149 | else if (lua_istable(obj)) |
| 152 | else printf("invalid value to print\n"); | 150 | sprintf(buff, "table: %p", avalue(luaI_Address(obj))); |
| 153 | } | 151 | else if (lua_isnil(obj)) |
| 152 | sprintf(buff, "nil"); | ||
| 153 | else buff[0] = 0; | ||
| 154 | return buff; | ||
| 154 | } | 155 | } |
| 155 | 156 | ||
| 157 | void luaI_tostring (void) | ||
| 158 | { | ||
| 159 | lua_pushstring(tostring(lua_getparam(1))); | ||
| 160 | } | ||
| 161 | |||
| 162 | void luaI_print (void) | ||
| 163 | { | ||
| 164 | int i = 1; | ||
| 165 | lua_Object obj; | ||
| 166 | while ((obj = lua_getparam(i++)) != LUA_NOOBJECT) | ||
| 167 | printf("%s\n", tostring(obj)); | ||
| 168 | } | ||
| 156 | 169 | ||
| 157 | /* | 170 | /* |
| 158 | ** Internal function: return an object type. | 171 | ** Internal function: return an object type. |
