From c9902be294f5c2dca8a67a67fd324f91e4352c0a Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 18 Jun 1998 13:57:03 -0300 Subject: [PATCH] "findname" moved from lobject.c to lauxlib.c (so libraries may use it). --- lauxlib.c | 11 ++++++++++- lauxlib.h | 3 ++- llex.c | 6 +++--- lobject.c | 13 +------------ lobject.h | 3 +-- ltm.c | 8 ++++---- 6 files changed, 21 insertions(+), 23 deletions(-) diff --git a/lauxlib.c b/lauxlib.c index 0a7475b1..0fa745e4 100644 --- a/lauxlib.c +++ b/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 #include +#include /* 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; diff --git a/lauxlib.h b/lauxlib.h index 0e150d25..572db923 100644 --- a/lauxlib.h +++ b/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 diff --git a/llex.c b/llex.c index 75c1c28b..8bd60aaf 100644 --- a/llex.c +++ b/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; diff --git a/lobject.c b/lobject.c index e70d50ba..99c76233 100644 --- a/lobject.c +++ b/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 -#include #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; diff --git a/lobject.h b/lobject.h index c2fa373a..18cf2097 100644 --- a/lobject.h +++ b/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 diff --git a/ltm.c b/ltm.c index 724fee76..cc290dde 100644 --- a/ltm.c +++ b/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;