From 2baf403afe04b523df2ea018e7de1d5ee1ad57cf Mon Sep 17 00:00:00 2001 From: xpol Date: Fri, 8 Nov 2013 13:27:15 +0800 Subject: [PATCH 1/4] Make compile under msvc. --- fpconv.c | 6 ++++++ fpconv.h | 2 +- lua_cjson.c | 8 +++++++- strbuf.h | 4 ++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/fpconv.c b/fpconv.c index 79908317..de29b3c6 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/fpconv.h b/fpconv.h index 01249088..7b0d0ee3 100644 --- a/fpconv.h +++ b/fpconv.h @@ -12,7 +12,7 @@ static inline void fpconv_init() /* Do nothing - not required */ } #else -extern inline void fpconv_init(); +extern void fpconv_init(); #endif extern int fpconv_g_fmt(char*, double, int); diff --git a/lua_cjson.c b/lua_cjson.c index c14a1c5c..a4bc8027 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,7 +467,7 @@ 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; - int i; + size_t i; const char *str; size_t len; 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. From 1744279cfffad643831013fa7f91698e3685dac9 Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Tue, 31 Mar 2015 16:06:09 +0800 Subject: [PATCH 2/4] build support for msvc and luarocks under windows. --- NEWS | 3 +++ lua-cjson-2.1devel-1.rockspec => lua-cjson-2.1.1-1.rockspec | 5 +++-- 2 files changed, 6 insertions(+), 2 deletions(-) rename lua-cjson-2.1devel-1.rockspec => lua-cjson-2.1.1-1.rockspec (93%) 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/lua-cjson-2.1devel-1.rockspec b/lua-cjson-2.1.1-1.rockspec similarity index 93% rename from lua-cjson-2.1devel-1.rockspec rename to lua-cjson-2.1.1-1.rockspec index 154e333d..311b8495 100644 --- a/lua-cjson-2.1devel-1.rockspec +++ b/lua-cjson-2.1.1-1.rockspec @@ -1,8 +1,9 @@ package = "lua-cjson" -version = "2.1devel-1" +version = "2.1.1-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.1', } description = { From f1912f573e0948b6be11773de659ace96deecdbc Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Mon, 22 Aug 2016 11:17:02 +0800 Subject: [PATCH 3/4] Fixes windows build that cjson.safe not exported. --- .gitignore | 5 +++++ CMakeLists.txt | 2 +- lua-cjson-2.1.1-1.rockspec | 4 +++- lua_cjson.c | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) 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/lua-cjson-2.1.1-1.rockspec b/lua-cjson-2.1.1-1.rockspec index 311b8495..62a5cde7 100644 --- a/lua-cjson-2.1.1-1.rockspec +++ b/lua-cjson-2.1.1-1.rockspec @@ -48,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 a4bc8027..19de7bc0 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -1413,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); @@ -1427,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); From b690bec81693c58f2efa9b09e247ce5b45d39b86 Mon Sep 17 00:00:00 2001 From: Xpol Wan Date: Mon, 22 Aug 2016 11:28:46 +0800 Subject: [PATCH 4/4] Prepare release of 2.1.2. --- lua-cjson-2.1.1-1.rockspec => lua-cjson-2.1.2-1.rockspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) rename lua-cjson-2.1.1-1.rockspec => lua-cjson-2.1.2-1.rockspec (97%) diff --git a/lua-cjson-2.1.1-1.rockspec b/lua-cjson-2.1.2-1.rockspec similarity index 97% rename from lua-cjson-2.1.1-1.rockspec rename to lua-cjson-2.1.2-1.rockspec index 62a5cde7..20226c8d 100644 --- a/lua-cjson-2.1.1-1.rockspec +++ b/lua-cjson-2.1.2-1.rockspec @@ -1,9 +1,9 @@ package = "lua-cjson" -version = "2.1.1-1" +version = "2.1.2-1" source = { url = 'git://github.com/xpol/lua-cjson', - tag = '2.1.1', + tag = '2.1.2', } description = {