Skip to content

Commit 17291bf

Browse files
authored
Merge pull request #47 from NiceAndPeter/claude/modernize-nu-01WwycWxne9VSgahxUfqsWm1
Modernize NU
2 parents b2769e7 + aa61f96 commit 17291bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+583
-583
lines changed

src/auxiliary/lauxlib.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ LUALIB_API int luaL_argerror (lua_State *L, int arg, const char *extramsg) {
188188
}
189189
argword = "argument";
190190
}
191-
if (ar.name == NULL)
191+
if (ar.name == nullptr)
192192
ar.name = (pushglobalfuncname(L, &ar)) ? lua_tostring(L, -1) : "?";
193193
return luaL_error(L, "bad %s #%d to '%s' (%s)",
194194
argword, arg, ar.name, extramsg);
@@ -291,7 +291,7 @@ LUALIB_API int luaL_fileresult (lua_State *L, int stat, const char *fname) {
291291

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

337337
LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {
338338
void *p = lua_touserdata(L, ud);
339-
if (p != NULL) { /* value is a userdata? */
339+
if (p != nullptr) { /* value is a userdata? */
340340
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
341341
luaL_getmetatable(L, tname); /* get correct metatable */
342342
if (!lua_rawequal(L, -1, -2)) /* not the same? */
343-
p = NULL; /* value is a userdata with wrong metatable */
343+
p = nullptr; /* value is a userdata with wrong metatable */
344344
lua_pop(L, 2); /* remove both metatables */
345345
return p;
346346
}
347347
}
348-
return NULL; /* value is not a userdata with a metatable */
348+
return nullptr; /* value is not a userdata with a metatable */
349349
}
350350

351351

352352
LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
353353
void *p = luaL_testudata(L, ud, tname);
354-
luaL_argexpected(L, p != NULL, ud, tname);
354+
luaL_argexpected(L, p != nullptr, ud, tname);
355355
return p;
356356
}
357357

@@ -490,7 +490,7 @@ static void *resizebox (lua_State *L, int idx, size_t newsize) {
490490
void *ud;
491491
lua_Alloc allocf = lua_getallocf(L, &ud);
492492
void *temp = allocf(ud, box->box, box->bsize, newsize);
493-
if (l_unlikely(temp == NULL && newsize > 0)) { /* allocation error? */
493+
if (l_unlikely(temp == nullptr && newsize > 0)) { /* allocation error? */
494494
lua_pushliteral(L, "not enough memory");
495495
lua_error(L); /* raise a memory error */
496496
}
@@ -510,13 +510,13 @@ static int boxgc (lua_State *L) {
510510
static const luaL_Reg boxmt[] = { /* box metamethods */
511511
{"__gc", boxgc},
512512
{"__close", boxgc},
513-
{NULL, NULL}
513+
{nullptr, nullptr}
514514
};
515515

516516

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

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

542542

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

597597

598598
LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {
599-
if (l > 0) { /* avoid 'std::copy_n' when 's' can be NULL */
599+
if (l > 0) { /* avoid 'std::copy_n' when 's' can be nullptr */
600600
char *b = prepbuffsize(B, l, -1);
601601
std::copy_n(s, l, b);
602602
luaL_addsize(B, l);
@@ -624,7 +624,7 @@ LUALIB_API void luaL_pushresult (luaL_Buffer *B) {
624624
s = (char*)box->box; /* final buffer address */
625625
s[len] = '\0'; /* add ending zero */
626626
/* clear box, as Lua will take control of the buffer */
627-
box->bsize = 0; box->box = NULL;
627+
box->bsize = 0; box->box = nullptr;
628628
lua_pushexternalstring(L, s, len, allocf, ud);
629629
lua_closeslot(L, -2); /* close the box */
630630
lua_gc(L, LUA_GCSTEP, len);
@@ -752,7 +752,7 @@ static const char *getF (lua_State *L, void *ud, size_t *size) {
752752
/* 'fread' can return > 0 *and* set the EOF flag. If next call to
753753
'getF' called 'fread', it might still wait for user input.
754754
The next check avoids this problem. */
755-
if (feof(lf->f)) return NULL;
755+
if (feof(lf->f)) return nullptr;
756756
*size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */
757757
}
758758
return lf->buff;
@@ -812,15 +812,15 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
812812
int status, readstatus;
813813
int c;
814814
int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */
815-
if (filename == NULL) {
815+
if (filename == nullptr) {
816816
lua_pushliteral(L, "=stdin");
817817
lf.f = stdin;
818818
}
819819
else {
820820
lua_pushfstring(L, "@%s", filename);
821821
errno = 0;
822822
lf.f = fopen(filename, "r");
823-
if (lf.f == NULL) return errfile(L, "open", fnameindex);
823+
if (lf.f == nullptr) return errfile(L, "open", fnameindex);
824824
}
825825
lf.n = 0;
826826
if (skipcomment(lf.f, &c)) /* read initial portion */
@@ -830,7 +830,7 @@ LUALIB_API int luaL_loadfilex (lua_State *L, const char *filename,
830830
if (filename) { /* "real" file? */
831831
errno = 0;
832832
lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */
833-
if (lf.f == NULL) return errfile(L, "reopen", fnameindex);
833+
if (lf.f == nullptr) return errfile(L, "reopen", fnameindex);
834834
skipcomment(lf.f, &c); /* re-read initial portion */
835835
}
836836
}
@@ -858,7 +858,7 @@ typedef struct LoadS {
858858
static const char *getS (lua_State *L, void *ud, size_t *size) {
859859
LoadS *ls = (LoadS *)ud;
860860
(void)L; /* not used */
861-
if (ls->size == 0) return NULL;
861+
if (ls->size == 0) return nullptr;
862862
*size = ls->size;
863863
ls->size = 0;
864864
return ls->s;
@@ -965,8 +965,8 @@ LUALIB_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) {
965965
*/
966966
LUALIB_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) {
967967
luaL_checkstack(L, nup, "too many upvalues");
968-
for (; l->name != NULL; l++) { /* fill the table with given functions */
969-
if (l->func == NULL) /* placeholder? */
968+
for (; l->name != nullptr; l++) { /* fill the table with given functions */
969+
if (l->func == nullptr) /* placeholder? */
970970
lua_pushboolean(L, 0);
971971
else {
972972
int i;
@@ -1028,7 +1028,7 @@ LUALIB_API void luaL_addgsub (luaL_Buffer *b, const char *s,
10281028
const char *p, const char *r) {
10291029
const char *wild;
10301030
size_t l = strlen(p);
1031-
while ((wild = strstr(s, p)) != NULL) {
1031+
while ((wild = strstr(s, p)) != nullptr) {
10321032
luaL_addlstring(b, s, ct_diff2sz(wild - s)); /* push prefix */
10331033
luaL_addstring(b, r); /* push replacement in place of pattern */
10341034
s = wild + l; /* continue after 'p' */
@@ -1051,7 +1051,7 @@ static void *l_alloc (void *ud, void *ptr, size_t osize, size_t nsize) {
10511051
(void)ud; (void)osize; /* not used */
10521052
if (nsize == 0) {
10531053
free(ptr);
1054-
return NULL;
1054+
return nullptr;
10551055
}
10561056
else
10571057
return realloc(ptr, nsize);
@@ -1157,7 +1157,7 @@ static unsigned int luai_makeseed (void) {
11571157
unsigned int buff[BUFSEED];
11581158
unsigned int res;
11591159
unsigned int i;
1160-
time_t t = time(NULL);
1160+
time_t t = time(nullptr);
11611161
char *b = (char*)buff;
11621162
addbuff(b, b); /* local variable's address */
11631163
addbuff(b, t); /* time */
@@ -1183,7 +1183,7 @@ LUALIB_API unsigned int luaL_makeseed (lua_State *L) {
11831183
** as a macro.
11841184
*/
11851185
LUALIB_API lua_State *(luaL_newstate) (void) {
1186-
lua_State *L = lua_newstate(l_alloc, NULL, luai_makeseed());
1186+
lua_State *L = lua_newstate(l_alloc, nullptr, luai_makeseed());
11871187
if (l_likely(L)) {
11881188
lua_atpanic(L, &panic);
11891189
lua_setwarnf(L, warnfoff, L); /* default is warnings off */

src/auxiliary/linit.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ static const luaL_Reg stdlibs[] = {
3636
{LUA_STRLIBNAME, luaopen_string},
3737
{LUA_TABLIBNAME, luaopen_table},
3838
{LUA_UTF8LIBNAME, luaopen_utf8},
39-
{NULL, NULL}
39+
{nullptr, nullptr}
4040
};
4141

4242

@@ -47,7 +47,7 @@ LUALIB_API void luaL_openselectedlibs (lua_State *L, int load, int preload) {
4747
int mask;
4848
const luaL_Reg *lib;
4949
luaL_getsubtable(L, LUA_REGISTRYINDEX, LUA_PRELOAD_TABLE);
50-
for (lib = stdlibs, mask = 1; lib->name != NULL; lib++, mask <<= 1) {
50+
for (lib = stdlibs, mask = 1; lib->name != nullptr; lib++, mask <<= 1) {
5151
if (load & mask) { /* selected? */
5252
luaL_requiref(L, lib->name, lib->func, 1); /* require library */
5353
lua_pop(L, 1); /* remove result from the stack */

src/compiler/funcstate.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ short FuncState::registerlocalvar(TString *varname) {
9292
luaM_growvector(getLexState()->getLuaState(), proto->getLocVarsRef(), getNumDebugVars(), proto->getLocVarsSizeRef(),
9393
LocVar, SHRT_MAX, "local variables");
9494
while (oldsize < proto->getLocVarsSize())
95-
proto->getLocVars()[oldsize++].setVarName(NULL);
95+
proto->getLocVars()[oldsize++].setVarName(nullptr);
9696
proto->getLocVars()[getNumDebugVars()].setVarName(varname);
9797
proto->getLocVars()[getNumDebugVars()].setStartPC(getPC());
9898
luaC_objbarrier(getLexState()->getLuaState(), proto, varname);
@@ -140,7 +140,7 @@ lu_byte FuncState::nvarstack() {
140140
LocVar *FuncState::localdebuginfo(int vidx) {
141141
Vardesc *vd = getlocalvardesc(vidx);
142142
if (!vd->isInReg())
143-
return NULL; /* no debug info. for constants */
143+
return nullptr; /* no debug info. for constants */
144144
else {
145145
int idx = vd->vd.pidx;
146146
lua_assert(idx < getNumDebugVars());
@@ -197,7 +197,7 @@ Upvaldesc *FuncState::allocupvalue() {
197197
luaM_growvector(getLexState()->getLuaState(), proto->getUpvaluesRef(), getNumUpvalues(), proto->getUpvaluesSizeRef(),
198198
Upvaldesc, MAXUPVAL, "upvalues");
199199
while (oldsize < proto->getUpvaluesSize())
200-
proto->getUpvalues()[oldsize++].setName(NULL);
200+
proto->getUpvalues()[oldsize++].setName(nullptr);
201201
return &proto->getUpvalues()[getNumUpvaluesRef()++];
202202
}
203203

@@ -238,7 +238,7 @@ int FuncState::searchvar(TString *n, expdesc *var) {
238238
for (i = cast_int(getNumActiveVars()) - 1; i >= 0; i--) {
239239
Vardesc *vd = getlocalvardesc(i);
240240
if (vd->isGlobal()) { /* global declaration? */
241-
if (vd->vd.name == NULL) { /* collective declaration? */
241+
if (vd->vd.name == nullptr) { /* collective declaration? */
242242
if (var->getInfo() < 0) /* no previous collective declaration? */
243243
var->setInfo(getFirstLocal() + i); /* this is the first one */
244244
}
@@ -301,7 +301,7 @@ void FuncState::singlevaraux(TString *n, expdesc *var, int base) {
301301
else { /* not found at current level; try upvalues */
302302
int idx = searchupvalue(n); /* try existing upvalues */
303303
if (idx < 0) { /* not found? */
304-
if (getPrev() != NULL) /* more levels? */
304+
if (getPrev() != nullptr) /* more levels? */
305305
getPrev()->singlevaraux(n, var, 0); /* try upper levels */
306306
if (var->getKind() == VLOCAL || var->getKind() == VUPVAL) /* local or upvalue? */
307307
idx = newupvalue(n, var); /* will be a new upvalue */
@@ -329,7 +329,7 @@ void FuncState::solvegotos(BlockCnt *blockCnt) {
329329
Labeldesc *gt = &(*gl)[igt];
330330
/* search for a matching label in the current block */
331331
Labeldesc *lb = lexState->findlabel(gt->name, blockCnt->firstlabel);
332-
if (lb != NULL) /* found a match? */
332+
if (lb != nullptr) /* found a match? */
333333
lexState->closegoto(this, igt, lb, blockCnt->upval); /* close and remove goto */
334334
else { /* adjust 'goto' for outer block */
335335
/* block has variables to be closed and goto escapes the scope of
@@ -351,7 +351,7 @@ void FuncState::enterblock(BlockCnt *blk, lu_byte isloop) {
351351
blk->firstgoto = getLexState()->getDyndata()->gt.getN();
352352
blk->upval = 0;
353353
/* inherit 'insidetbc' from enclosing block */
354-
blk->insidetbc = (getBlock() != NULL && getBlock()->insidetbc);
354+
blk->insidetbc = (getBlock() != nullptr && getBlock()->insidetbc);
355355
blk->previous = getBlock(); /* link block in function's block list */
356356
setBlock(blk);
357357
lua_assert(getFreeReg() == luaY_nvarstack(this));
@@ -370,7 +370,7 @@ void FuncState::leaveblock() {
370370
if (blk->isloop == 2) /* has to fix pending breaks? */
371371
lexstate->createlabel(this, lexstate->getBreakName(), 0, 0);
372372
solvegotos(blk);
373-
if (blk->previous == NULL) { /* was it the last block? */
373+
if (blk->previous == nullptr) { /* was it the last block? */
374374
if (blk->firstgoto < lexstate->getDyndata()->gt.getN()) /* still pending gotos? */
375375
lexstate->undefgoto(this, &lexstate->getDyndata()->gt[blk->firstgoto]); /* error */
376376
}

src/compiler/lcode.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -943,7 +943,7 @@ void FuncState::codebinNoK(BinOpr opr, expdesc *e1, expdesc *e2, int flip, int l
943943
** constant in the proper range, use variant opcodes with K operands.
944944
*/
945945
void FuncState::codearith(BinOpr opr, expdesc *e1, expdesc *e2, int flip, int line) {
946-
if (tonumeral(e2, NULL) && exp2K(e2)) /* K operand? */
946+
if (tonumeral(e2, nullptr) && exp2K(e2)) /* K operand? */
947947
codebinK(opr, e1, e2, flip, line);
948948
else /* 'e2' is neither an immediate nor a K operand */
949949
codebinNoK(opr, e1, e2, flip, line);
@@ -956,7 +956,7 @@ void FuncState::codearith(BinOpr opr, expdesc *e1, expdesc *e2, int flip, int li
956956
*/
957957
void FuncState::codecommutative(BinOpr op, expdesc *e1, expdesc *e2, int line) {
958958
int flip = 0;
959-
if (tonumeral(e1, NULL)) { /* is first operand a numeric constant? */
959+
if (tonumeral(e1, nullptr)) { /* is first operand a numeric constant? */
960960
swapexps(e1, e2); /* change order */
961961
flip = 1;
962962
}
@@ -1527,14 +1527,14 @@ void FuncState::infix(int opr, expdesc *v) {
15271527
case BinOpr::OPR_MOD: case BinOpr::OPR_POW:
15281528
case BinOpr::OPR_BAND: case BinOpr::OPR_BOR: case BinOpr::OPR_BXOR:
15291529
case BinOpr::OPR_SHL: case BinOpr::OPR_SHR: {
1530-
if (!tonumeral(v, NULL))
1530+
if (!tonumeral(v, nullptr))
15311531
exp2anyreg(v);
15321532
/* else keep numeral, which may be folded or used as an immediate
15331533
operand */
15341534
break;
15351535
}
15361536
case BinOpr::OPR_EQ: case BinOpr::OPR_NE: {
1537-
if (!tonumeral(v, NULL))
1537+
if (!tonumeral(v, nullptr))
15381538
exp2RK(v);
15391539
/* else keep numeral, which may be an immediate operand */
15401540
break;

src/compiler/llex.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ int LexState::lex(SemInfo *seminfo) {
463463
size_t sep = skipSep();
464464
luaZ_resetbuffer(getBuffer()); /* 'skip_sep' may dirty the buffer */
465465
if (sep >= 2) {
466-
readLongString(NULL, sep); /* skip long comment */
466+
readLongString(nullptr, sep); /* skip long comment */
467467
luaZ_resetbuffer(getBuffer()); /* previous call may dirty the buff. */
468468
break;
469469
}

src/compiler/parselabels.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ typedef struct BlockCnt {
5454
*/
5555
l_noret LexState::jumpscopeerror(FuncState *funcState, Labeldesc *gt) {
5656
TString *tsname = funcState->getlocalvardesc(gt->nactvar)->vd.name;
57-
const char *varname = (tsname != NULL) ? getstr(tsname) : "*";
57+
const char *varname = (tsname != nullptr) ? getstr(tsname) : "*";
5858
semerror("<goto %s> at line %d jumps into the scope of '%s'",
5959
getstr(gt->name), gt->line, varname); /* raise the error */
6060
}
@@ -103,7 +103,7 @@ Labeldesc *LexState::findlabel(TString *name, int ilb) {
103103
if (eqstr(lb->name, name)) /* correct label? */
104104
return lb;
105105
}
106-
return NULL; /* label not found */
106+
return nullptr; /* label not found */
107107
}
108108

109109

0 commit comments

Comments
 (0)