Fixes for Visual Studio.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 18 Mar 2008 01:01:57 +0000
changeset 496 68bd78c489b3
parent 495 16e08147c906
child 497 95e967fc2c03
Fixes for Visual Studio.
src/CMakeLists.txt
src/toby_app.c
src/toby_app.h
--- a/src/CMakeLists.txt	Mon Mar 17 23:16:52 2008 +0000
+++ b/src/CMakeLists.txt	Tue Mar 18 01:01:57 2008 +0000
@@ -44,10 +44,14 @@
 
 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 @@
     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 @@
 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)
 
--- a/src/toby_app.c	Mon Mar 17 23:16:52 2008 +0000
+++ b/src/toby_app.c	Tue Mar 18 01:01:57 2008 +0000
@@ -229,7 +229,7 @@
 
     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 @@
     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 @@
     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 @@
         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_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));
--- a/src/toby_app.h	Mon Mar 17 23:16:52 2008 +0000
+++ b/src/toby_app.h	Tue Mar 18 01:01:57 2008 +0000
@@ -17,7 +17,21 @@
 #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 <malloc.h>
+#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:
  *