diff --git a/polymer/eduke32/source/astub.c b/polymer/eduke32/source/astub.c index 83a557d3f..8967ad826 100644 --- a/polymer/eduke32/source/astub.c +++ b/polymer/eduke32/source/astub.c @@ -9552,7 +9552,7 @@ static int32_t registerosdcommands(void) #endif #ifdef LUNATIC - OSD_RegisterFunction("lua", "lua \"lua code...\": runs Lua code", osdcmd_lua); + OSD_RegisterFunction("lua", "lua \"Lua code...\": runs Lua code", osdcmd_lua); #endif // M32 script OSD_RegisterFunction("include", "include : compiles one or more M32 script files", osdcmd_include); diff --git a/polymer/eduke32/source/lunatic/lunatic_game.c b/polymer/eduke32/source/lunatic/lunatic_game.c index 231deb0ce..8dea746c3 100644 --- a/polymer/eduke32/source/lunatic/lunatic_game.c +++ b/polymer/eduke32/source/lunatic/lunatic_game.c @@ -194,6 +194,7 @@ finish: #define EL_MAXERRORS 20 static int32_t el_numErrors=0, el_tooMuchErrors; static char *el_errorMsgs[EL_MAXERRORS]; +int8_t el_addNewErrors = 1; // add new errors to display? // Compare against all other error messages. // Strictly seen, this is quadratic-time, but EL_MAXERRORS is small and @@ -209,7 +210,7 @@ static int32_t cmp_against_others(const char *str, int32_t slen) LUNATIC_EXTERN void El_OnError(const char *str) { - if (!el_tooMuchErrors) + if (el_addNewErrors && !el_tooMuchErrors) { char *errstr = NULL; const char *nl = Bstrchr(str, '\n'); diff --git a/polymer/eduke32/source/lunatic/lunatic_game.h b/polymer/eduke32/source/lunatic/lunatic_game.h index 354d94520..401ce1096 100644 --- a/polymer/eduke32/source/lunatic/lunatic_game.h +++ b/polymer/eduke32/source/lunatic/lunatic_game.h @@ -39,6 +39,7 @@ void El_DestroyState(L_State *estate); int32_t El_CallEvent(L_State *estate, int32_t eventidx, int32_t iActor, int32_t iPlayer, int32_t lDist, int32_t *iReturn); int32_t El_CallActor(L_State *estate, int32_t actortile, int32_t iActor, int32_t iPlayer, int32_t lDist); +extern int8_t el_addNewErrors; // add new errors to display? void El_OnError(const char *str); int32_t (*El_RestoreGamevars)(const char *savecode); diff --git a/polymer/eduke32/source/osdcmds.c b/polymer/eduke32/source/osdcmds.c index d1fafdaa1..ba72aed0a 100644 --- a/polymer/eduke32/source/osdcmds.c +++ b/polymer/eduke32/source/osdcmds.c @@ -39,6 +39,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include "enet/enet.h" +#ifdef LUNATIC +# include "lunatic_game.h" +#endif + extern int32_t voting, g_doQuickSave; struct osdcmd_cheatsinfo osdcmd_cheatsinfo_stat; float r_ambientlight = 1.0, r_ambientlightrecip = 1.0; @@ -612,6 +616,39 @@ static int32_t osdcmd_setactorvar(const osdfuncparm_t *parm) Gv_SetVar(i, varval, ID, -1); return OSDCMD_OK; } +#else +static int32_t osdcmd_lua(const osdfuncparm_t *parm) +{ + // Should be used like + // lua "lua code..." + // (the quotes making the whole string passed as one argument) + + int32_t ret; + + if (parm->numparms != 1) + return OSDCMD_SHOWHELP; + + if (!L_IsInitialized(&g_ElState)) + { + OSD_Printf("Lua state is not initialized.\n"); + return OSDCMD_OK; + } + + // TODO: "=" as shorthand for "print()", like in the + // stand-alone Lua interpreter? + // TODO: reserve some table to explicitly store stuff on the top level, for + // debugging convenience? + + // For the 'lua' OSD command, don't make errors appear on-screen: + el_addNewErrors = 0; + ret = L_RunString(&g_ElState, (char *)parm->parms[0], 0, -1, "console"); + el_addNewErrors = 1; + + if (ret != 0) + OSD_Printf("Error running the Lua code (error code %d)\n", ret); + + return OSDCMD_OK; +} #endif static int32_t osdcmd_addpath(const osdfuncparm_t *parm) @@ -1595,6 +1632,8 @@ int32_t registerosdcommands(void) OSD_RegisterFunction("setvar","setvar : sets the value of a gamevar", osdcmd_setvar); OSD_RegisterFunction("setvarvar","setvarvar : sets the value of to ", osdcmd_setvar); OSD_RegisterFunction("setactorvar","setactorvar : sets the value of 's to ", osdcmd_setactorvar); +#else + OSD_RegisterFunction("lua", "lua \"Lua code...\": runs Lunatic code", osdcmd_lua); #endif OSD_RegisterFunction("screenshot","screenshot: takes a screenshot. See r_scrcaptureformat.", osdcmd_screenshot);