mirror of
https://github.com/lua/lua
synced 2024-11-26 06:39:41 +03:00
more consistent names for auxlib functions
This commit is contained in:
parent
21aa7e55f2
commit
070204300c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lauxlib.c,v 1.50 2001/04/23 16:35:45 roberto Exp roberto $
|
||||
** $Id: lauxlib.c,v 1.51 2001/07/12 18:11:58 roberto Exp $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -54,19 +54,19 @@ static void tag_error (lua_State *L, int narg, int tag) {
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_checkstack (lua_State *L, int space, const l_char *mes) {
|
||||
LUALIB_API void luaL_check_stack (lua_State *L, int space, const l_char *mes) {
|
||||
if (space > lua_stackspace(L))
|
||||
luaL_verror(L, l_s("stack overflow (%.30s)"), mes);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_checktype(lua_State *L, int narg, int t) {
|
||||
LUALIB_API void luaL_check_rawtype(lua_State *L, int narg, int t) {
|
||||
if (lua_rawtag(L, narg) != t)
|
||||
tag_error(L, narg, t);
|
||||
}
|
||||
|
||||
|
||||
LUALIB_API void luaL_checkany (lua_State *L, int narg) {
|
||||
LUALIB_API void luaL_check_any (lua_State *L, int narg) {
|
||||
if (lua_rawtag(L, narg) == LUA_TNONE)
|
||||
luaL_argerror(L, narg, l_s("value expected"));
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lauxlib.h,v 1.35 2001/04/06 21:17:37 roberto Exp roberto $
|
||||
** $Id: lauxlib.h,v 1.36 2001/07/22 00:59:36 roberto Exp $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -36,9 +36,9 @@ LUALIB_API const lua_char *luaL_opt_lstr (lua_State *L, int numArg,
|
||||
LUALIB_API lua_Number luaL_check_number (lua_State *L, int numArg);
|
||||
LUALIB_API lua_Number luaL_opt_number (lua_State *L, int nArg, lua_Number def);
|
||||
|
||||
LUALIB_API void luaL_checkstack (lua_State *L, int space, const lua_char *msg);
|
||||
LUALIB_API void luaL_checktype (lua_State *L, int narg, int t);
|
||||
LUALIB_API void luaL_checkany (lua_State *L, int narg);
|
||||
LUALIB_API void luaL_check_stack (lua_State *L, int space, const lua_char *msg);
|
||||
LUALIB_API void luaL_check_rawtype (lua_State *L, int narg, int t);
|
||||
LUALIB_API void luaL_check_any (lua_State *L, int narg);
|
||||
LUALIB_API void *luaL_check_userdata (lua_State *L, int narg,
|
||||
const lua_char *name);
|
||||
|
||||
|
59
lbaselib.c
59
lbaselib.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lbaselib.c,v 1.43 2001/10/11 21:41:21 roberto Exp $
|
||||
** $Id: lbaselib.c,v 1.44 2001/10/17 21:12:57 roberto Exp $
|
||||
** Basic library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -42,7 +42,7 @@ static int luaB__ALERT (lua_State *L) {
|
||||
** The library `liolib' redefines _ERRORMESSAGE for better error information.
|
||||
*/
|
||||
static int luaB__ERRORMESSAGE (lua_State *L) {
|
||||
luaL_checktype(L, 1, LUA_TSTRING);
|
||||
luaL_check_rawtype(L, 1, LUA_TSTRING);
|
||||
lua_getglobal(L, l_s(LUA_ALERT));
|
||||
if (lua_isfunction(L, -1)) { /* avoid error loop if _ALERT is not defined */
|
||||
lua_Debug ar;
|
||||
@ -95,7 +95,7 @@ static int luaB_print (lua_State *L) {
|
||||
static int luaB_tonumber (lua_State *L) {
|
||||
int base = luaL_opt_int(L, 2, 10);
|
||||
if (base == 10) { /* standard conversion */
|
||||
luaL_checkany(L, 1);
|
||||
luaL_check_any(L, 1);
|
||||
if (lua_isnumber(L, 1)) {
|
||||
lua_pushnumber(L, lua_tonumber(L, 1));
|
||||
return 1;
|
||||
@ -126,7 +126,7 @@ static int luaB_error (lua_State *L) {
|
||||
}
|
||||
|
||||
static int luaB_setglobal (lua_State *L) {
|
||||
luaL_checkany(L, 2);
|
||||
luaL_check_any(L, 2);
|
||||
lua_setglobal(L, luaL_check_string(L, 1));
|
||||
return 0;
|
||||
}
|
||||
@ -157,13 +157,13 @@ static int gettag (lua_State *L, int narg) {
|
||||
|
||||
|
||||
static int luaB_tag (lua_State *L) {
|
||||
luaL_checkany(L, 1);
|
||||
luaL_check_any(L, 1);
|
||||
lua_pushnumber(L, lua_tag(L, 1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luaB_settype (lua_State *L) {
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
lua_pushvalue(L, 1); /* push table */
|
||||
lua_settag(L, gettag(L, 2));
|
||||
return 1; /* return table */
|
||||
@ -171,7 +171,7 @@ static int luaB_settype (lua_State *L) {
|
||||
|
||||
static int luaB_weakmode (lua_State *L) {
|
||||
const l_char *mode = luaL_check_string(L, 2);
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
if (*mode == l_c('?')) {
|
||||
l_char buff[3];
|
||||
l_char *s = buff;
|
||||
@ -202,7 +202,7 @@ static int luaB_newtype (lua_State *L) {
|
||||
static int luaB_globals (lua_State *L) {
|
||||
lua_getglobals(L); /* value to be returned */
|
||||
if (!lua_isnull(L, 1)) {
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
lua_pushvalue(L, 1); /* new table of globals */
|
||||
lua_setglobals(L);
|
||||
}
|
||||
@ -210,16 +210,16 @@ static int luaB_globals (lua_State *L) {
|
||||
}
|
||||
|
||||
static int luaB_rawget (lua_State *L) {
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_checkany(L, 2);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
luaL_check_any(L, 2);
|
||||
lua_rawget(L, -2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int luaB_rawset (lua_State *L) {
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_checkany(L, 2);
|
||||
luaL_checkany(L, 3);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
luaL_check_any(L, 2);
|
||||
luaL_check_any(L, 3);
|
||||
lua_rawset(L, -3);
|
||||
return 1;
|
||||
}
|
||||
@ -262,21 +262,21 @@ static int luaB_collectgarbage (lua_State *L) {
|
||||
|
||||
|
||||
static int luaB_type (lua_State *L) {
|
||||
luaL_checkany(L, 1);
|
||||
luaL_check_any(L, 1);
|
||||
lua_pushstring(L, lua_type(L, 1));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int luaB_rawtype (lua_State *L) {
|
||||
luaL_checkany(L, 1);
|
||||
luaL_check_any(L, 1);
|
||||
lua_pushstring(L, lua_tag2name(L, lua_rawtag(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int luaB_next (lua_State *L) {
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
lua_settop(L, 2); /* create a 2nd argument if there isn't one */
|
||||
if (lua_next(L, 1))
|
||||
return 2;
|
||||
@ -394,9 +394,9 @@ static int luaB_require (lua_State *L) {
|
||||
|
||||
static int aux_unpack (lua_State *L, int arg) {
|
||||
int n, i;
|
||||
luaL_checktype(L, arg, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, arg, LUA_TTABLE);
|
||||
n = lua_getn(L, arg);
|
||||
luaL_checkstack(L, n, l_s("table too big to unpack"));
|
||||
luaL_check_stack(L, n, l_s("table too big to unpack"));
|
||||
for (i=1; i<=n; i++) /* push arg[1...n] */
|
||||
lua_rawgeti(L, arg, i);
|
||||
return n;
|
||||
@ -479,8 +479,8 @@ static int luaB_tostring (lua_State *L) {
|
||||
|
||||
static int luaB_foreachi (lua_State *L) {
|
||||
int n, i;
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 2, LUA_TFUNCTION);
|
||||
n = lua_getn(L, 1);
|
||||
for (i=1; i<=n; i++) {
|
||||
lua_pushvalue(L, 2); /* function */
|
||||
@ -496,8 +496,8 @@ static int luaB_foreachi (lua_State *L) {
|
||||
|
||||
|
||||
static int luaB_foreach (lua_State *L) {
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 2, LUA_TFUNCTION);
|
||||
lua_pushnil(L); /* first index */
|
||||
for (;;) {
|
||||
if (lua_next(L, 1) == 0)
|
||||
@ -514,16 +514,17 @@ static int luaB_foreach (lua_State *L) {
|
||||
|
||||
|
||||
static int luaB_assert (lua_State *L) {
|
||||
luaL_checkany(L, 1);
|
||||
luaL_check_any(L, 1);
|
||||
if (lua_isnil(L, 1))
|
||||
luaL_verror(L, l_s("assertion failed! %.90s"), luaL_opt_string(L, 2, l_s("")));
|
||||
luaL_verror(L, l_s("assertion failed! %.90s"),
|
||||
luaL_opt_string(L, 2, l_s("")));
|
||||
lua_settop(L, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static int luaB_getn (lua_State *L) {
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
lua_pushnumber(L, lua_getn(L, 1));
|
||||
return 1;
|
||||
}
|
||||
@ -532,7 +533,7 @@ static int luaB_getn (lua_State *L) {
|
||||
static int luaB_tinsert (lua_State *L) {
|
||||
int v = lua_gettop(L); /* number of arguments */
|
||||
int n, pos;
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
n = lua_getn(L, 1);
|
||||
if (v == 2) /* called with only 2 arguments */
|
||||
pos = n+1;
|
||||
@ -553,7 +554,7 @@ static int luaB_tinsert (lua_State *L) {
|
||||
|
||||
static int luaB_tremove (lua_State *L) {
|
||||
int pos, n;
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
n = lua_getn(L, 1);
|
||||
pos = luaL_opt_int(L, 2, n);
|
||||
if (n <= 0) return 0; /* table is `empty' */
|
||||
@ -665,10 +666,10 @@ static void auxsort (lua_State *L, int l, int u) {
|
||||
|
||||
static int luaB_sort (lua_State *L) {
|
||||
int n;
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
n = lua_getn(L, 1);
|
||||
if (!lua_isnull(L, 2)) /* is there a 2nd argument? */
|
||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||
luaL_check_rawtype(L, 2, LUA_TFUNCTION);
|
||||
lua_settop(L, 2); /* make sure there is two arguments */
|
||||
auxsort(L, 1, n);
|
||||
return 0;
|
||||
|
4
ldblib.c
4
ldblib.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ldblib.c,v 1.38 2001/08/31 19:46:07 roberto Exp $
|
||||
** $Id: ldblib.c,v 1.39 2001/10/17 21:12:57 roberto Exp $
|
||||
** Interface from Lua to its debug API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -104,7 +104,7 @@ static int setlocal (lua_State *L) {
|
||||
lua_Debug ar;
|
||||
if (!lua_getstack(L, luaL_check_int(L, 1), &ar)) /* level out of range? */
|
||||
luaL_argerror(L, 1, l_s("level out of range"));
|
||||
luaL_checkany(L, 3);
|
||||
luaL_check_any(L, 3);
|
||||
lua_pushstring(L, lua_setlocal(L, &ar, luaL_check_int(L, 2)));
|
||||
return 1;
|
||||
}
|
||||
|
8
liolib.c
8
liolib.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: liolib.c,v 1.122 2001/08/31 19:46:07 roberto Exp $
|
||||
** $Id: liolib.c,v 1.123 2001/10/02 16:41:36 roberto Exp $
|
||||
** Standard I/O (and system) library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -254,7 +254,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) {
|
||||
double d;
|
||||
lua_Number d;
|
||||
if (fscanf(f, l_s(LUA_NUMBER_SCAN), &d) == 1) {
|
||||
lua_pushnumber(L, d);
|
||||
return 1;
|
||||
@ -299,7 +299,7 @@ static int io_read (lua_State *L) {
|
||||
n = 2; /* will return n-1 results */
|
||||
}
|
||||
else { /* ensure stack space for all results and for auxlib's buffer */
|
||||
luaL_checkstack(L, nargs+LUA_MINSTACK, l_s("too many arguments"));
|
||||
luaL_check_stack(L, nargs+LUA_MINSTACK, l_s("too many arguments"));
|
||||
success = 1;
|
||||
for (n = 1; n<=nargs && success; n++) {
|
||||
if (lua_rawtag(L, n) == LUA_TNUMBER) {
|
||||
@ -515,7 +515,7 @@ static int io_time (lua_State *L) {
|
||||
else {
|
||||
time_t t;
|
||||
struct tm ts;
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
lua_settop(L, 1); /* make sure table is at the top */
|
||||
ts.tm_sec = getfield(L, l_s("sec"), 0);
|
||||
ts.tm_min = getfield(L, l_s("min"), 0);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstrlib.c,v 1.71 2001/08/31 19:46:07 roberto Exp $
|
||||
** $Id: lstrlib.c,v 1.72 2001/10/16 17:41:43 roberto Exp $
|
||||
** Standard library for string operations and pattern-matching
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -92,7 +92,7 @@ static int str_concat (lua_State *L) {
|
||||
size_t lsep;
|
||||
const char *sep = luaL_opt_lstr(L, 2, "", &lsep);
|
||||
int n, i;
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
luaL_buffinit(L, &b);
|
||||
n = lua_getn(L, 1);
|
||||
for (i=1; i<=n; i++) {
|
||||
@ -431,7 +431,7 @@ static void push_onecapture (MatchState *ms, int i) {
|
||||
|
||||
static int push_captures (MatchState *ms) {
|
||||
int i;
|
||||
luaL_checkstack(ms->L, ms->level, l_s("too many captures"));
|
||||
luaL_check_stack(ms->L, ms->level, l_s("too many captures"));
|
||||
for (i=0; i<ms->level; i++)
|
||||
push_onecapture(ms, i);
|
||||
return ms->level; /* number of strings pushed */
|
||||
|
14
ltests.c
14
ltests.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: ltests.c,v 1.93 2001/10/17 21:12:57 roberto Exp $
|
||||
** $Id: ltests.c,v 1.94 2001/10/25 19:14:14 roberto Exp $
|
||||
** Internal Module for Debugging of the Lua Implementation
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -247,7 +247,7 @@ static int hash_query (lua_State *L) {
|
||||
else {
|
||||
TObject *o = luaA_index(L, 1);
|
||||
Table *t;
|
||||
luaL_checktype(L, 2, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 2, LUA_TTABLE);
|
||||
t = hvalue(luaA_index(L, 2));
|
||||
lua_pushnumber(L, luaH_mainposition(t, o) - t->node);
|
||||
}
|
||||
@ -258,7 +258,7 @@ static int hash_query (lua_State *L) {
|
||||
static int table_query (lua_State *L) {
|
||||
const Table *t;
|
||||
int i = luaL_opt_int(L, 2, -1);
|
||||
luaL_checktype(L, 1, LUA_TTABLE);
|
||||
luaL_check_rawtype(L, 1, LUA_TTABLE);
|
||||
t = hvalue(luaA_index(L, 1));
|
||||
if (i == -1) {
|
||||
lua_pushnumber(L, t->sizearray);
|
||||
@ -312,7 +312,7 @@ static int string_query (lua_State *L) {
|
||||
|
||||
static int tref (lua_State *L) {
|
||||
int level = lua_gettop(L);
|
||||
luaL_checkany(L, 1);
|
||||
luaL_check_any(L, 1);
|
||||
lua_pushvalue(L, 1);
|
||||
lua_pushnumber(L, lua_ref(L, 1));
|
||||
assert(lua_gettop(L) == level+1); /* +1 for result */
|
||||
@ -346,14 +346,14 @@ static int newuserdatabox (lua_State *L) {
|
||||
}
|
||||
|
||||
static int settag (lua_State *L) {
|
||||
luaL_checkany(L, 1);
|
||||
luaL_check_any(L, 1);
|
||||
lua_pushvalue(L, 1); /* push value */
|
||||
lua_settag(L, luaL_check_int(L, 2));
|
||||
return 1; /* return value */
|
||||
}
|
||||
|
||||
static int udataval (lua_State *L) {
|
||||
luaL_checktype(L, 1, LUA_TUSERDATA);
|
||||
luaL_check_rawtype(L, 1, LUA_TUSERDATA);
|
||||
lua_pushnumber(L, cast(int, lua_touserdata(L, 1)));
|
||||
return 1;
|
||||
}
|
||||
@ -438,7 +438,7 @@ static int doremote (lua_State *L) {
|
||||
static int settagmethod (lua_State *L) {
|
||||
int tag = luaL_check_int(L, 1);
|
||||
const l_char *event = luaL_check_string(L, 2);
|
||||
luaL_checkany(L, 3);
|
||||
luaL_check_any(L, 3);
|
||||
lua_gettagmethod(L, tag, event);
|
||||
lua_pushvalue(L, 3);
|
||||
lua_settagmethod(L, tag, event);
|
||||
|
Loading…
Reference in New Issue
Block a user