mirror of
https://github.com/lua/lua.git
synced 2024-11-23 18:23:43 +08:00
details
This commit is contained in:
parent
d84cc9d2db
commit
d55bb795fa
10
lapi.c
10
lapi.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lapi.c,v 2.26 2005/01/14 14:19:42 roberto Exp roberto $
|
||||
** $Id: lapi.c,v 2.27 2005/02/18 12:40:02 roberto Exp roberto $
|
||||
** Lua API
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -975,7 +975,7 @@ LUA_API void lua_concat (lua_State *L, int n) {
|
||||
|
||||
LUA_API lua_Alloc lua_getallocf (lua_State *L, void **ud) {
|
||||
*ud = G(L)->ud;
|
||||
return G(L)->realloc;
|
||||
return G(L)->frealloc;
|
||||
}
|
||||
|
||||
|
||||
@ -993,7 +993,7 @@ LUA_API void *lua_newuserdata (lua_State *L, size_t size) {
|
||||
|
||||
|
||||
|
||||
static const char *aux_upvalue (lua_State *L, StkId fi, int n, TValue **val) {
|
||||
static const char *aux_upvalue (StkId fi, int n, TValue **val) {
|
||||
Closure *f;
|
||||
if (!ttisfunction(fi)) return NULL;
|
||||
f = clvalue(fi);
|
||||
@ -1015,7 +1015,7 @@ LUA_API const char *lua_getupvalue (lua_State *L, int funcindex, int n) {
|
||||
const char *name;
|
||||
TValue *val;
|
||||
lua_lock(L);
|
||||
name = aux_upvalue(L, index2adr(L, funcindex), n, &val);
|
||||
name = aux_upvalue(index2adr(L, funcindex), n, &val);
|
||||
if (name) {
|
||||
setobj2s(L, L->top, val);
|
||||
api_incr_top(L);
|
||||
@ -1032,7 +1032,7 @@ LUA_API const char *lua_setupvalue (lua_State *L, int funcindex, int n) {
|
||||
lua_lock(L);
|
||||
fi = index2adr(L, funcindex);
|
||||
api_checknelems(L, 1);
|
||||
name = aux_upvalue(L, fi, n, &val);
|
||||
name = aux_upvalue(fi, n, &val);
|
||||
if (name) {
|
||||
L->top--;
|
||||
setobj(L, val, L->top);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lauxlib.c,v 1.127 2004/12/20 13:47:29 roberto Exp roberto $
|
||||
** $Id: lauxlib.c,v 1.128 2005/02/10 17:12:02 roberto Exp roberto $
|
||||
** Auxiliary functions for building Lua libraries
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -704,6 +704,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
|
||||
|
||||
|
||||
static int panic (lua_State *L) {
|
||||
(void)L; /* to avoid warnings */
|
||||
fprintf(stderr, "PANIC: unprotected error during Lua-API call\n");
|
||||
return 0;
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lbaselib.c,v 1.166 2005/02/14 13:19:44 roberto Exp roberto $
|
||||
** $Id: lbaselib.c,v 1.167 2005/02/18 12:40:02 roberto Exp roberto $
|
||||
** Basic library
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -283,6 +283,7 @@ static int luaB_loadfile (lua_State *L) {
|
||||
** reserved slot inside the stack.
|
||||
*/
|
||||
static const char *generic_reader (lua_State *L, void *ud, size_t *size) {
|
||||
(void)ud; /* to avoid warnings */
|
||||
luaL_checkstack(L, 2, "too many nested functions");
|
||||
lua_pushvalue(L, 1); /* get function */
|
||||
lua_call(L, 0, 1); /* call it */
|
||||
|
9
lgc.c
9
lgc.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lgc.c,v 2.25 2005/02/14 13:19:50 roberto Exp roberto $
|
||||
** $Id: lgc.c,v 2.26 2005/02/18 12:40:02 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -36,14 +36,13 @@
|
||||
((x)->gch.marked = ((x)->gch.marked & maskmarks) | luaC_white(g))
|
||||
|
||||
#define white2gray(x) reset2bits((x)->gch.marked, WHITE0BIT, WHITE1BIT)
|
||||
#define gray2black(x) setbit((x)->gch.marked, BLACKBIT)
|
||||
#define black2gray(x) resetbit((x)->gch.marked, BLACKBIT)
|
||||
|
||||
#define stringmark(s) reset2bits((s)->tsv.marked, WHITE0BIT, WHITE1BIT)
|
||||
|
||||
|
||||
#define isfinalized(u) testbit((u)->marked, FINALIZEDBIT)
|
||||
#define markfinalized(u) setbit((u)->marked, FINALIZEDBIT)
|
||||
#define markfinalized(u) l_setbit((u)->marked, FINALIZEDBIT)
|
||||
|
||||
|
||||
#define KEYWEAK bitmask(KEYWEAKBIT)
|
||||
@ -665,9 +664,9 @@ void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v) {
|
||||
}
|
||||
|
||||
|
||||
void luaC_barrierback (lua_State *L, GCObject *o, GCObject *v) {
|
||||
void luaC_barrierback (lua_State *L, GCObject *o) {
|
||||
global_State *g = G(L);
|
||||
lua_assert(isblack(o) && iswhite(v) && !isdead(g, v) && !isdead(g, o));
|
||||
lua_assert(isblack(o) && !isdead(g, o));
|
||||
lua_assert(g->gcstate != GCSfinalize && g->gcstate != GCSpause);
|
||||
black2gray(o); /* make table gray (again) */
|
||||
gco2h(o)->gclist = g->grayagain;
|
||||
|
12
lgc.h
12
lgc.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lgc.h,v 2.10 2005/01/19 15:54:26 roberto Exp roberto $
|
||||
** $Id: lgc.h,v 2.11 2005/02/10 13:25:02 roberto Exp roberto $
|
||||
** Garbage Collector
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -29,7 +29,7 @@
|
||||
#define testbits(x,m) ((x) & (m))
|
||||
#define bitmask(b) (1<<(b))
|
||||
#define bit2mask(b1,b2) (bitmask(b1) | bitmask(b2))
|
||||
#define setbit(x,b) setbits(x, bitmask(b))
|
||||
#define l_setbit(x,b) setbits(x, bitmask(b))
|
||||
#define resetbit(x,b) resetbits(x, bitmask(b))
|
||||
#define testbit(x,b) testbits(x, bitmask(b))
|
||||
#define set2bits(x,b1,b2) setbits(x, (bit2mask(b1, b2)))
|
||||
@ -70,7 +70,7 @@
|
||||
#define isdead(g,v) ((v)->gch.marked & otherwhite(g) & WHITEBITS)
|
||||
|
||||
#define changewhite(x) ((x)->gch.marked ^= WHITEBITS)
|
||||
#define gray2black(x) setbit((x)->gch.marked, BLACKBIT)
|
||||
#define gray2black(x) l_setbit((x)->gch.marked, BLACKBIT)
|
||||
|
||||
#define valiswhite(x) (iscollectable(x) && iswhite(gcvalue(x)))
|
||||
|
||||
@ -85,7 +85,7 @@
|
||||
luaC_barrierf(L,obj2gco(p),gcvalue(v)); }
|
||||
|
||||
#define luaC_barriert(L,p,v) { if (valiswhite(v) && isblack(obj2gco(p))) \
|
||||
luaC_barrierback(L,obj2gco(p),gcvalue(v)); }
|
||||
luaC_barrierback(L,obj2gco(p)); }
|
||||
|
||||
#define luaC_objbarrier(L,p,o) \
|
||||
{ if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
|
||||
@ -93,7 +93,7 @@
|
||||
|
||||
#define luaC_objbarriert(L,p,o) \
|
||||
{ if (iswhite(obj2gco(o)) && isblack(obj2gco(p))) \
|
||||
luaC_barrierback(L,obj2gco(p),obj2gco(o)); }
|
||||
luaC_barrierback(L,obj2gco(p)); }
|
||||
|
||||
size_t luaC_separateudata (lua_State *L, int all);
|
||||
void luaC_callGCTM (lua_State *L);
|
||||
@ -103,7 +103,7 @@ void luaC_fullgc (lua_State *L);
|
||||
void luaC_link (lua_State *L, GCObject *o, lu_byte tt);
|
||||
void luaC_linkupval (lua_State *L, UpVal *uv);
|
||||
void luaC_barrierf (lua_State *L, GCObject *o, GCObject *v);
|
||||
void luaC_barrierback (lua_State *L, GCObject *o, GCObject *v);
|
||||
void luaC_barrierback (lua_State *L, GCObject *o);
|
||||
|
||||
|
||||
#endif
|
||||
|
16
lmem.c
16
lmem.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lmem.c,v 1.67 2004/12/01 15:46:18 roberto Exp roberto $
|
||||
** $Id: lmem.c,v 1.68 2005/01/14 14:21:16 roberto Exp roberto $
|
||||
** Interface to Memory Manager
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -22,19 +22,19 @@
|
||||
|
||||
/*
|
||||
** About the realloc function:
|
||||
** void * realloc (void *ud, void *ptr, size_t osize, size_t nsize);
|
||||
** void * frealloc (void *ud, void *ptr, size_t osize, size_t nsize);
|
||||
** (`osize' is the old size, `nsize' is the new size)
|
||||
**
|
||||
** Lua ensures that (ptr == NULL) iff (osize == 0).
|
||||
**
|
||||
** * realloc(ud, NULL, 0, x) creates a new block of size `x'
|
||||
** * frealloc(ud, NULL, 0, x) creates a new block of size `x'
|
||||
**
|
||||
** * realloc(ud, p, x, 0) frees the block `p'
|
||||
** (in this specific case, realloc must return NULL).
|
||||
** particularly, realloc(ud, NULL, 0, 0) does nothing
|
||||
** * frealloc(ud, p, x, 0) frees the block `p'
|
||||
** (in this specific case, frealloc must return NULL).
|
||||
** particularly, frealloc(ud, NULL, 0, 0) does nothing
|
||||
** (which is equivalent to free(NULL) in ANSI C)
|
||||
**
|
||||
** realloc returns NULL if it cannot create or reallocate the area
|
||||
** frealloc returns NULL if it cannot create or reallocate the area
|
||||
** (any reallocation to an equal or smaller size cannot fail!)
|
||||
*/
|
||||
|
||||
@ -76,7 +76,7 @@ void *luaM_toobig (lua_State *L) {
|
||||
void *luaM_realloc_ (lua_State *L, void *block, size_t osize, size_t nsize) {
|
||||
global_State *g = G(L);
|
||||
lua_assert((osize == 0) == (block == NULL));
|
||||
block = (*g->realloc)(g->ud, block, osize, nsize);
|
||||
block = (*g->frealloc)(g->ud, block, osize, nsize);
|
||||
if (block == NULL && nsize > 0)
|
||||
luaD_throw(L, LUA_ERRMEM);
|
||||
lua_assert((nsize == 0) == (block == NULL));
|
||||
|
6
lstate.c
6
lstate.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstate.c,v 2.23 2005/01/18 17:18:09 roberto Exp roberto $
|
||||
** $Id: lstate.c,v 2.24 2005/02/10 13:25:02 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -120,7 +120,7 @@ static void close_state (lua_State *L) {
|
||||
luaZ_freebuffer(L, &g->buff);
|
||||
freestack(L, L);
|
||||
lua_assert(g->totalbytes == sizeof(LG));
|
||||
(*g->realloc)(g->ud, fromstate(L), state_size(LG), 0);
|
||||
(*g->frealloc)(g->ud, fromstate(L), state_size(LG), 0);
|
||||
}
|
||||
|
||||
|
||||
@ -160,7 +160,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
|
||||
L->marked = luaC_white(g);
|
||||
set2bits(L->marked, FIXEDBIT, SFIXEDBIT);
|
||||
preinit_state(L, g);
|
||||
g->realloc = f;
|
||||
g->frealloc = f;
|
||||
g->ud = ud;
|
||||
g->mainthread = L;
|
||||
g->uvhead.u.l.prev = &g->uvhead;
|
||||
|
6
lstate.h
6
lstate.h
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstate.h,v 2.14 2005/02/11 20:03:35 roberto Exp roberto $
|
||||
** $Id: lstate.h,v 2.15 2005/02/18 12:40:02 roberto Exp roberto $
|
||||
** Global State
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -67,8 +67,8 @@ typedef struct CallInfo {
|
||||
*/
|
||||
typedef struct global_State {
|
||||
stringtable strt; /* hash table for strings */
|
||||
lua_Alloc realloc; /* function to reallocate memory */
|
||||
void *ud; /* auxiliary data to `realloc' */
|
||||
lua_Alloc frealloc; /* function to reallocate memory */
|
||||
void *ud; /* auxiliary data to `frealloc' */
|
||||
lu_byte currentwhite;
|
||||
lu_byte gcstate; /* state of garbage collector */
|
||||
GCObject *rootgc; /* list of all collectable objects */
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lstring.h,v 1.40 2004/11/19 15:52:40 roberto Exp roberto $
|
||||
** $Id: lstring.h,v 1.41 2005/02/18 12:40:02 roberto Exp roberto $
|
||||
** String table (keep all strings handled by Lua)
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -21,7 +21,7 @@
|
||||
#define luaS_newliteral(L, s) (luaS_newlstr(L, "" s, \
|
||||
(sizeof(s)/sizeof(char))-1))
|
||||
|
||||
#define luaS_fix(s) setbit((s)->tsv.marked, FIXEDBIT)
|
||||
#define luaS_fix(s) l_setbit((s)->tsv.marked, FIXEDBIT)
|
||||
|
||||
void luaS_resize (lua_State *L, int newsize);
|
||||
Udata *luaS_newudata (lua_State *L, size_t s, Table *e);
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: luaconf.h,v 1.27 2005/01/10 18:33:37 roberto Exp roberto $
|
||||
** $Id: luaconf.h,v 1.28 2005/02/10 17:12:02 roberto Exp roberto $
|
||||
** Configuration file for Lua
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -307,7 +307,7 @@ __inline int l_lrint (double flt)
|
||||
|
||||
|
||||
/* allows user-specific initialization on new threads */
|
||||
#define lua_userstateopen(L) /* empty */
|
||||
#define lua_userstateopen(L) ((void)0)
|
||||
|
||||
|
||||
#endif
|
||||
@ -325,9 +325,6 @@ __inline int l_lrint (double flt)
|
||||
#ifdef LUA_LIB
|
||||
|
||||
|
||||
|
||||
/* `assert' options */
|
||||
|
||||
/* environment variables that hold the search path for packages */
|
||||
#define LUA_PATH "LUA_PATH"
|
||||
#define LUA_CPATH "LUA_CPATH"
|
||||
@ -336,7 +333,7 @@ __inline int l_lrint (double flt)
|
||||
#define LUA_POF "luaopen_"
|
||||
|
||||
/* separator for open functions in C libraries */
|
||||
#define LUA_OFSEP ""
|
||||
#define LUA_OFSEP "_"
|
||||
|
||||
/* directory separator (for submodules) */
|
||||
#if defined(_WIN32)
|
||||
|
4
lvm.c
4
lvm.c
@ -1,5 +1,5 @@
|
||||
/*
|
||||
** $Id: lvm.c,v 2.24 2005/02/18 12:40:02 roberto Exp roberto $
|
||||
** $Id: lvm.c,v 2.25 2005/02/18 12:50:08 roberto Exp roberto $
|
||||
** Lua virtual machine
|
||||
** See Copyright Notice in lua.h
|
||||
*/
|
||||
@ -113,7 +113,7 @@ StkId luaV_gettable (lua_State *L, const TValue *t, TValue *key, StkId val,
|
||||
const TValue *tm;
|
||||
if (ttistable(t)) { /* `t' is a table? */
|
||||
Table *h = hvalue(t);
|
||||
const TValue *res = luaH_get(h, key); /* do a primitive set */
|
||||
const TValue *res = luaH_get(h, key); /* do a primitive get */
|
||||
if (!ttisnil(res) || /* result is no nil? */
|
||||
(tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */
|
||||
setobj2s(L, val, res);
|
||||
|
Loading…
Reference in New Issue
Block a user