浏览代码

"findname" moved from lobject.c to lauxlib.c (so libraries may use it).

Roberto Ierusalimschy 27 年之前
父节点
当前提交
c9902be294
共有 6 个文件被更改,包括 21 次插入23 次删除
  1. 10 1
      lauxlib.c
  2. 2 1
      lauxlib.h
  3. 3 3
      llex.c
  4. 1 12
      lobject.c
  5. 1 2
      lobject.h
  6. 4 4
      ltm.c

+ 10 - 1
lauxlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.c,v 1.9 1998/03/06 16:54:42 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.10 1998/03/06 18:47:42 roberto Exp roberto $
 ** Auxiliar functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -7,6 +7,7 @@
 
 #include <stdarg.h>
 #include <stdio.h>
+#include <string.h>
 
 /* Please Notice: This file uses only the oficial API of Lua
 ** Any function declared here could be written as an application
@@ -18,6 +19,14 @@
 
 
 
+int luaL_findstring (char *name, char *list[]) {
+  int i;
+  for (i=0; list[i]; i++)
+    if (strcmp(list[i], name) == 0)
+      return i;
+  return -1;  /* name not found */
+}
+
 void luaL_argerror (int numarg, char *extramsg)
 {
   char *funcname;

+ 2 - 1
lauxlib.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lauxlib.h,v 1.6 1998/01/09 15:06:07 roberto Exp roberto $
+** $Id: lauxlib.h,v 1.7 1998/03/06 16:54:42 roberto Exp roberto $
 ** Auxiliar functions for building Lua libraries
 ** See Copyright Notice in lua.h
 */
@@ -41,6 +41,7 @@ void luaL_addsize (int n);
 int luaL_newbuffer (int size);
 void luaL_oldbuffer (int old);
 char *luaL_buffer (void);
+int luaL_findstring (char *name, char *list[]);
 
 
 #endif

+ 3 - 3
llex.c

@@ -1,5 +1,5 @@
 /*
-** $Id: llex.c,v 1.19 1998/05/27 13:03:40 roberto Exp roberto $
+** $Id: llex.c,v 1.20 1998/06/06 20:44:05 roberto Exp roberto $
 ** Lexical Analizer
 ** See Copyright Notice in lua.h
 */
@@ -118,7 +118,7 @@ static void skipspace (LexState *LS)
 static int checkcond (LexState *LS, char *buff)
 {
   static char *opts[] = {"nil", "1", NULL};
-  int i = luaO_findstring(buff, opts);
+  int i = luaL_findstring(buff, opts);
   if (i >= 0) return i;
   else if (isalpha((unsigned char)buff[0]) || buff[0] == '_')
     return luaS_globaldefined(buff);
@@ -172,7 +172,7 @@ static void inclinenumber (LexState *LS)
     int skip = LS->ifstate[LS->iflevel].skip;
     next(LS);  /* skip $ */
     readname(LS, buff);
-    switch (luaO_findstring(buff, pragmas)) {
+    switch (luaL_findstring(buff, pragmas)) {
       case 0:  /* debug */
         if (!skip) lua_debug = 1;
         break;

+ 1 - 12
lobject.c

@@ -1,11 +1,10 @@
 /*
-** $Id: lobject.c,v 1.10 1998/01/09 14:44:55 roberto Exp roberto $
+** $Id: lobject.c,v 1.11 1998/03/09 21:49:52 roberto Exp roberto $
 ** Some generic functions over Lua objects
 ** See Copyright Notice in lua.h
 */
 
 #include <stdlib.h>
-#include <string.h>
 
 #include "lobject.h"
 #include "lua.h"
@@ -58,16 +57,6 @@ int luaO_equalObj (TObject *t1, TObject *t2)
 }
 
 
-int luaO_findstring (char *name, char *list[])
-{
-  int i;
-  for (i=0; list[i]; i++)
-    if (strcmp(list[i], name) == 0)
-      return i;
-  return -1;  /* name not found */
-}
-
-
 void luaO_insertlist (GCnode *root, GCnode *node)
 {
   node->next = root->next;

+ 1 - 2
lobject.h

@@ -1,5 +1,5 @@
 /*
-** $Id: lobject.h,v 1.19 1998/05/18 22:26:03 roberto Exp roberto $
+** $Id: lobject.h,v 1.20 1998/06/11 18:21:37 roberto Exp roberto $
 ** Type definitions for Lua objects
 ** See Copyright Notice in lua.h
 */
@@ -196,7 +196,6 @@ extern TObject luaO_nilobject;
 
 int luaO_equalObj (TObject *t1, TObject *t2);
 int luaO_redimension (int oldsize);
-int luaO_findstring (char *name, char *list[]);
 void luaO_insertlist (GCnode *root, GCnode *node);
 
 #ifdef OLD_ANSI

+ 4 - 4
ltm.c

@@ -1,5 +1,5 @@
 /*
-** $Id: ltm.c,v 1.14 1998/03/09 21:49:52 roberto Exp roberto $
+** $Id: ltm.c,v 1.15 1998/03/11 13:59:50 roberto Exp roberto $
 ** Tag methods
 ** See Copyright Notice in lua.h
 */
@@ -24,7 +24,7 @@ char *luaT_eventname[] = {  /* ORDER IM */
 
 static int luaI_checkevent (char *name, char *list[])
 {
-  int e = luaO_findstring(name, list);
+  int e = luaL_findstring(name, list);
   if (e < 0)
     luaL_verror("`%.50s' is not a valid event name", name);
   return e;
@@ -214,7 +214,7 @@ void luaT_setfallback (void)
   char *name = luaL_check_string(1);
   lua_Object func = lua_getparam(2);
   luaL_arg_check(lua_isfunction(func), 2, "function expected");
-  switch (luaO_findstring(name, oldnames)) {
+  switch (luaL_findstring(name, oldnames)) {
     case 0:  /* old error fallback */
       oldfunc = L->errorim;
       L->errorim = *luaA_Address(func);
@@ -243,7 +243,7 @@ void luaT_setfallback (void)
     }
     default: {
       int e;
-      if ((e = luaO_findstring(name, luaT_eventname)) >= 0) {
+      if ((e = luaL_findstring(name, luaT_eventname)) >= 0) {
         oldfunc = *luaT_getim(LUA_T_NIL, e);
         fillvalids(e, luaA_Address(func));
         replace = (e == IM_GC || e == IM_INDEX) ? nilFB : typeFB;