diff --git a/.gitignore b/.gitignore index 948a9ca8..f24bfded 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,8 @@ notes packages tags tests/utf8.dat +*.obj +cjson.lib +cjson.exp +cjson.dll +cjson.def diff --git a/CMakeLists.txt b/CMakeLists.txt index c17239b2..851b8f3e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -63,7 +63,7 @@ if(WIN32) set(_MODULE_LINK ${LUA_LIBRARY} ${_MODULE_LINK}) set(_lua_module_dir "${_lua_lib_dir}") # Windows sprintf()/strtod() handle NaN/inf differently. Not supported. - add_definitions(-DDISABLE_INVALID_NUMBERS) + add_definitions(-DDISABLE_INVALID_NUMBERS -DLUA_BUILD_AS_DLL -DLUA_LIB) else() set(_lua_module_dir "${_lua_lib_dir}/lua/5.1") endif() diff --git a/NEWS b/NEWS index 8927d6e5..0707dbba 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,6 @@ +Version 2.1.1 (Mar 31 2015) +* Build support for MSVC and luarocks install lua-cjson. (Xpol Wan ) + Version 2.1.0 (Mar 1 2012) * Added cjson.safe module interface which returns nil after an error * Improved Makefile compatibility with Solaris make diff --git a/fpconv.c b/fpconv.c index 3ecb8f71..14ab51ca 100644 --- a/fpconv.c +++ b/fpconv.c @@ -35,6 +35,12 @@ #include "fpconv.h" +/* Workaround for MSVC */ +#ifdef _MSC_VER +#define inline __inline +#define snprintf sprintf_s +#endif + /* Lua CJSON assumes the locale is the same for all threads within a * process and doesn't change after initialisation. * diff --git a/lua-cjson-2.1devel-1.rockspec b/lua-cjson-2.1.2-1.rockspec similarity index 89% rename from lua-cjson-2.1devel-1.rockspec rename to lua-cjson-2.1.2-1.rockspec index 154e333d..20226c8d 100644 --- a/lua-cjson-2.1devel-1.rockspec +++ b/lua-cjson-2.1.2-1.rockspec @@ -1,8 +1,9 @@ package = "lua-cjson" -version = "2.1devel-1" +version = "2.1.2-1" source = { - url = "http://www.kyne.com.au/~mark/software/download/lua-cjson-2.1devel.zip", + url = 'git://github.com/xpol/lua-cjson', + tag = '2.1.2', } description = { @@ -47,7 +48,9 @@ build = { -- Override default build options (per platform) platforms = { win32 = { modules = { cjson = { defines = { - "DISABLE_INVALID_NUMBERS" + "DISABLE_INVALID_NUMBERS", + "LUA_BUILD_AS_DLL", + "LUA_LIB" } } } } }, copy_directories = { "tests" } diff --git a/lua_cjson.c b/lua_cjson.c index 8f74a3d8..9b9d8e01 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -59,6 +59,12 @@ #define isinf(x) (!isnan(x) && isnan((x) - (x))) #endif +/* Workaround for MSVC */ +#ifdef _MSC_VER +#define snprintf sprintf_s +#define strncasecmp strnicmp +#endif + #define DEFAULT_SPARSE_CONVERT 0 #define DEFAULT_SPARSE_RATIO 2 #define DEFAULT_SPARSE_SAFE 10 @@ -461,9 +467,9 @@ static void json_encode_exception(lua_State *l, json_config_t *cfg, strbuf_t *js static void json_append_string(lua_State *l, strbuf_t *json, int lindex) { const char *escstr; + size_t i; const char *str; size_t len; - size_t i; str = lua_tolstring(l, lindex, &len); @@ -1407,7 +1413,7 @@ static int lua_cjson_safe_new(lua_State *l) return 1; } -int luaopen_cjson(lua_State *l) +LUALIB_API int luaopen_cjson(lua_State *l) { lua_cjson_new(l); @@ -1421,7 +1427,7 @@ int luaopen_cjson(lua_State *l) return 1; } -int luaopen_cjson_safe(lua_State *l) +LUALIB_API int luaopen_cjson_safe(lua_State *l) { lua_cjson_safe_new(l); diff --git a/strbuf.h b/strbuf.h index d861108c..7025c2d3 100644 --- a/strbuf.h +++ b/strbuf.h @@ -25,6 +25,10 @@ #include #include +#ifdef _MSC_VER +#define inline __inline +#endif + /* Size: Total bytes allocated to *buf * Length: String length, excluding optional NULL terminator. * Increment: Allocation increments when resizing the string buffer.