Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes for Visual Studio.
  • Loading branch information
icculus committed Mar 18, 2008
1 parent 6f94ee7 commit af3823b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 12 deletions.
12 changes: 6 additions & 6 deletions src/CMakeLists.txt
Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
14 changes: 9 additions & 5 deletions src/toby_app.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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));
Expand Down Expand Up @@ -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 */

Expand Down Expand Up @@ -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));
Expand Down
16 changes: 15 additions & 1 deletion src/toby_app.h
Expand Up @@ -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 <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:
*
Expand Down

0 comments on commit af3823b

Please sign in to comment.