aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-02-09 17:00:23 -0200
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>1996-02-09 17:00:23 -0200
commit801722825d94b3bddd94d83887b081c328772147 (patch)
treea76eedfe7e3e9105c0adcfbeb5d861167bc4dcce
parent3abc25fa5424ebc857d445792dd0689926b7ea34 (diff)
downloadlua-801722825d94b3bddd94d83887b081c328772147.tar.gz
lua-801722825d94b3bddd94d83887b081c328772147.tar.bz2
lua-801722825d94b3bddd94d83887b081c328772147.zip
"lua_check_number" accepts strings convertible to numbers.
-rw-r--r--lualib.h4
-rw-r--r--strlib.c22
2 files changed, 17 insertions, 9 deletions
diff --git a/lualib.h b/lualib.h
index 1e64bcc5..25f0570e 100644
--- a/lualib.h
+++ b/lualib.h
@@ -2,7 +2,7 @@
2** Libraries to be used in LUA programs 2** Libraries to be used in LUA programs
3** Grupo de Tecnologia em Computacao Grafica 3** Grupo de Tecnologia em Computacao Grafica
4** TeCGraf - PUC-Rio 4** TeCGraf - PUC-Rio
5** $Id: lualib.h,v 1.4 1995/11/10 17:54:31 roberto Exp roberto $ 5** $Id: lualib.h,v 1.5 1996/01/22 17:38:57 roberto Exp roberto $
6*/ 6*/
7 7
8#ifndef lualib_h 8#ifndef lualib_h
@@ -16,7 +16,7 @@ void mathlib_open (void);
16/* auxiliar functions (private) */ 16/* auxiliar functions (private) */
17void lua_arg_error(char *funcname); 17void lua_arg_error(char *funcname);
18char *lua_check_string (int numArg, char *funcname); 18char *lua_check_string (int numArg, char *funcname);
19float lua_check_number (int numArg, char *funcname); 19double lua_check_number (int numArg, char *funcname);
20char *luaI_addchar (int c); 20char *luaI_addchar (int c);
21 21
22#endif 22#endif
diff --git a/strlib.c b/strlib.c
index 7f4bab1c..80c412a9 100644
--- a/strlib.c
+++ b/strlib.c
@@ -3,7 +3,7 @@
3** String library to LUA 3** String library to LUA
4*/ 4*/
5 5
6char *rcs_strlib="$Id: strlib.c,v 1.15 1996/01/22 17:38:57 roberto Exp roberto $"; 6char *rcs_strlib="$Id: strlib.c,v 1.16 1996/01/26 12:11:28 roberto Exp roberto $";
7 7
8#include <string.h> 8#include <string.h>
9#include <stdio.h> 9#include <stdio.h>
@@ -29,12 +29,20 @@ char *lua_check_string (int numArg, char *funcname)
29 return lua_getstring(o); 29 return lua_getstring(o);
30} 30}
31 31
32float lua_check_number (int numArg, char *funcname) 32double lua_check_number (int numArg, char *funcname)
33{ 33{
34 lua_Object o = lua_getparam(numArg); 34 lua_Object o = lua_getparam(numArg);
35 if (!lua_isnumber(o)) 35 if (lua_isnumber(o))
36 lua_arg_error(funcname); 36 return lua_getnumber(o);
37 return lua_getnumber(o); 37 else if (lua_isstring(o))
38 {
39 float t;
40 char c;
41 if (sscanf(lua_getstring(o), "%f %c",&t, &c) == 1)
42 return t;
43 }
44 lua_arg_error(funcname);
45 return 0; /* to avoid warnings */
38} 46}
39 47
40char *luaI_addchar (int c) 48char *luaI_addchar (int c)
@@ -171,7 +179,7 @@ static void str_ascii (void)
171#define MAX_CONVERTION 2000 179#define MAX_CONVERTION 2000
172#define MAX_FORMAT 50 180#define MAX_FORMAT 50
173 181
174static void io_format (void) 182static void str_format (void)
175{ 183{
176 int arg = 1; 184 int arg = 1;
177 char *strfrmt = lua_check_string(arg++, "format"); 185 char *strfrmt = lua_check_string(arg++, "format");
@@ -244,5 +252,5 @@ void strlib_open (void)
244 lua_register ("strlower", str_lower); 252 lua_register ("strlower", str_lower);
245 lua_register ("strupper", str_upper); 253 lua_register ("strupper", str_upper);
246 lua_register ("ascii", str_ascii); 254 lua_register ("ascii", str_ascii);
247 lua_register ("format", io_format); 255 lua_register ("format", str_format);
248} 256}