functions "lua_is..." consider coercions.
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
** TecCGraf - PUC-Rio
|
** TecCGraf - PUC-Rio
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_fallback="$Id: fallback.c,v 1.20 1996/02/22 20:34:33 roberto Exp roberto $";
|
char *rcs_fallback="$Id: fallback.c,v 1.21 1996/03/04 13:29:10 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
@@ -49,7 +49,7 @@ void luaI_setfallback (void)
|
|||||||
int i;
|
int i;
|
||||||
char *name = lua_getstring(lua_getparam(1));
|
char *name = lua_getstring(lua_getparam(1));
|
||||||
lua_Object func = lua_getparam(2);
|
lua_Object func = lua_getparam(2);
|
||||||
if (name == NULL || !(lua_isfunction(func) || lua_iscfunction(func)))
|
if (name == NULL || !lua_isfunction(func))
|
||||||
lua_error("incorrect argument to function `setfallback'");
|
lua_error("incorrect argument to function `setfallback'");
|
||||||
for (i=0; i<N_FB; i++)
|
for (i=0; i<N_FB; i++)
|
||||||
{
|
{
|
||||||
|
|||||||
38
inout.c
38
inout.c
@@ -5,7 +5,7 @@
|
|||||||
** Also provides some predefined lua functions.
|
** Also provides some predefined lua functions.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_inout="$Id: inout.c,v 2.34 1996/03/15 13:13:13 roberto Exp roberto $";
|
char *rcs_inout="$Id: inout.c,v 2.35 1996/03/19 16:50:24 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
@@ -128,21 +128,26 @@ void lua_internaldofile (void)
|
|||||||
static char *tostring (lua_Object obj)
|
static char *tostring (lua_Object obj)
|
||||||
{
|
{
|
||||||
char *buff = luaI_buffer(20);
|
char *buff = luaI_buffer(20);
|
||||||
if (lua_isstring(obj))
|
if (lua_isstring(obj)) /* get strings and numbers */
|
||||||
return lua_getstring(obj);
|
return lua_getstring(obj);
|
||||||
if (lua_isnumber(obj))
|
else switch(lua_type(obj))
|
||||||
sprintf(buff, "%g", lua_getnumber(obj));
|
{
|
||||||
else if (lua_isfunction(obj))
|
case LUA_T_FUNCTION:
|
||||||
sprintf(buff, "function: %p", (luaI_Address(obj))->value.tf);
|
sprintf(buff, "function: %p", (luaI_Address(obj))->value.tf);
|
||||||
else if (lua_iscfunction(obj))
|
break;
|
||||||
|
case LUA_T_CFUNCTION:
|
||||||
sprintf(buff, "cfunction: %p", lua_getcfunction(obj));
|
sprintf(buff, "cfunction: %p", lua_getcfunction(obj));
|
||||||
else if (lua_isuserdata(obj))
|
break;
|
||||||
sprintf(buff, "userdata: %p", lua_getuserdata(obj));
|
case LUA_T_ARRAY:
|
||||||
else if (lua_istable(obj))
|
|
||||||
sprintf(buff, "table: %p", avalue(luaI_Address(obj)));
|
sprintf(buff, "table: %p", avalue(luaI_Address(obj)));
|
||||||
else if (lua_isnil(obj))
|
break;
|
||||||
|
case LUA_T_NIL:
|
||||||
sprintf(buff, "nil");
|
sprintf(buff, "nil");
|
||||||
else buff[0] = 0;
|
break;
|
||||||
|
default:
|
||||||
|
sprintf(buff, "userdata: %p", lua_getuserdata(obj));
|
||||||
|
break;
|
||||||
|
}
|
||||||
return buff;
|
return buff;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,16 +206,7 @@ void lua_obj2number (void)
|
|||||||
{
|
{
|
||||||
lua_Object o = lua_getparam(1);
|
lua_Object o = lua_getparam(1);
|
||||||
if (lua_isnumber(o))
|
if (lua_isnumber(o))
|
||||||
lua_pushobject(o);
|
lua_pushnumber(lua_getnumber(o));
|
||||||
else if (lua_isstring(o))
|
|
||||||
{
|
|
||||||
char c;
|
|
||||||
float f;
|
|
||||||
if (sscanf(lua_getstring(o),"%f %c",&f,&c) == 1)
|
|
||||||
lua_pushnumber(f);
|
|
||||||
else
|
|
||||||
lua_pushnil();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
lua_pushnil();
|
lua_pushnil();
|
||||||
}
|
}
|
||||||
|
|||||||
7
iolib.c
7
iolib.c
@@ -3,7 +3,7 @@
|
|||||||
** Input/output library to LUA
|
** Input/output library to LUA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_iolib="$Id: iolib.c,v 1.38 1996/03/12 15:56:03 roberto Exp roberto $";
|
char *rcs_iolib="$Id: iolib.c,v 1.39 1996/03/14 15:55:18 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@@ -422,9 +422,10 @@ static void io_write (void)
|
|||||||
if (lua_getparam (2) == LUA_NOOBJECT) /* free format */
|
if (lua_getparam (2) == LUA_NOOBJECT) /* free format */
|
||||||
{
|
{
|
||||||
lua_Object o1 = lua_getparam(1);
|
lua_Object o1 = lua_getparam(1);
|
||||||
if (lua_isnumber(o1))
|
int t = lua_type(o1);
|
||||||
|
if (t == LUA_T_NUMBER)
|
||||||
status = fprintf (out, "%g", lua_getnumber(o1)) >= 0;
|
status = fprintf (out, "%g", lua_getnumber(o1)) >= 0;
|
||||||
else if (lua_isstring(o1))
|
else if (t == LUA_T_STRING)
|
||||||
status = fprintf (out, "%s", lua_getstring(o1)) >= 0;
|
status = fprintf (out, "%s", lua_getstring(o1)) >= 0;
|
||||||
}
|
}
|
||||||
else /* formated */
|
else /* formated */
|
||||||
|
|||||||
18
lua.h
18
lua.h
@@ -2,7 +2,7 @@
|
|||||||
** LUA - Linguagem para Usuarios de Aplicacao
|
** LUA - Linguagem para Usuarios de Aplicacao
|
||||||
** Grupo de Tecnologia em Computacao Grafica
|
** Grupo de Tecnologia em Computacao Grafica
|
||||||
** TeCGraf - PUC-Rio
|
** TeCGraf - PUC-Rio
|
||||||
** $Id: lua.h,v 3.22 1996/02/12 18:32:09 roberto Exp roberto $
|
** $Id: lua.h,v 3.23 1996/02/14 13:40:26 roberto Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
@@ -52,6 +52,14 @@ void lua_endblock (void);
|
|||||||
lua_Object lua_getparam (int number);
|
lua_Object lua_getparam (int number);
|
||||||
#define lua_getresult(_) lua_getparam(_)
|
#define lua_getresult(_) lua_getparam(_)
|
||||||
|
|
||||||
|
#define lua_isnil(_) (lua_type(_)==LUA_T_NIL)
|
||||||
|
#define lua_istable(_) (lua_type(_)==LUA_T_ARRAY)
|
||||||
|
#define lua_isuserdata(_) (lua_type(_)>=LUA_T_USERDATA)
|
||||||
|
#define lua_iscfunction(_) (lua_type(_)==LUA_T_CFUNCTION)
|
||||||
|
int lua_isnumber (lua_Object object);
|
||||||
|
int lua_isstring (lua_Object object);
|
||||||
|
int lua_isfunction (lua_Object object);
|
||||||
|
|
||||||
float lua_getnumber (lua_Object object);
|
float lua_getnumber (lua_Object object);
|
||||||
char *lua_getstring (lua_Object object);
|
char *lua_getstring (lua_Object object);
|
||||||
lua_CFunction lua_getcfunction (lua_Object object);
|
lua_CFunction lua_getcfunction (lua_Object object);
|
||||||
@@ -88,14 +96,6 @@ lua_Object lua_createtable (void);
|
|||||||
|
|
||||||
#define lua_pushuserdata(u) lua_pushusertag(u, LUA_T_USERDATA)
|
#define lua_pushuserdata(u) lua_pushusertag(u, LUA_T_USERDATA)
|
||||||
|
|
||||||
#define lua_isnil(_) (lua_type(_)==LUA_T_NIL)
|
|
||||||
#define lua_isnumber(_) (lua_type(_)==LUA_T_NUMBER)
|
|
||||||
#define lua_isstring(_) (lua_type(_)==LUA_T_STRING)
|
|
||||||
#define lua_istable(_) (lua_type(_)==LUA_T_ARRAY)
|
|
||||||
#define lua_isfunction(_) (lua_type(_)==LUA_T_FUNCTION)
|
|
||||||
#define lua_iscfunction(_) (lua_type(_)==LUA_T_CFUNCTION)
|
|
||||||
#define lua_isuserdata(_) (lua_type(_)>=LUA_T_USERDATA)
|
|
||||||
|
|
||||||
|
|
||||||
/* for compatibility with old versions. Avoid using these macros */
|
/* for compatibility with old versions. Avoid using these macros */
|
||||||
|
|
||||||
|
|||||||
16
strlib.c
16
strlib.c
@@ -3,7 +3,7 @@
|
|||||||
** String library to LUA
|
** String library to LUA
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *rcs_strlib="$Id: strlib.c,v 1.18 1996/02/12 18:34:44 roberto Exp roberto $";
|
char *rcs_strlib="$Id: strlib.c,v 1.19 1996/03/14 15:52:35 roberto Exp roberto $";
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -24,7 +24,7 @@ void lua_arg_error(char *funcname)
|
|||||||
char *lua_check_string (int numArg, char *funcname)
|
char *lua_check_string (int numArg, char *funcname)
|
||||||
{
|
{
|
||||||
lua_Object o = lua_getparam(numArg);
|
lua_Object o = lua_getparam(numArg);
|
||||||
if (!(lua_isstring(o) || lua_isnumber(o)))
|
if (!lua_isstring(o))
|
||||||
lua_arg_error(funcname);
|
lua_arg_error(funcname);
|
||||||
return lua_getstring(o);
|
return lua_getstring(o);
|
||||||
}
|
}
|
||||||
@@ -32,17 +32,9 @@ char *lua_check_string (int numArg, char *funcname)
|
|||||||
double lua_check_number (int numArg, char *funcname)
|
double lua_check_number (int numArg, char *funcname)
|
||||||
{
|
{
|
||||||
lua_Object o = lua_getparam(numArg);
|
lua_Object o = lua_getparam(numArg);
|
||||||
if (lua_isnumber(o))
|
if (!lua_isnumber(o))
|
||||||
return lua_getnumber(o);
|
|
||||||
else if (lua_isstring(o))
|
|
||||||
{
|
|
||||||
float t;
|
|
||||||
char c;
|
|
||||||
if (sscanf(lua_getstring(o), "%f %c",&t, &c) == 1)
|
|
||||||
return t;
|
|
||||||
}
|
|
||||||
lua_arg_error(funcname);
|
lua_arg_error(funcname);
|
||||||
return 0; /* to avoid warnings */
|
return lua_getnumber(o);
|
||||||
}
|
}
|
||||||
|
|
||||||
char *luaI_addchar (int c)
|
char *luaI_addchar (int c)
|
||||||
|
|||||||
Reference in New Issue
Block a user