瀏覽代碼

new macro to control format for `read"*n"'

Roberto Ierusalimschy 24 年之前
父節點
當前提交
61a036eaa5
共有 2 個文件被更改,包括 11 次插入5 次删除
  1. 2 2
      liolib.c
  2. 9 3
      lua.h

+ 2 - 2
liolib.c

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: liolib.c,v 1.115 2001/06/08 16:48:32 roberto Exp roberto $
+** $Id: liolib.c,v 1.116 2001/06/22 13:49:42 roberto Exp roberto $
 ** Standard I/O (and system) library
 ** Standard I/O (and system) library
 ** See Copyright Notice in lua.h
 ** See Copyright Notice in lua.h
 */
 */
@@ -263,7 +263,7 @@ static int read_until (lua_State *L, FILE *f, const l_char *p, int pl) {
 
 
 static int read_number (lua_State *L, FILE *f) {
 static int read_number (lua_State *L, FILE *f) {
   double d;
   double d;
-  if (fscanf(f, l_s("%lf"), &d) == 1) {
+  if (fscanf(f, l_s(LUA_SCAN_NUMBER), &d) == 1) {
     lua_pushnumber(L, d);
     lua_pushnumber(L, d);
     return 1;
     return 1;
   }
   }

+ 9 - 3
lua.h

@@ -1,5 +1,5 @@
 /*
 /*
-** $Id: lua.h,v 1.97 2001/04/23 16:35:45 roberto Exp roberto $
+** $Id: lua.h,v 1.98 2001/06/06 18:00:19 roberto Exp roberto $
 ** Lua - An Extensible Extension Language
 ** Lua - An Extensible Extension Language
 ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
 ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
 ** e-mail: [email protected]
 ** e-mail: [email protected]
@@ -292,10 +292,16 @@ LUA_API void lua_pushusertag (lua_State *L, void *u, int tag);
 #define l_charint	int
 #define l_charint	int
 #endif
 #endif
 
 
-/* function to convert a lua_Number to a string */
+/*
+** formats for Lua numbers
+*/
+#ifndef LUA_SCAN_NUMBER
+#define LUA_SCAN_NUMBER		"%lf"
+#endif
 #ifndef LUA_NUMBER_FMT
 #ifndef LUA_NUMBER_FMT
-#define LUA_NUMBER_FMT      "%.16g"
+#define LUA_NUMBER_FMT		"%.16g"
 #endif
 #endif
+/* function to convert a lua_Number to a string */
 #ifndef lua_number2str
 #ifndef lua_number2str
 #define lua_number2str(s,n)     sprintf((s), l_s(LUA_NUMBER_FMT), (n))
 #define lua_number2str(s,n)     sprintf((s), l_s(LUA_NUMBER_FMT), (n))
 #endif
 #endif