whitespace adjustment src/nhlua.c

I noticed some tabs had crept into the file, so adjust the whitespace.
This commit is contained in:
nhmall
2024-01-12 12:33:26 -05:00
parent aebc666efa
commit 6274ad3259
+50 -40
View File
@@ -119,7 +119,8 @@ static lua_State *luapat; /* instance for file pattern matching */
void void
l_nhcore_init(void) l_nhcore_init(void)
{ {
nhl_sandbox_info sbi = {NHL_SB_SAFE, 1*1024*1024, 0, 1*1024*1024}; nhl_sandbox_info sbi = { NHL_SB_SAFE, 1 * 1024 * 1024, 0,
1 * 1024 * 1024 };
if ((gl.luacore = nhl_init(&sbi)) != 0) { if ((gl.luacore = nhl_init(&sbi)) != 0) {
if (!nhl_loadlua(gl.luacore, "nhcore.lua")) { if (!nhl_loadlua(gl.luacore, "nhcore.lua")) {
@@ -149,8 +150,8 @@ l_nhcore_call(int callidx)
{ {
int ltyp; int ltyp;
if (callidx < 0 || callidx >= NUM_NHCORE_CALLS if (callidx < 0 || callidx >= NUM_NHCORE_CALLS || !gl.luacore
|| !gl.luacore || !nhcore_call_available[callidx]) || !nhcore_call_available[callidx])
return; return;
lua_getglobal(gl.luacore, "nhcore"); lua_getglobal(gl.luacore, "nhcore");
@@ -256,8 +257,8 @@ nhl_get_timertype(lua_State *L, int idx)
{ {
static const char *const timerstr[NUM_TIME_FUNCS + 1] = { static const char *const timerstr[NUM_TIME_FUNCS + 1] = {
"rot-organic", "rot-corpse", "revive-mon", "zombify-mon", "rot-organic", "rot-corpse", "revive-mon", "zombify-mon",
"burn-obj", "hatch-egg", "fig-transform", "melt-ice", "shrink-glob", "burn-obj", "hatch-egg", "fig-transform", "melt-ice",
NULL "shrink-glob", NULL
}; };
short ret = luaL_checkoption(L, idx, NULL, timerstr); short ret = luaL_checkoption(L, idx, NULL, timerstr);
@@ -302,8 +303,8 @@ nhl_add_table_entry_bool(lua_State *L, const char *name, boolean value)
} }
void void
nhl_add_table_entry_region(lua_State *L, const char *name, nhl_add_table_entry_region(lua_State *L, const char *name, coordxy x1,
coordxy x1, coordxy y1, coordxy x2, coordxy y2) coordxy y1, coordxy x2, coordxy y2)
{ {
lua_pushstring(L, name); lua_pushstring(L, name);
lua_newtable(L); lua_newtable(L);
@@ -435,10 +436,12 @@ nhl_gettrap(lua_State *L)
break; break;
} }
return 1; return 1;
} else } else {
nhl_error(L, "No trap at location"); nhl_error(L, "No trap at location");
} else }
} else {
nhl_error(L, "Coordinates out of range"); nhl_error(L, "Coordinates out of range");
}
return 0; return 0;
} }
@@ -577,8 +580,7 @@ nhl_getmap(lua_State *L)
(levl[x][y].flags & S_LPUDDING)); (levl[x][y].flags & S_LPUDDING));
nhl_add_table_entry_bool(L, "dishwasher", nhl_add_table_entry_bool(L, "dishwasher",
(levl[x][y].flags & S_LDWASHER)); (levl[x][y].flags & S_LDWASHER));
nhl_add_table_entry_bool(L, "ring", nhl_add_table_entry_bool(L, "ring", (levl[x][y].flags & S_LRING));
(levl[x][y].flags & S_LRING));
} }
/* TODO: drawbridges, walls, ladders, room=>ICED_xxx */ /* TODO: drawbridges, walls, ladders, room=>ICED_xxx */
@@ -750,7 +752,8 @@ nhl_menu(lua_State *L)
any.a_char = key[0]; any.a_char = key[0];
add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr, str, add_menu(tmpwin, &nul_glyphinfo, &any, 0, 0, ATR_NONE, clr, str,
(*defval && *key && defval[0] == key[0]) (*defval && *key && defval[0] == key[0])
? MENU_ITEMFLAGS_SELECTED : MENU_ITEMFLAGS_NONE); ? MENU_ITEMFLAGS_SELECTED
: MENU_ITEMFLAGS_NONE);
lua_pop(L, 1); /* removes 'value'; keeps 'key' for next iteration */ lua_pop(L, 1); /* removes 'value'; keeps 'key' for next iteration */
} }
@@ -763,8 +766,8 @@ nhl_menu(lua_State *L)
char buf[2]; char buf[2];
buf[0] = picks[0].item.a_char; buf[0] = picks[0].item.a_char;
if (pick == PICK_ONE && pick_cnt > 1 if (pick == PICK_ONE && pick_cnt > 1 && *defval
&& *defval && defval[0] == picks[0].item.a_char) && defval[0] == picks[0].item.a_char)
buf[0] = picks[1].item.a_char; buf[0] = picks[1].item.a_char;
buf[1] = '\0'; buf[1] = '\0';
@@ -919,7 +922,8 @@ nhl_random(lua_State *L)
if (argc == 1) if (argc == 1)
lua_pushinteger(L, rn2((int) luaL_checkinteger(L, 1))); lua_pushinteger(L, rn2((int) luaL_checkinteger(L, 1)));
else if (argc == 2) else if (argc == 2)
lua_pushinteger(L, luaL_checkinteger(L, 1) + rn2((int) luaL_checkinteger(L, 2))); lua_pushinteger(L, luaL_checkinteger(L, 1)
+ rn2((int) luaL_checkinteger(L, 2)));
else else
nhl_error(L, "Wrong args"); nhl_error(L, "Wrong args");
@@ -933,8 +937,7 @@ nhl_level_difficulty(lua_State *L)
int argc = lua_gettop(L); int argc = lua_gettop(L);
if (argc == 0) { if (argc == 0) {
lua_pushinteger(L, level_difficulty()); lua_pushinteger(L, level_difficulty());
} } else {
else {
nhl_error(L, "level_difficulty should not have any args"); nhl_error(L, "level_difficulty should not have any args");
} }
return 1; return 1;
@@ -1188,7 +1191,8 @@ get_nh_lua_variables(void)
lua_getglobal(gl.luacore, "get_variables_string"); lua_getglobal(gl.luacore, "get_variables_string");
if (lua_type(gl.luacore, -1) == LUA_TFUNCTION) { if (lua_type(gl.luacore, -1) == LUA_TFUNCTION) {
if (nhl_pcall_handle(gl.luacore, 0, 1, "get_nh_lua_variables", NHLpa_impossible)) { if (nhl_pcall_handle(gl.luacore, 0, 1, "get_nh_lua_variables",
NHLpa_impossible)) {
return key; return key;
} }
key = dupstr(lua_tostring(gl.luacore, -1)); key = dupstr(lua_tostring(gl.luacore, -1));
@@ -1242,7 +1246,6 @@ nhl_stairways(lua_State *L)
lua_newtable(L); lua_newtable(L);
while (tmp) { while (tmp) {
lua_pushinteger(L, i); lua_pushinteger(L, i);
lua_newtable(L); lua_newtable(L);
@@ -1716,13 +1719,16 @@ nhl_push_anything(lua_State *L, int anytype, void *src)
anything any = cg.zeroany; anything any = cg.zeroany;
switch (anytype) { switch (anytype) {
case ANY_INT: any.a_int = *(int *) src; case ANY_INT:
any.a_int = *(int *) src;
lua_pushinteger(L, any.a_int); lua_pushinteger(L, any.a_int);
break; break;
case ANY_UCHAR: any.a_uchar = *(uchar *) src; case ANY_UCHAR:
any.a_uchar = *(uchar *) src;
lua_pushinteger(L, any.a_uchar); lua_pushinteger(L, any.a_uchar);
break; break;
case ANY_SCHAR: any.a_schar = *(schar *) src; case ANY_SCHAR:
any.a_schar = *(schar *) src;
lua_pushinteger(L, any.a_schar); lua_pushinteger(L, any.a_schar);
break; break;
} }
@@ -1892,7 +1898,8 @@ nhl_pcall(lua_State *L, int nargs, int nresults, const char *name)
if (setjmp(nud->jb)) { if (setjmp(nud->jb)) {
/* panic, because we don't know if the game state is corrupt */ /* panic, because we don't know if the game state is corrupt */
/* XXX can we get a lua stack trace as well? */ /* XXX can we get a lua stack trace as well? */
panic("Lua time exceeded %d:%s",nud->sid,nud->name?nud->name:"(unknown)"); panic("Lua time exceeded %d:%s", nud->sid,
nud->name ? nud->name : "(unknown)");
} }
} }
#endif #endif
@@ -1901,17 +1908,16 @@ nhl_pcall(lua_State *L, int nargs, int nresults, const char *name)
lua_remove(L, 1); /* remove handler */ lua_remove(L, 1); /* remove handler */
#ifdef NHL_SANDBOX #ifdef NHL_SANDBOX
if (nud && nud->perpcall && gl.loglua) { if (nud && nud->perpcall && gl.loglua) {
long ic = nud->statctr * NHL_SB_STEPSIZE; // an approximation long ic = nud->statctr * NHL_SB_STEPSIZE; // an approximation
livelog_printf(LL_DEBUG, "LUASTATS PCAL %d:%s %ld", livelog_printf(LL_DEBUG, "LUASTATS PCAL %d:%s %ld", nud->sid,
nud->sid,nud->name,ic); nud->name, ic);
} }
if (nud && nud->memlimit && gl.loglua) { if (nud && nud->memlimit && gl.loglua) {
lua_gc(L, LUA_GCCOLLECT); lua_gc(L, LUA_GCCOLLECT);
livelog_printf(LL_DEBUG, "LUASTATS PMEM %d:%s %lu", livelog_printf(LL_DEBUG, "LUASTATS PMEM %d:%s %lu", nud->sid,
nud->sid,nud->name,(long unsigned)nud->inuse); nud->name, (long unsigned) nud->inuse);
} }
#endif #endif
return rv; return rv;
@@ -1919,8 +1925,8 @@ nhl_pcall(lua_State *L, int nargs, int nresults, const char *name)
int int
nhl_pcall_handle(lua_State *L, int nargs, int nresults, const char *name, nhl_pcall_handle(lua_State *L, int nargs, int nresults, const char *name,
NHL_pcall_action npa NHL_pcall_action npa)
){ {
int rv = nhl_pcall(L, nargs, nresults, name); int rv = nhl_pcall(L, nargs, nresults, name);
if (rv) { if (rv) {
nhl_user_data *nud; nhl_user_data *nud;
@@ -1932,7 +1938,8 @@ nhl_pcall_handle(lua_State *L, int nargs, int nresults, const char *name,
nud->name ? nud->name : "(unknown)", lua_tostring(L, -1)); nud->name ? nud->name : "(unknown)", lua_tostring(L, -1));
case NHLpa_impossible: case NHLpa_impossible:
impossible("Lua error: %d:%s %s", nud->sid, impossible("Lua error: %d:%s %s", nud->sid,
nud->name?nud->name:"(unknown)", lua_tostring(L, -1)); nud->name ? nud->name : "(unknown)",
lua_tostring(L, -1));
} }
} }
return rv; return rv;
@@ -2029,8 +2036,8 @@ nhl_loadlua(lua_State *L, const char *fname)
llret = luaL_loadbuffer(L, buf, strlen(buf), altfname); llret = luaL_loadbuffer(L, buf, strlen(buf), altfname);
if (llret != LUA_OK) { if (llret != LUA_OK) {
impossible("luaL_loadbuffer: Error loading %s: %s", impossible("luaL_loadbuffer: Error loading %s: %s", altfname,
altfname, lua_tostring(L, -1)); lua_tostring(L, -1));
ret = FALSE; ret = FALSE;
goto give_up; goto give_up;
} else { } else {
@@ -2128,13 +2135,13 @@ nhl_done(lua_State *L)
if (gl.loglua) { if (gl.loglua) {
if (nud && nud->osteps) { if (nud && nud->osteps) {
long ic = nud->statctr * NHL_SB_STEPSIZE; // an approximation long ic = nud->statctr * NHL_SB_STEPSIZE; // an approximation
livelog_printf(LL_DEBUG, "LUASTATS DONE %d:%s %ld", livelog_printf(LL_DEBUG, "LUASTATS DONE %d:%s %ld", nud->sid,
nud->sid, nud->name,ic); nud->name, ic);
} }
if (nud && nud->memlimit && !nud->perpcall) { if (nud && nud->memlimit && !nud->perpcall) {
lua_gc(L, LUA_GCCOLLECT); lua_gc(L, LUA_GCCOLLECT);
livelog_printf(LL_DEBUG, "LUASTATS DMEM %d:%s %lu", livelog_printf(LL_DEBUG, "LUASTATS DMEM %d:%s %lu", nud->sid,
nud->sid, nud->name,(long unsigned)nud->inuse); nud->name, (long unsigned) nud->inuse);
} }
} }
if (nud) if (nud)
@@ -2171,7 +2178,8 @@ DISABLE_WARNING_CONDEXPR_IS_CONSTANT
const char * const char *
get_lua_version(void) get_lua_version(void)
{ {
nhl_sandbox_info sbi = {NHL_SB_VERSION, 1*1024*1024, 0, 1*1024*1024}; nhl_sandbox_info sbi = { NHL_SB_VERSION, 1 * 1024 * 1024, 0,
1 * 1024 * 1024 };
if (gl.lua_ver[0] == 0) { if (gl.lua_ver[0] == 0) {
lua_State *L = nhl_init(&sbi); lua_State *L = nhl_init(&sbi);
@@ -2419,7 +2427,8 @@ start_luapat(void)
return FALSE; return FALSE;
/* load a pattern matching function */ /* load a pattern matching function */
rv = luaL_loadstring(luapat, rv = luaL_loadstring(
luapat,
"function matches(s,p) return not not stringm.match(s,p) end"); "function matches(s,p) return not not stringm.match(s,p) end");
if (rv != LUA_OK) { if (rv != LUA_OK) {
panic("start_luapat: %d", rv); panic("start_luapat: %d", rv);
@@ -2828,7 +2837,8 @@ nhlL_newstate(nhl_sandbox_info *sbi, const char *name)
} }
lua_State *L = lua_newstate(nhl_alloc, nud); lua_State *L = lua_newstate(nhl_alloc, nud);
if(!L)panic("NULL lua_newstate"); if (!L)
panic("NULL lua_newstate");
lua_atpanic(L, nhl_panic); lua_atpanic(L, nhl_panic);
#if LUA_VERSION_NUM == 504 #if LUA_VERSION_NUM == 504