From 842cce37b75f7c399216ee3e88f159885c5e1285 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 31 Jan 2014 21:13:03 +0000 Subject: [PATCH] Lunatic: Fix compilation of C++ build, but not starting up yet. BUILD_LUNATIC. git-svn-id: https://svn.eduke32.com/eduke32@4286 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/Makefile.common | 6 +++++ polymer/eduke32/build/include/lunatic.h | 12 ++++++++-- polymer/eduke32/build/src/lunatic.c | 10 +++++++- polymer/eduke32/source/game.c | 4 ++-- polymer/eduke32/source/gamevars.c | 5 +++- polymer/eduke32/source/gamevars.h | 4 ++-- polymer/eduke32/source/lunatic/lunatic_game.c | 23 ++++++++++++++++--- polymer/eduke32/source/lunatic/lunatic_game.h | 2 +- polymer/eduke32/source/savegame.c | 2 +- polymer/eduke32/source/savegame.h | 2 +- 10 files changed, 56 insertions(+), 14 deletions(-) diff --git a/polymer/eduke32/Makefile.common b/polymer/eduke32/Makefile.common index dce595e00..69d1e4800 100644 --- a/polymer/eduke32/Makefile.common +++ b/polymer/eduke32/Makefile.common @@ -470,6 +470,12 @@ ifneq ($(LUNATIC),0) # chains! override DISABLEINLINING=1 + ifneq ($(CPLUSPLUS),0) + # FIXME: Lunatic C++ doesn't build because otherwise it doesn't find + # INT32_MIN and the like. + BASECFLAGS+= -D__STDC_LIMIT_MACROS + endif + BASECOMMONFLAGS+= -I$(MAKEFILE_COMMON_DIR)/source/lunatic -DLUNATIC ifneq ($(USE_LUAJIT_2_1),0) BASECOMMONFLAGS+= -DUSE_LUAJIT_2_1 diff --git a/polymer/eduke32/build/include/lunatic.h b/polymer/eduke32/build/include/lunatic.h index dc415dbad..1b7fd3b7f 100644 --- a/polymer/eduke32/build/include/lunatic.h +++ b/polymer/eduke32/build/include/lunatic.h @@ -3,12 +3,20 @@ #ifndef ENGINE_LUNATIC_H_ #define ENGINE_LUNATIC_H_ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef USE_LUAJIT_2_1 # include #else # include #endif +#ifdef __cplusplus +} +#endif + typedef struct { @@ -25,9 +33,9 @@ void L_CheckAndRegisterFunction(lua_State *L, void *regkeyaddr); int L_HandleError(lua_State *L, int errcode, void (*ErrorPrintFunc)(const char *)); // Callback on Lua error. must be used immediately or strdup'd. -void (*L_ErrorFunc)(const char *str); +extern void (*L_ErrorFunc)(const char *str); // Out-of-memory handler, supposed to terminate the host program. -void (*L_OutOfMemFunc)(void); +extern void (*L_OutOfMemFunc)(void); int L_CreateState(L_State *estate, const char *name, void (*StateSetupFunc)(lua_State *)); void L_DestroyState(L_State *estate); diff --git a/polymer/eduke32/build/src/lunatic.c b/polymer/eduke32/build/src/lunatic.c index d5db75946..ecc5a09a8 100644 --- a/polymer/eduke32/build/src/lunatic.c +++ b/polymer/eduke32/build/src/lunatic.c @@ -1,5 +1,9 @@ /* The Lunatic Interpreter, part of EDuke32. Common, engine-side stuff. */ +#ifdef __cplusplus +extern "C" { +#endif + #ifdef USE_LUAJIT_2_1 # include # include @@ -10,6 +14,10 @@ # include #endif +#ifdef __cplusplus +} +#endif + #include "cache1d.h" #include "osd.h" @@ -66,7 +74,7 @@ static int32_t read_whole_file(const char *fn, char **retbufptr) if (flen == 0) return 5; - buf = Bmalloc(flen+1); + buf = (char *)Bmalloc(flen+1); if (!buf) { kclose(fid); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index f6e13f908..ab3547bff 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -9620,7 +9620,7 @@ static void G_CheckCommandLine(int32_t argc, const char **argv) #ifdef LUNATIC g_argv = argv; - g_elModules = Bcalloc(argc+1, sizeof(char *)); + g_elModules = (const char **)Bcalloc(argc+1, sizeof(char *)); Bassert(g_elModules); #endif ud.fta_on = 1; @@ -10727,7 +10727,7 @@ LUNATIC_EXTERN void El_SetCON(const char *conluacode) { int32_t slen = Bstrlen(conluacode); - g_elCON = Bmalloc(slen); + g_elCON = (char *)Bmalloc(slen); if (g_elCON == NULL) G_GameExit("OUT OF MEMORY in El_SetCON!"); diff --git a/polymer/eduke32/source/gamevars.c b/polymer/eduke32/source/gamevars.c index c45914519..1518092c4 100644 --- a/polymer/eduke32/source/gamevars.c +++ b/polymer/eduke32/source/gamevars.c @@ -29,7 +29,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define _gamevars_c_ -#if !defined LUNATIC +#ifdef LUNATIC +int32_t g_noResetVars; +LUNATIC_CB void (*A_ResetVars)(int32_t iActor); +#else # include "gamestructures.c" extern int32_t OSD_errors; diff --git a/polymer/eduke32/source/gamevars.h b/polymer/eduke32/source/gamevars.h index 7749c216e..49abaacc1 100644 --- a/polymer/eduke32/source/gamevars.h +++ b/polymer/eduke32/source/gamevars.h @@ -112,8 +112,8 @@ void Gv_ResetVars(void); int32_t Gv_ReadSave(int32_t fil,int32_t newbehav); void Gv_WriteSave(FILE *fil,int32_t newbehav); #else -int32_t g_noResetVars; -LUNATIC_CB void (*A_ResetVars)(int32_t iActor); +extern int32_t g_noResetVars; +extern LUNATIC_CB void (*A_ResetVars)(int32_t iActor); #endif void Gv_ResetSystemDefaults(void); diff --git a/polymer/eduke32/source/lunatic/lunatic_game.c b/polymer/eduke32/source/lunatic/lunatic_game.c index bc1fa89bf..8fcaa3544 100644 --- a/polymer/eduke32/source/lunatic/lunatic_game.c +++ b/polymer/eduke32/source/lunatic/lunatic_game.c @@ -5,6 +5,10 @@ #include #include // strerror +#ifdef __cplusplus +extern "C" { +#endif + #ifdef USE_LUAJIT_2_1 # include # include @@ -13,6 +17,10 @@ # include #endif +#ifdef __cplusplus +} +#endif + #include "build.h" // printext256 #include "lunatic_game.h" @@ -56,9 +64,18 @@ static uint8_t g_tweakTracebackMsg = 0; static int32_t SetEvent_CF(lua_State *L); static int32_t SetActor_CF(lua_State *L); + +#ifdef __cplusplus +extern "C" { +#endif + // in lpeg.o extern int luaopen_lpeg(lua_State *L); +#ifdef __cplusplus +} +#endif + typedef struct { uint32_t x, y, z, c; @@ -103,7 +120,7 @@ void El_PrintTimes(void) const int32_t baselen = Bstrlen(basefn); const int32_t addnlen = Bstrlen(".actors.csv"); // MUST equal that of ".events.csv" - char *fullfn = Bmalloc(baselen + addnlen + 1); + char *fullfn = (char *)Bmalloc(baselen + addnlen + 1); BFILE *outf; if (fullfn == NULL) @@ -252,7 +269,7 @@ LUNATIC_EXTERN void El_OnError(const char *str) // Otherwise, allocate storage for the potentially clipped error string... if (nl) { - errstr = Bmalloc(nl-str+1); + errstr = (char *)Bmalloc(nl-str+1); if (errstr) { Bmemcpy(errstr, str, nl-str); @@ -413,7 +430,7 @@ DEFINE_VOID_CFUNC(G_ShowView, LARG(1), LARG(2), LARG(3), LARG(4), LARG(5), LARG( #define CFUNC_REG(Name) { #Name, Name##_CF } -struct { const char *name; lua_CFunction func; } cfuncs[] = +static struct { const char *name; lua_CFunction func; } cfuncs[] = { CFUNC_REG(P_AddWeaponMaybeSwitchI), CFUNC_REG(P_CheckWeaponI), diff --git a/polymer/eduke32/source/lunatic/lunatic_game.h b/polymer/eduke32/source/lunatic/lunatic_game.h index 401ce1096..68fbd2bb3 100644 --- a/polymer/eduke32/source/lunatic/lunatic_game.h +++ b/polymer/eduke32/source/lunatic/lunatic_game.h @@ -42,7 +42,7 @@ int32_t El_CallActor(L_State *estate, int32_t actortile, int32_t iActor, int32_t extern int8_t el_addNewErrors; // add new errors to display? void El_OnError(const char *str); -int32_t (*El_RestoreGamevars)(const char *savecode); +extern int32_t (*El_RestoreGamevars)(const char *savecode); static inline int32_t El_HaveEvent(int32_t eventidx) { return g_elEvents[eventidx]!=0; } static inline int32_t El_HaveActor(int32_t actortile) { return g_elActors[actortile].haveit!=0; } diff --git a/polymer/eduke32/source/savegame.c b/polymer/eduke32/source/savegame.c index f21d1930f..0f11b3612 100644 --- a/polymer/eduke32/source/savegame.c +++ b/polymer/eduke32/source/savegame.c @@ -1796,7 +1796,7 @@ static int32_t El_ReadSaveCode(int32_t fil) if (slen > 0) { - char *svcode = Bmalloc(slen+1); + char *svcode = (char *)Bmalloc(slen+1); if (svcode == NULL) G_GameExit("OUT OF MEMORY in doloadplayer2()."); diff --git a/polymer/eduke32/source/savegame.h b/polymer/eduke32/source/savegame.h index eaf27f318..ed2a80d65 100644 --- a/polymer/eduke32/source/savegame.h +++ b/polymer/eduke32/source/savegame.h @@ -93,7 +93,7 @@ void G_Util_PtrToIdx(void *ptr, int32_t count, const void *base, int32_t mode); void G_Util_PtrToIdx2(void *ptr, int32_t count, size_t stride, const void *base, int32_t mode); #ifdef LUNATIC -const char *(*El_SerializeGamevars)(int32_t *slenptr, int32_t levelnum); +extern const char *(*El_SerializeGamevars)(int32_t *slenptr, int32_t levelnum); #endif #endif