Add in_lua flag
In preparation of making config errors available to lua scripts, instead outputting them via pline.
This commit is contained in:
@@ -1646,6 +1646,7 @@ extern int l_obj_register(lua_State *);
|
||||
|
||||
#if !defined(CROSSCOMPILE) || defined(CROSSCOMPILE_TARGET)
|
||||
extern lua_State * nhl_init(void);
|
||||
extern void nhl_done(lua_State *);
|
||||
extern boolean nhl_loadlua(lua_State *, const char *);
|
||||
extern boolean load_lua(const char *);
|
||||
extern void nhl_error(lua_State *, const char *) NORETURN;
|
||||
|
||||
@@ -174,6 +174,7 @@ struct instance_flags {
|
||||
* a structure of their own elsewhere some day.
|
||||
*/
|
||||
boolean debug_fuzzer; /* fuzz testing */
|
||||
boolean in_lua; /* executing a lua script */
|
||||
boolean defer_plname; /* X11 hack: askname() might not set g.plname */
|
||||
boolean herecmd_menu; /* use menu when mouseclick on yourself */
|
||||
boolean invis_goldsym; /* gold symbol is ' '? */
|
||||
|
||||
@@ -1175,7 +1175,7 @@ init_dungeons(void)
|
||||
so that it's hidden from '#wizwhere' feedback. */
|
||||
}
|
||||
|
||||
lua_close(L);
|
||||
nhl_done(L);
|
||||
|
||||
for (i = 0; i < pd.n_brs; i++) {
|
||||
free((genericptr_t) pd.tmpbranch[i].name);
|
||||
|
||||
@@ -259,7 +259,7 @@ free_luathemes(boolean keependgame) /* False: exiting, True: discarding main dun
|
||||
if (keependgame && i == astral_level.dnum)
|
||||
continue;
|
||||
if (g.luathemes[i]) {
|
||||
lua_close((lua_State *) g.luathemes[i]);
|
||||
nhl_done((lua_State *) g.luathemes[i]);
|
||||
g.luathemes[i] = (lua_State *) 0;
|
||||
}
|
||||
}
|
||||
@@ -277,7 +277,7 @@ makerooms(void)
|
||||
if ((themes = nhl_init()) != 0) {
|
||||
if (!nhl_loadlua(themes, fname)) {
|
||||
/* loading lua failed, don't use themed rooms */
|
||||
lua_close(themes);
|
||||
nhl_done(themes);
|
||||
themes = (lua_State *) 0;
|
||||
} else {
|
||||
/* success; save state for this dungeon branch */
|
||||
|
||||
12
src/nhlua.c
12
src/nhlua.c
@@ -1110,6 +1110,7 @@ nhl_init(void)
|
||||
{
|
||||
lua_State *L = luaL_newstate();
|
||||
|
||||
iflags.in_lua = TRUE;
|
||||
luaL_openlibs(L);
|
||||
nhl_set_package_path(L, "./?.lua");
|
||||
|
||||
@@ -1130,13 +1131,20 @@ nhl_init(void)
|
||||
l_obj_register(L);
|
||||
|
||||
if (!nhl_loadlua(L, "nhlib.lua")) {
|
||||
lua_close(L);
|
||||
nhl_done(L);
|
||||
return (lua_State *) 0;
|
||||
}
|
||||
|
||||
return L;
|
||||
}
|
||||
|
||||
void
|
||||
nhl_done(lua_State *L)
|
||||
{
|
||||
lua_close(L);
|
||||
iflags.in_lua = FALSE;
|
||||
}
|
||||
|
||||
boolean
|
||||
load_lua(const char *name)
|
||||
{
|
||||
@@ -1154,7 +1162,7 @@ load_lua(const char *name)
|
||||
}
|
||||
|
||||
give_up:
|
||||
lua_close(L);
|
||||
nhl_done(L);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -542,7 +542,7 @@ com_pager_core(const char *section, const char *msgid, boolean showerror)
|
||||
free((genericptr_t) synopsis);
|
||||
if (fallback_msgid)
|
||||
free((genericptr_t) fallback_msgid);
|
||||
lua_close(L);
|
||||
nhl_done(L);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user