diff options
| -rw-r--r-- | inout.c | 49 |
1 files changed, 37 insertions, 12 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.51 1997/04/01 17:31:42 roberto Exp roberto $"; | 8 | char *rcs_inout="$Id: inout.c,v 2.52 1997/04/01 19:02:43 roberto Exp roberto $"; |
| 9 | 9 | ||
| 10 | #include <stdio.h> | 10 | #include <stdio.h> |
| 11 | #include <string.h> | 11 | #include <string.h> |
| @@ -20,6 +20,7 @@ char *rcs_inout="$Id: inout.c,v 2.51 1997/04/01 17:31:42 roberto Exp roberto $"; | |||
| 20 | #include "hash.h" | 20 | #include "hash.h" |
| 21 | #include "luamem.h" | 21 | #include "luamem.h" |
| 22 | #include "fallback.h" | 22 | #include "fallback.h" |
| 23 | #include "luamem.h" | ||
| 23 | 24 | ||
| 24 | 25 | ||
| 25 | /* Exported variables */ | 26 | /* Exported variables */ |
| @@ -27,6 +28,12 @@ Word lua_linenumber; | |||
| 27 | char *lua_parsedfile; | 28 | char *lua_parsedfile; |
| 28 | 29 | ||
| 29 | 30 | ||
| 31 | static char *typenames[] = { /* ORDER LUA_T */ | ||
| 32 | "userdata", "line", "cmark", "mark", "function", | ||
| 33 | "function", "table", "string", "number", "nil", | ||
| 34 | NULL | ||
| 35 | }; | ||
| 36 | |||
| 30 | static FILE *fp; | 37 | static FILE *fp; |
| 31 | static char *st; | 38 | static char *st; |
| 32 | 39 | ||
| @@ -135,16 +142,26 @@ static void lua_internaldofile (void) | |||
| 135 | 142 | ||
| 136 | static char *tostring (lua_Object obj) | 143 | static char *tostring (lua_Object obj) |
| 137 | { | 144 | { |
| 138 | if (lua_isstring(obj)) /* get strings and numbers */ | 145 | TObject *o = luaI_Address(obj); |
| 139 | return lua_getstring(obj); | 146 | switch (ttype(o)) { |
| 140 | else if (lua_istable(obj)) | 147 | case LUA_T_NUMBER: case LUA_T_STRING: |
| 141 | return "<table>"; | 148 | return lua_getstring(obj); |
| 142 | else if (lua_isfunction(obj)) | 149 | case LUA_T_ARRAY: case LUA_T_FUNCTION: |
| 143 | return "<function>"; | 150 | case LUA_T_CFUNCTION: case LUA_T_NIL: |
| 144 | else if (lua_isnil(obj)) | 151 | return typenames[-ttype(o)]; |
| 145 | return "nil"; | 152 | case LUA_T_USERDATA: { |
| 146 | else /* if (lua_isuserdata(obj)) */ | 153 | char *buff = luaI_buffer(100); |
| 147 | return "<userdata>"; | 154 | int size = o->value.ts->size; |
| 155 | int i; | ||
| 156 | strcpy(buff, "userdata: "); | ||
| 157 | if (size > 10) size = 10; | ||
| 158 | for (i=0; i<size; i++) | ||
| 159 | sprintf(buff+strlen(buff), "%.2X", | ||
| 160 | (int)(unsigned char)o->value.ts->str[i]); | ||
| 161 | return buff; | ||
| 162 | } | ||
| 163 | default: return "<unknown object>"; | ||
| 164 | } | ||
| 148 | } | 165 | } |
| 149 | 166 | ||
| 150 | static void luaI_tostring (void) | 167 | static void luaI_tostring (void) |
| @@ -160,6 +177,14 @@ static void luaI_print (void) | |||
| 160 | printf("%s\n", tostring(obj)); | 177 | printf("%s\n", tostring(obj)); |
| 161 | } | 178 | } |
| 162 | 179 | ||
| 180 | static void luaI_type (void) | ||
| 181 | { | ||
| 182 | lua_Object o = lua_getparam(1); | ||
| 183 | luaL_arg_check(o != LUA_NOOBJECT, "type", 1, "no argument"); | ||
| 184 | lua_pushstring(typenames[-ttype(luaI_Address(o))]); | ||
| 185 | lua_pushnumber(lua_tag(o)); | ||
| 186 | } | ||
| 187 | |||
| 163 | /* | 188 | /* |
| 164 | ** Internal function: convert an object to a number | 189 | ** Internal function: convert an object to a number |
| 165 | */ | 190 | */ |
| @@ -263,7 +288,7 @@ static void luaIl_settag (void) | |||
| 263 | 288 | ||
| 264 | static void luaIl_newtag (void) | 289 | static void luaIl_newtag (void) |
| 265 | { | 290 | { |
| 266 | lua_pushnumber(lua_newtag(luaL_check_string(1, "newtag"))); | 291 | lua_pushnumber(lua_newtag()); |
| 267 | } | 292 | } |
| 268 | 293 | ||
| 269 | static void basicindex (void) | 294 | static void basicindex (void) |
