luaL_openlib -> luaL_register, luaL_putchar -> luaL_addchar

This commit is contained in:
Roberto Ierusalimschy 2005-08-15 11:12:32 -03:00
parent 16ddf86168
commit 5e8a9e324c
10 changed files with 45 additions and 36 deletions

View File

@ -1,5 +1,5 @@
/*
** $Id: lbaselib.c,v 1.179 2005/07/07 15:48:29 roberto Exp roberto $
** $Id: lbaselib.c,v 1.180 2005/07/12 18:15:11 roberto Exp roberto $
** Basic library
** See Copyright Notice in lua.h
*/
@ -602,7 +602,7 @@ static void auxopen (lua_State *L, const char *name,
static void base_open (lua_State *L) {
lua_pushvalue(L, LUA_GLOBALSINDEX);
luaL_openlib(L, NULL, base_funcs, 0); /* open lib into global table */
luaL_register(L, NULL, base_funcs); /* open lib into global table */
lua_pushliteral(L, LUA_VERSION);
lua_setglobal(L, "_VERSION"); /* set global _VERSION */
/* `ipairs' and `pairs' need auxiliary functions as upvalues */
@ -627,7 +627,7 @@ static void base_open (lua_State *L) {
LUALIB_API int luaopen_base (lua_State *L) {
base_open(L);
luaL_openlib(L, LUA_COLIBNAME, co_funcs, 0);
luaL_register(L, LUA_COLIBNAME, co_funcs);
return 2;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: ldblib.c,v 1.98 2005/05/17 19:49:15 roberto Exp roberto $
** $Id: ldblib.c,v 1.99 2005/07/12 14:32:08 roberto Exp roberto $
** Interface from Lua to its debug API
** See Copyright Notice in lua.h
*/
@ -384,7 +384,7 @@ static const luaL_reg dblib[] = {
LUALIB_API int luaopen_debug (lua_State *L) {
luaL_openlib(L, LUA_DBLIBNAME, dblib, 0);
luaL_register(L, LUA_DBLIBNAME, dblib);
return 1;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: liolib.c,v 2.63 2005/06/06 18:42:21 roberto Exp roberto $
** $Id: liolib.c,v 2.64 2005/07/12 14:32:08 roberto Exp roberto $
** Standard I/O (and system) library
** See Copyright Notice in lua.h
*/
@ -493,7 +493,7 @@ static void createmeta (lua_State *L) {
luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
lua_pushvalue(L, -1); /* push metatable */
lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
luaL_openlib(L, NULL, flib, 0); /* file methods */
luaL_register(L, NULL, flib); /* file methods */
}
@ -513,7 +513,7 @@ LUALIB_API int luaopen_io (lua_State *L) {
lua_newtable(L);
lua_replace(L, LUA_ENVIRONINDEX);
/* open library */
luaL_openlib(L, LUA_IOLIBNAME, iolib, 0);
luaL_register(L, LUA_IOLIBNAME, iolib);
/* create (and set) default files */
createstdfile(L, stdin, IO_INPUT, "stdin");
createstdfile(L, stdout, IO_OUTPUT, "stdout");

View File

@ -1,5 +1,5 @@
/*
** $Id: lmathlib.c,v 1.64 2005/06/13 21:20:14 roberto Exp roberto $
** $Id: lmathlib.c,v 1.65 2005/07/11 23:58:35 roberto Exp roberto $
** Standard mathematical library
** See Copyright Notice in lua.h
*/
@ -249,7 +249,7 @@ static const luaL_reg mathlib[] = {
** Open math library
*/
LUALIB_API int luaopen_math (lua_State *L) {
luaL_openlib(L, LUA_MATHLIBNAME, mathlib, 0);
luaL_register(L, LUA_MATHLIBNAME, mathlib);
lua_pushnumber(L, PI);
lua_setfield(L, -2, "pi");
lua_pushnumber(L, HUGE_VAL);

View File

@ -1,5 +1,5 @@
/*
** $Id: loadlib.c,v 1.36 2005/08/09 17:58:09 roberto Exp roberto $
** $Id: loadlib.c,v 1.37 2005/08/10 18:06:58 roberto Exp roberto $
** Dynamic library loader for Lua
** See Copyright Notice in lua.h
**
@ -625,7 +625,7 @@ LUALIB_API int luaopen_package (lua_State *L) {
#endif
lua_setfield(L, -2, "loadlib");
lua_pushvalue(L, LUA_GLOBALSINDEX);
luaL_openlib(L, NULL, ll_funcs, 0); /* open lib into global table */
luaL_register(L, NULL, ll_funcs); /* open lib into global table */
return 1;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: loslib.c,v 1.9 2005/05/17 19:49:15 roberto Exp roberto $
** $Id: loslib.c,v 1.10 2005/05/25 13:21:26 roberto Exp roberto $
** Standard Operating System library
** See Copyright Notice in lua.h
*/
@ -229,7 +229,7 @@ static const luaL_reg syslib[] = {
LUALIB_API int luaopen_os (lua_State *L) {
luaL_openlib(L, LUA_OSLIBNAME, syslib, 0);
luaL_register(L, LUA_OSLIBNAME, syslib);
return 1;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lstrlib.c,v 1.120 2005/07/31 16:47:34 roberto Exp roberto $
** $Id: lstrlib.c,v 1.121 2005/08/09 17:42:02 roberto Exp roberto $
** Standard library for string operations and pattern-matching
** See Copyright Notice in lua.h
*/
@ -58,7 +58,7 @@ static int str_reverse (lua_State *L) {
luaL_Buffer b;
const char *s = luaL_checklstring(L, 1, &l);
luaL_buffinit(L, &b);
while (l--) luaL_putchar(&b, s[l]);
while (l--) luaL_addchar(&b, s[l]);
luaL_pushresult(&b);
return 1;
}
@ -71,7 +71,7 @@ static int str_lower (lua_State *L) {
const char *s = luaL_checklstring(L, 1, &l);
luaL_buffinit(L, &b);
for (i=0; i<l; i++)
luaL_putchar(&b, tolower(uchar(s[i])));
luaL_addchar(&b, tolower(uchar(s[i])));
luaL_pushresult(&b);
return 1;
}
@ -84,7 +84,7 @@ static int str_upper (lua_State *L) {
const char *s = luaL_checklstring(L, 1, &l);
luaL_buffinit(L, &b);
for (i=0; i<l; i++)
luaL_putchar(&b, toupper(uchar(s[i])));
luaL_addchar(&b, toupper(uchar(s[i])));
luaL_pushresult(&b);
return 1;
}
@ -127,7 +127,7 @@ static int str_char (lua_State *L) {
for (i=1; i<=n; i++) {
int c = luaL_checkint(L, i);
luaL_argcheck(L, uchar(c) == c, i, "invalid value");
luaL_putchar(&b, uchar(c));
luaL_addchar(&b, uchar(c));
}
luaL_pushresult(&b);
return 1;
@ -594,11 +594,11 @@ static void add_s (MatchState *ms, luaL_Buffer *b,
size_t i;
for (i=0; i<l; i++) {
if (news[i] != L_ESC)
luaL_putchar(b, news[i]);
luaL_addchar(b, news[i]);
else {
i++; /* skip ESC */
if (!isdigit(uchar(news[i])))
luaL_putchar(b, news[i]);
luaL_addchar(b, news[i]);
else {
if (news[i] == '0')
lua_pushlstring(L, s, e - s); /* add whole match */
@ -651,7 +651,7 @@ static int str_gsub (lua_State *L) {
if (e && e>src) /* non empty match? */
src = e; /* skip it */
else if (src < ms.src_end)
luaL_putchar(&b, *src++);
luaL_addchar(&b, *src++);
else break;
if (anchor) break;
}
@ -673,12 +673,12 @@ static int str_gsub (lua_State *L) {
static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
size_t l;
const char *s = luaL_checklstring(L, arg, &l);
luaL_putchar(b, '"');
luaL_addchar(b, '"');
while (l--) {
switch (*s) {
case '"': case '\\': case '\n': {
luaL_putchar(b, '\\');
luaL_putchar(b, *s);
luaL_addchar(b, '\\');
luaL_addchar(b, *s);
break;
}
case '\0': {
@ -686,13 +686,13 @@ static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
break;
}
default: {
luaL_putchar(b, *s);
luaL_addchar(b, *s);
break;
}
}
s++;
}
luaL_putchar(b, '"');
luaL_addchar(b, '"');
}
@ -728,9 +728,9 @@ static int str_format (lua_State *L) {
luaL_buffinit(L, &b);
while (strfrmt < strfrmt_end) {
if (*strfrmt != L_ESC)
luaL_putchar(&b, *strfrmt++);
luaL_addchar(&b, *strfrmt++);
else if (*++strfrmt == L_ESC)
luaL_putchar(&b, *strfrmt++); /* %% */
luaL_addchar(&b, *strfrmt++); /* %% */
else { /* format item */
char form[MAX_FORMAT]; /* to store the format (`%...') */
char buff[MAX_ITEM]; /* to store the formatted item */
@ -818,7 +818,7 @@ static void createmetatable (lua_State *L) {
** Open string library
*/
LUALIB_API int luaopen_string (lua_State *L) {
luaL_openlib(L, LUA_STRLIBNAME, strlib, 0);
luaL_register(L, LUA_STRLIBNAME, strlib);
#if defined(LUA_COMPAT_GFIND)
lua_getfield(L, -1, "gmatch");
lua_setfield(L, -2, "gfind");

View File

@ -1,5 +1,5 @@
/*
** $Id: ltablib.c,v 1.32 2005/07/11 18:48:02 roberto Exp roberto $
** $Id: ltablib.c,v 1.33 2005/07/12 14:32:08 roberto Exp roberto $
** Library for Table Manipulation
** See Copyright Notice in lua.h
*/
@ -250,7 +250,7 @@ static const luaL_reg tab_funcs[] = {
LUALIB_API int luaopen_table (lua_State *L) {
luaL_openlib(L, LUA_TABLIBNAME, tab_funcs, 0);
luaL_register(L, LUA_TABLIBNAME, tab_funcs);
return 1;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: ltests.c,v 2.26 2005/07/11 14:00:59 roberto Exp roberto $
** $Id: ltests.c,v 2.27 2005/07/12 14:32:08 roberto Exp roberto $
** Internal Module for Debugging of the Lua Implementation
** See Copyright Notice in lua.h
*/
@ -730,7 +730,7 @@ static int loadlib (lua_State *L) {
lua_State *L1 = cast(lua_State *,
cast(unsigned long, luaL_checknumber(L, 1)));
lua_pushvalue(L1, LUA_GLOBALSINDEX);
luaL_openlib(L1, NULL, libs, 0);
luaL_register(L1, NULL, libs);
return 0;
}
@ -1161,7 +1161,7 @@ int luaB_opentests (lua_State *L) {
lua_assert(ud == cast(void *, &memcontrol));
lua_atpanic(L, l_panic);
lua_state = L; /* keep first state to be opened */
luaL_openlib(L, "T", tests_funcs, 0);
luaL_register(L, "T", tests_funcs);
atexit(fim);
return 0;
}

View File

@ -1,5 +1,5 @@
/*
** $Id: luaconf.h,v 1.57 2005/08/04 13:37:10 roberto Exp roberto $
** $Id: luaconf.h,v 1.58 2005/08/09 17:57:29 roberto Exp roberto $
** Configuration file for Lua
** See Copyright Notice in lua.h
*/
@ -330,6 +330,15 @@
#define LUA_COMPAT_GFIND
/*
@@ LUA_COMPAT_OPENLIB controls compatibility with old 'luaL_openlib'
@* behavior.
** CHANGE it to undefined as soon as you replace to 'luaL_registry'
** your uses of 'luaL_openlib'
*/
#define LUA_COMPAT_OPENLIB
/*
@@ luai_apicheck is the assert macro used by the Lua-C API.