From af3823beb0f846aed3a4f287e4f0f8a05f287ae5 Mon Sep 17 00:00:00 2001 From: "Ryan C. Gordon" Date: Tue, 18 Mar 2008 01:01:57 +0000 Subject: [PATCH] Fixes for Visual Studio. --- src/CMakeLists.txt | 12 ++++++------ src/toby_app.c | 14 +++++++++----- src/toby_app.h | 16 +++++++++++++++- 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 00437e0..ad0f7ea 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -44,10 +44,14 @@ ENDIF(MACOSX) IF(WINDOWS) ADD_DEFINITIONS(-DPLATFORM_WINDOWS=1) + SET(USES_WINMAIN WIN32) ENDIF(WINDOWS) IF(BEOS) ADD_DEFINITIONS(-DPLATFORM_BEOS=1) + # !!! FIXME: Workaround for lua issue on some platforms...fix this better. + ADD_DEFINITIONS(-D_setjmp=setjmp) + ADD_DEFINITIONS(-D_longjmp=longjmp) ENDIF(BEOS) IF(UNIX) @@ -59,10 +63,6 @@ IF(CMAKE_COMPILER_IS_GNUCC) ADD_DEFINITIONS(-g -pipe -Wall -Werror -fsigned-char) ENDIF(CMAKE_COMPILER_IS_GNUCC) -# !!! FIXME: Workaround for lua issue on some platforms...fix this better. -ADD_DEFINITIONS(-D_setjmp=setjmp) -ADD_DEFINITIONS(-D_longjmp=longjmp) - IF(MSVC) # VS.NET 8.0 got really really anal about strcpy, etc. ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS=1) @@ -156,12 +156,12 @@ ENDIF(UNIX AND NOT MACOSX) ADD_LIBRARY(tobybackend STATIC ${TOBY_SRCS} ${OPTIONAL_SRCS}) IF(TOBY_GUI_WXWIDGETS) - ADD_EXECUTABLE(toby toby_wxwidgets.cpp) + ADD_EXECUTABLE(toby ${USES_WINMAIN} toby_wxwidgets.cpp) TARGET_LINK_LIBRARIES(toby tobybackend ${OPTIONAL_LIBS} ${wxWidgets_LIBRARIES}) ENDIF(TOBY_GUI_WXWIDGETS) IF(TOBY_GUI_SDL) - ADD_EXECUTABLE(toby-sdl toby_sdl.c) + ADD_EXECUTABLE(toby-sdl ${USES_WINMAIN} toby_sdl.c) TARGET_LINK_LIBRARIES(toby-sdl tobybackend ${OPTIONAL_LIBS} ${SDL_LIBRARY}) ENDIF(TOBY_GUI_SDL) diff --git a/src/toby_app.c b/src/toby_app.c index 947e0e7..02c81d4 100644 --- a/src/toby_app.c +++ b/src/toby_app.c @@ -229,7 +229,7 @@ static int allocateTurtle(lua_State *L) ptr->pos.x = ptr->pos.y = N(500); /* center of turtlespace. */ ptr->width = ptr->height = N(20); - ptr->pen.r = ptr->pen.g = ptr->pen.b = N(255); /* white. */ + ptr->pen.r = ptr->pen.g = ptr->pen.b = 255; /* white. */ ptr->angle = 270; /* due north. */ ptr->penDown = 1; ptr->recalcPoints = 1; @@ -606,7 +606,7 @@ static int luahook_leftstring(lua_State *L) int charCount = checkWholeNum(L, 2); if (charCount < 0) throwError(L, "Negative string length"); - else if (charCount > origLen) + else if ( ((size_t) charCount) > origLen ) charCount = origLen; lua_pushlstring(L, str, charCount); @@ -621,7 +621,7 @@ static int luahook_rightstring(lua_State *L) int charCount = checkWholeNum(L, 2); if (charCount < 0) throwError(L, "Negative string length"); - else if (charCount > origLen) + else if ( ((size_t) charCount) > origLen) charCount = origLen; lua_pushstring(L, str + (origLen - charCount)); @@ -663,8 +663,8 @@ static int luahook_substring(lua_State *L) lua_pushstring(L, ""); else { - if (charCount > origLen) - charCount = origLen; + if ( ((size_t) charCount) > origLen) + charCount = (int) origLen; lua_pushlstring(L, str+pos, charCount); } /* else */ @@ -713,7 +713,11 @@ static int luahook_drawstring(lua_State *L) static int luahook_random(lua_State *L) { +#ifdef _MSC_VER + const long val = rand(); /* !!! FIXME: seed this. */ +#else const long val = random(); /* !!! FIXME: seed this. */ +#endif /* !!! FIXME: fixed point */ /* !!! FIXME: nasty double code. */ const lua_Number flt = (lua_Number) (((double)val) / ((double)RAND_MAX)); diff --git a/src/toby_app.h b/src/toby_app.h index 1b47443..49e1b09 100644 --- a/src/toby_app.h +++ b/src/toby_app.h @@ -17,7 +17,21 @@ extern "C" { #include "lauxlib.h" #include "lualib.h" -/* Try to handle platforms where lua_Number isn't a double. Whenever +#if (defined(_MSC_VER) && (!defined inline)) +#define inline __inline +#endif + +/* needed for alloca(). */ +#if defined(_MSC_VER) || defined(__MINGW32__) +#include +#endif + +#ifndef M_PI +#define M_PI (3.14159265358979323846) +#endif + +/* + * Try to handle platforms where lua_Number isn't a double. Whenever * specifying a numeric constant, try to use whole numbers, and wrap them * in N(), so that we don't have the compiler do an unnecessary implicit cast: *