diff options
author | Mark Pulford <mark@kyne.com.au> | 2012-01-18 17:49:47 +0400 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2012-03-04 12:24:35 +0400 |
commit | 88bb249473db4e4923e4c27a8e3ece7a77e738ce (patch) | |
tree | 9c7d5d537fb539aca1f17b75c7296d1f6489de22 | |
parent | 1a5460be319ac29af31f201fbf9775340262ba9b (diff) |
Disable registration of cjson global variable
Disable registration of cjson module table global variable in the
default build. Automatically creating a variable in the global namespace
can cause issues for other software and is no longer recommended with
Lua.
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | lua_cjson.c | 9 | ||||
-rw-r--r-- | manual.txt | 4 | ||||
-rwxr-xr-x | tests/test.lua | 2 |
5 files changed, 9 insertions, 14 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3768fc4..c18381f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ project(lua-cjson C) cmake_minimum_required(VERSION 2.6) -option(DISABLE_CJSON_GLOBAL "Disable global registration of the 'cjson' module table") +option(ENABLE_CJSON_GLOBAL "Register cjson module table as a global variable - not recommended") option(USE_INTERNAL_DTOA "Use internal strtod() / dtoa code for performance") option(MULTIPLE_THREADS "Build internal dtoa with support for multi-threaded applications - recommended" ON) @@ -20,8 +20,8 @@ endif() find_package(Lua51 REQUIRED) include_directories(${LUA_INCLUDE_DIR}) -if(DISABLE_CJSON_GLOBAL) - add_definitions(-DDISABLE_CJSON_GLOBAL) +if(ENABLE_CJSON_GLOBAL) + add_definitions(-DENABLE_CJSON_GLOBAL) endif() if(NOT USE_INTERNAL_DTOA) @@ -1,7 +1,7 @@ ##### Available defines for CJSON_CFLAGS ##### ## ## USE_INTERNAL_ISINF: Workaround for Solaris platforms missing isinf(). -## DISABLE_CJSON_GLOBAL: Do not store module is "cjson" global. +## ENABLE_CJSON_GLOBAL: Register "cjson" module table as a global variable. ## DISABLE_INVALID_NUMBERS: Permanently disable invalid JSON numbers: ## NaN, Infinity, hex. ## diff --git a/lua_cjson.c b/lua_cjson.c index 0662414..118ca27 100644 --- a/lua_cjson.c +++ b/lua_cjson.c @@ -1382,13 +1382,8 @@ int luaopen_cjson(lua_State *l) { lua_cjson_new(l); -#if !defined(DISABLE_CJSON_GLOBAL) && (!defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502) - /* Register a global "cjson" table to maintain compatibility with earlier - * versions of Lua CJSON which used luaL_register() under Lua 5.1. - * - * From Lua 5.2 onwards, Lua CJSON does not automatically register a global - * table. - */ +#ifdef ENABLE_CJSON_GLOBAL + /* Register a global "cjson" table. */ lua_pushvalue(l, -1); lua_setglobal(l, CJSON_MODNAME); #endif @@ -113,9 +113,9 @@ Build Options (#define) ~~~~~~~~~~~~~~~~~~~~~~~ [horizontal] +ENABLE_CJSON_GLOBAL:: Register +cjson+ module table as a global + variable (not recommended). USE_INTERNAL_ISINF:: Workaround for Solaris platforms missing ++isinf++(3). -DISABLE_CJSON_GLOBAL:: Do not store module table in global "cjson" - variable. Redundant from Lua 5.2 onwards. DISABLE_INVALID_NUMBERS:: Recommended on platforms where ++strtod++(3) / ++sprintf++(3) are not POSIX compliant (Eg, Windows MinGW). Prevents +cjson.encode_invalid_numbers+ and +cjson.decode_invalid_numbers+ diff --git a/tests/test.lua b/tests/test.lua index 19fc1af..152579e 100755 --- a/tests/test.lua +++ b/tests/test.lua @@ -69,7 +69,7 @@ function load_testdata() local big = {} for i = 1, 1100 do - big = { { 10, false, true, cjson.null }, "string", a = big } + big = { { 10, false, true, json.null }, "string", a = big } end data.deeply_nested_data = big |