Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions src/auxiliary/lauxlib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) {
}
argword = "argument";
}
if (ar.name == NULL)
if (ar.name == nullptr)
ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
return luaL_error(L, "bad %s #%d to '%s' (%s)",
argword, arg, ar.name, extramsg);
Expand Down Expand Up @@ -291,7 +291,7 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {

LUALIB_API int luaL_execresult (lua_State *L, int stat) {
if (stat == -1) /* error with an 'errno'? */
return luaL_fileresult(L, 0, NULL);
return luaL_fileresult(L, 0, nullptr);
else {
const char *what = "exit"; /* type of termination */
l_inspectstat(stat, what); /* interpret result */
Expand Down Expand Up @@ -336,22 +336,22 @@ LUALIB_API void luaL_setmetatable (lua_State *L, const char *tname) {

LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {
void *p = lua_touserdata(L, ud);
if (p != NULL) { /* value is a userdata? */
if (p != nullptr) { /* value is a userdata? */
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
luaL_getmetatable(L, tname); /* get correct metatable */
if (!lua_rawequal(L, -1, -2)) /* not the same? */
p = NULL; /* value is a userdata with wrong metatable */
p = nullptr; /* value is a userdata with wrong metatable */
lua_pop(L, 2); /* remove both metatables */
return p;
}
}
return NULL; /* value is not a userdata with a metatable */
return nullptr; /* value is not a userdata with a metatable */
}


LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
void *p = luaL_testudata(L, ud, tname);
luaL_argexpected(L, p != NULL, ud, tname);
luaL_argexpected(L, p != nullptr, ud, tname);
return p;
}

Expand Down Expand Up @@ -490,7 +490,7 @@ static void *resizebox (lua_State *L, int idx, size_t newsize) {
void *ud;
lua_Alloc allocf = lua_getallocf(L, &ud);
void *temp = allocf(ud, box->box, box->bsize, newsize);
if (l_unlikely(temp == NULL && newsize > 0)) { /* allocation error? */
if (l_unlikely(temp == nullptr && newsize > 0)) { /* allocation error? */
lua_pushliteral(L, "not enough memory");
lua_error(L); /* raise a memory error */
}
Expand All @@ -510,13 +510,13 @@ static int boxgc (lua_State *L) {
static const luaL_Reg boxmt[] = { /* box metamethods */
{"__gc", boxgc},
{"__close", boxgc},
{NULL, NULL}
{nullptr, nullptr}
};


static void newbox (lua_State *L) {
UBox *box = (UBox *)lua_newuserdatauv(L, sizeof(UBox), 0);
box->box = NULL;
box->box = nullptr;
box->bsize = 0;
if (luaL_newmetatable(L, "_UBOX*")) /* creating metatable? */
luaL_setfuncs(L, boxmt, 0); /* set its metamethods */
Expand All @@ -533,10 +533,10 @@ static void newbox (lua_State *L) {

/*
** Whenever buffer is accessed, slot 'idx' must either be a box (which
** cannot be NULL) or it is a placeholder for the buffer.
** cannot be nullptr) or it is a placeholder for the buffer.
*/
#define checkbufferlevel(B,idx) \
lua_assert(buffonstack(B) ? lua_touserdata(B->L, idx) != NULL \
lua_assert(buffonstack(B) ? lua_touserdata(B->L, idx) != nullptr \
: lua_touserdata(B->L, idx) == (void*)B)


Expand Down Expand Up @@ -596,7 +596,7 @@ LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {


LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
if (l > 0) { /* avoid 'std::copy_n' when 's' can be NULL */
if (l > 0) { /* avoid 'std::copy_n' when 's' can be nullptr */
char *b = prepbuffsize(B, l, -1);
std::copy_n(s, l, b);
luaL_addsize(B, l);
Expand Down Expand Up @@ -624,7 +624,7 @@ LUALIB_API void luaL_pushresult (luaL_Buffer *B) {
s = (char*)box->box; /* final buffer address */
s[len] = '\0'; /* add ending zero */
/* clear box, as Lua will take control of the buffer */
box->bsize = 0; box->box = NULL;
box->bsize = 0; box->box = nullptr;
lua_pushexternalstring(L, s, len, allocf, ud);
lua_closeslot(L, -2); /* close the box */
lua_gc(L, LUA_GCSTEP, len);
Expand Down Expand Up @@ -752,7 +752,7 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {
/* 'fread' can return > 0 *and* set the EOF flag. If next call to
'getF' called 'fread', it might still wait for user input.
The next check avoids this problem. */
if (feof(lf->f)) return NULL;
if (feof(lf->f)) return nullptr;
*size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */
}
return lf->buff;
Expand Down Expand Up @@ -812,15 +812,15 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
int status, readstatus;
int c;
int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
if (filename == NULL) {
if (filename == nullptr) {
lua_pushliteral(L, "=stdin");
lf.f = stdin;
}
else {
lua_pushfstring(L, "@%s", filename);
errno = 0;
lf.f = fopen(filename, "r");
if (lf.f == NULL) return errfile(L, "open", fnameindex);
if (lf.f == nullptr) return errfile(L, "open", fnameindex);
}
lf.n = 0;
if (skipcomment(lf.f, &c)) /* read initial portion */
Expand All @@ -830,7 +830,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
if (filename) { /* "real" file? */
errno = 0;
lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
if (lf.f == nullptr) return errfile(L, "reopen", fnameindex);
skipcomment(lf.f, &c); /* re-read initial portion */
}
}
Expand Down Expand Up @@ -858,7 +858,7 @@ typedef struct LoadS {
static const char *getS (lua_State *L, void *ud, size_t *size) {
LoadS *ls = (LoadS *)ud;
(void)L; /* not used */
if (ls->size == 0) return NULL;
if (ls->size == 0) return nullptr;
*size = ls->size;
ls->size = 0;
return ls->s;
Expand Down Expand Up @@ -965,8 +965,8 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
*/
LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
luaL_checkstack(L, nup, "too many upvalues");
for (; l->name != NULL; l++) { /* fill the table with given functions */
if (l->func == NULL) /* placeholder? */
for (; l->name != nullptr; l++) { /* fill the table with given functions */
if (l->func == nullptr) /* placeholder? */
lua_pushboolean(L, 0);
else {
int i;
Expand Down Expand Up @@ -1028,7 +1028,7 @@ LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,
const char *p, const char *r) {
const char *wild;
size_t l = strlen(p);
while ((wild = strstr(s, p)) != NULL) {
while ((wild = strstr(s, p)) != nullptr) {
luaL_addlstring(b, s, ct_diff2sz(wild - s)); /* push prefix */
luaL_addstring(b, r); /* push replacement in place of pattern */
s = wild + l; /* continue after 'p' */
Expand All @@ -1051,7 +1051,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
(void)ud; (void)osize; /* not used */
if (nsize == 0) {
free(ptr);
return NULL;
return nullptr;
}
else
return realloc(ptr, nsize);
Expand Down Expand Up @@ -1157,7 +1157,7 @@ static unsigned int luai_makeseed (void) {
unsigned int buff[BUFSEED];
unsigned int res;
unsigned int i;
time_t t = time(NULL);
time_t t = time(nullptr);
char *b = (char*)buff;
addbuff(b, b); /* local variable's address */
addbuff(b, t); /* time */
Expand All @@ -1183,7 +1183,7 @@ LUALIB_API unsigned int luaL_makeseed (lua_State *L) {
** as a macro.
*/
LUALIB_API lua_State *(luaL_newstate) (void) {
lua_State *L = lua_newstate(l_alloc, NULL, luai_makeseed());
lua_State *L = lua_newstate(l_alloc, nullptr, luai_makeseed());
if (l_likely(L)) {
lua_atpanic(L, &panic);
lua_setwarnf(L, warnfoff, L); /* default is warnings off */
Expand Down
4 changes: 2 additions & 2 deletions src/auxiliary/linit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static const luaL_Reg stdlibs[] = {
{LUA_STRLIBNAME, luaopen_string},
{LUA_TABLIBNAME, luaopen_table},
{LUA_UTF8LIBNAME, luaopen_utf8},
{NULL, NULL}
{nullptr, nullptr}
};


Expand All @@ -47,7 +47,7 @@ LUALIB_API void luaL_openselectedlibs (lua_State *L, int load, int preload) {
int mask;
const luaL_Reg *lib;
luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
for (lib = stdlibs, mask = 1; lib->name != NULL; lib++, mask <<= 1) {
for (lib = stdlibs, mask = 1; lib->name != nullptr; lib++, mask <<= 1) {
if (load & mask) { /* selected? */
luaL_requiref(L, lib->name, lib->func, 1); /* require library */
lua_pop(L, 1); /* remove result from the stack */
Expand Down
16 changes: 8 additions & 8 deletions src/compiler/funcstate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ short FuncState::registerlocalvar(TString *varname) {
luaM_growvector(getLexState()->getLuaState(), proto->getLocVarsRef(), getNumDebugVars(), proto->getLocVarsSizeRef(),
LocVar, SHRT_MAX, "local variables");
while (oldsize < proto->getLocVarsSize())
proto->getLocVars()[oldsize++].setVarName(NULL);
proto->getLocVars()[oldsize++].setVarName(nullptr);
proto->getLocVars()[getNumDebugVars()].setVarName(varname);
proto->getLocVars()[getNumDebugVars()].setStartPC(getPC());
luaC_objbarrier(getLexState()->getLuaState(), proto, varname);
Expand Down Expand Up @@ -140,7 +140,7 @@ lu_byte FuncState::nvarstack() {
LocVar *FuncState::localdebuginfo(int vidx) {
Vardesc *vd = getlocalvardesc(vidx);
if (!vd->isInReg())
return NULL; /* no debug info. for constants */
return nullptr; /* no debug info. for constants */
else {
int idx = vd->vd.pidx;
lua_assert(idx < getNumDebugVars());
Expand Down Expand Up @@ -197,7 +197,7 @@ Upvaldesc *FuncState::allocupvalue() {
luaM_growvector(getLexState()->getLuaState(), proto->getUpvaluesRef(), getNumUpvalues(), proto->getUpvaluesSizeRef(),
Upvaldesc, MAXUPVAL, "upvalues");
while (oldsize < proto->getUpvaluesSize())
proto->getUpvalues()[oldsize++].setName(NULL);
proto->getUpvalues()[oldsize++].setName(nullptr);
return &proto->getUpvalues()[getNumUpvaluesRef()++];
}

Expand Down Expand Up @@ -238,7 +238,7 @@ int FuncState::searchvar(TString *n, expdesc *var) {
for (i = cast_int(getNumActiveVars()) - 1; i >= 0; i--) {
Vardesc *vd = getlocalvardesc(i);
if (vd->isGlobal()) { /* global declaration? */
if (vd->vd.name == NULL) { /* collective declaration? */
if (vd->vd.name == nullptr) { /* collective declaration? */
if (var->getInfo() < 0) /* no previous collective declaration? */
var->setInfo(getFirstLocal() + i); /* this is the first one */
}
Expand Down Expand Up @@ -301,7 +301,7 @@ void FuncState::singlevaraux(TString *n, expdesc *var, int base) {
else { /* not found at current level; try upvalues */
int idx = searchupvalue(n); /* try existing upvalues */
if (idx < 0) { /* not found? */
if (getPrev() != NULL) /* more levels? */
if (getPrev() != nullptr) /* more levels? */
getPrev()->singlevaraux(n, var, 0); /* try upper levels */
if (var->getKind() == VLOCAL || var->getKind() == VUPVAL) /* local or upvalue? */
idx = newupvalue(n, var); /* will be a new upvalue */
Expand Down Expand Up @@ -329,7 +329,7 @@ void FuncState::solvegotos(BlockCnt *blockCnt) {
Labeldesc *gt = &(*gl)[igt];
/* search for a matching label in the current block */
Labeldesc *lb = lexState->findlabel(gt->name, blockCnt->firstlabel);
if (lb != NULL) /* found a match? */
if (lb != nullptr) /* found a match? */
lexState->closegoto(this, igt, lb, blockCnt->upval); /* close and remove goto */
else { /* adjust 'goto' for outer block */
/* block has variables to be closed and goto escapes the scope of
Expand All @@ -351,7 +351,7 @@ void FuncState::enterblock(BlockCnt *blk, lu_byte isloop) {
blk->firstgoto = getLexState()->getDyndata()->gt.getN();
blk->upval = 0;
/* inherit 'insidetbc' from enclosing block */
blk->insidetbc = (getBlock() != NULL && getBlock()->insidetbc);
blk->insidetbc = (getBlock() != nullptr && getBlock()->insidetbc);
blk->previous = getBlock(); /* link block in function's block list */
setBlock(blk);
lua_assert(getFreeReg() == luaY_nvarstack(this));
Expand All @@ -370,7 +370,7 @@ void FuncState::leaveblock() {
if (blk->isloop == 2) /* has to fix pending breaks? */
lexstate->createlabel(this, lexstate->getBreakName(), 0, 0);
solvegotos(blk);
if (blk->previous == NULL) { /* was it the last block? */
if (blk->previous == nullptr) { /* was it the last block? */
if (blk->firstgoto < lexstate->getDyndata()->gt.getN()) /* still pending gotos? */
lexstate->undefgoto(this, &lexstate->getDyndata()->gt[blk->firstgoto]); /* error */
}
Expand Down
8 changes: 4 additions & 4 deletions src/compiler/lcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -943,7 +943,7 @@ void FuncState::codebinNoK(BinOpr opr, expdesc *e1, expdesc *e2, int flip, int l
** constant in the proper range, use variant opcodes with K operands.
*/
void FuncState::codearith(BinOpr opr, expdesc *e1, expdesc *e2, int flip, int line) {
if (tonumeral(e2, NULL) && exp2K(e2)) /* K operand? */
if (tonumeral(e2, nullptr) && exp2K(e2)) /* K operand? */
codebinK(opr, e1, e2, flip, line);
else /* 'e2' is neither an immediate nor a K operand */
codebinNoK(opr, e1, e2, flip, line);
Expand All @@ -956,7 +956,7 @@ void FuncState::codearith(BinOpr opr, expdesc *e1, expdesc *e2, int flip, int li
*/
void FuncState::codecommutative(BinOpr op, expdesc *e1, expdesc *e2, int line) {
int flip = 0;
if (tonumeral(e1, NULL)) { /* is first operand a numeric constant? */
if (tonumeral(e1, nullptr)) { /* is first operand a numeric constant? */
swapexps(e1, e2); /* change order */
flip = 1;
}
Expand Down Expand Up @@ -1527,14 +1527,14 @@ void FuncState::infix(int opr, expdesc *v) {
case BinOpr::OPR_MOD: case BinOpr::OPR_POW:
case BinOpr::OPR_BAND: case BinOpr::OPR_BOR: case BinOpr::OPR_BXOR:
case BinOpr::OPR_SHL: case BinOpr::OPR_SHR: {
if (!tonumeral(v, NULL))
if (!tonumeral(v, nullptr))
exp2anyreg(v);
/* else keep numeral, which may be folded or used as an immediate
operand */
break;
}
case BinOpr::OPR_EQ: case BinOpr::OPR_NE: {
if (!tonumeral(v, NULL))
if (!tonumeral(v, nullptr))
exp2RK(v);
/* else keep numeral, which may be an immediate operand */
break;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/llex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ int LexState::lex(SemInfo *seminfo) {
size_t sep = skipSep();
luaZ_resetbuffer(getBuffer()); /* 'skip_sep' may dirty the buffer */
if (sep >= 2) {
readLongString(NULL, sep); /* skip long comment */
readLongString(nullptr, sep); /* skip long comment */
luaZ_resetbuffer(getBuffer()); /* previous call may dirty the buff. */
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/parselabels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ typedef struct BlockCnt {
*/
l_noret LexState::jumpscopeerror(FuncState *funcState, Labeldesc *gt) {
TString *tsname = funcState->getlocalvardesc(gt->nactvar)->vd.name;
const char *varname = (tsname != NULL) ? getstr(tsname) : "*";
const char *varname = (tsname != nullptr) ? getstr(tsname) : "*";
semerror("<goto %s> at line %d jumps into the scope of '%s'",
getstr(gt->name), gt->line, varname); /* raise the error */
}
Expand Down Expand Up @@ -103,7 +103,7 @@ Labeldesc *LexState::findlabel(TString *name, int ilb) {
if (eqstr(lb->name, name)) /* correct label? */
return lb;
}
return NULL; /* label not found */
return nullptr; /* label not found */
}


Expand Down
Loading
Loading