aboutsummaryrefslogtreecommitdiff
path: root/inout.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-03-19 19:28:37 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-03-19 19:28:37 -0300
commita275d9a25b161af426696d7b73d46f91150309c9 (patch)
tree763a5694213fe30b231bc81777cec71828935696 /inout.c
parent7e0be1fbde80d72886e11bcbf114a8dbf6d5e1d9 (diff)
downloadlua-a275d9a25b161af426696d7b73d46f91150309c9.tar.gz
lua-a275d9a25b161af426696d7b73d46f91150309c9.tar.bz2
lua-a275d9a25b161af426696d7b73d46f91150309c9.zip
functions "lua_is..." consider coercions.
Diffstat (limited to 'inout.c')
-rw-r--r--inout.c46
1 files changed, 21 insertions, 25 deletions
diff --git a/inout.c b/inout.c
index 0582522c..294d4137 100644
--- a/inout.c
+++ b/inout.c
@@ -5,7 +5,7 @@
5** Also provides some predefined lua functions. 5** Also provides some predefined lua functions.
6*/ 6*/
7 7
8char *rcs_inout="$Id: inout.c,v 2.34 1996/03/15 13:13:13 roberto Exp roberto $"; 8char *rcs_inout="$Id: inout.c,v 2.35 1996/03/19 16:50:24 roberto Exp roberto $";
9 9
10#include <stdio.h> 10#include <stdio.h>
11 11
@@ -128,21 +128,26 @@ void lua_internaldofile (void)
128static char *tostring (lua_Object obj) 128static char *tostring (lua_Object obj)
129{ 129{
130 char *buff = luaI_buffer(20); 130 char *buff = luaI_buffer(20);
131 if (lua_isstring(obj)) 131 if (lua_isstring(obj)) /* get strings and numbers */
132 return lua_getstring(obj); 132 return lua_getstring(obj);
133 if (lua_isnumber(obj)) 133 else switch(lua_type(obj))
134 sprintf(buff, "%g", lua_getnumber(obj)); 134 {
135 else if (lua_isfunction(obj)) 135 case LUA_T_FUNCTION:
136 sprintf(buff, "function: %p", (luaI_Address(obj))->value.tf); 136 sprintf(buff, "function: %p", (luaI_Address(obj))->value.tf);
137 else if (lua_iscfunction(obj)) 137 break;
138 sprintf(buff, "cfunction: %p", lua_getcfunction(obj)); 138 case LUA_T_CFUNCTION:
139 else if (lua_isuserdata(obj)) 139 sprintf(buff, "cfunction: %p", lua_getcfunction(obj));
140 sprintf(buff, "userdata: %p", lua_getuserdata(obj)); 140 break;
141 else if (lua_istable(obj)) 141 case LUA_T_ARRAY:
142 sprintf(buff, "table: %p", avalue(luaI_Address(obj))); 142 sprintf(buff, "table: %p", avalue(luaI_Address(obj)));
143 else if (lua_isnil(obj)) 143 break;
144 sprintf(buff, "nil"); 144 case LUA_T_NIL:
145 else buff[0] = 0; 145 sprintf(buff, "nil");
146 break;
147 default:
148 sprintf(buff, "userdata: %p", lua_getuserdata(obj));
149 break;
150 }
146 return buff; 151 return buff;
147} 152}
148 153
@@ -201,16 +206,7 @@ void lua_obj2number (void)
201{ 206{
202 lua_Object o = lua_getparam(1); 207 lua_Object o = lua_getparam(1);
203 if (lua_isnumber(o)) 208 if (lua_isnumber(o))
204 lua_pushobject(o); 209 lua_pushnumber(lua_getnumber(o));
205 else if (lua_isstring(o))
206 {
207 char c;
208 float f;
209 if (sscanf(lua_getstring(o),"%f %c",&f,&c) == 1)
210 lua_pushnumber(f);
211 else
212 lua_pushnil();
213 }
214 else 210 else
215 lua_pushnil(); 211 lua_pushnil();
216} 212}