Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@ notes
packages
tags
tests/utf8.dat
*.obj
cjson.lib
cjson.exp
cjson.dll
cjson.def
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Version 2.1.1 (Mar 31 2015)
* Build support for MSVC and luarocks install lua-cjson. (Xpol Wan <xpolife@gmail.com>)

Version 2.1.0 (Mar 1 2012)
* Added cjson.safe module interface which returns nil after an error
* Improved Makefile compatibility with Solaris make
Expand Down
6 changes: 6 additions & 0 deletions fpconv.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
9 changes: 6 additions & 3 deletions lua-cjson-2.1devel-1.rockspec → lua-cjson-2.1.2-1.rockspec
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down Expand Up @@ -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" }
Expand Down
12 changes: 9 additions & 3 deletions lua_cjson.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand Down
4 changes: 4 additions & 0 deletions strbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
#include <stdlib.h>
#include <stdarg.h>

#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.
Expand Down