aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Pulford <mark@kyne.com.au>2011-04-25 16:57:27 +0930
committerMark Pulford <mark@kyne.com.au>2011-04-25 16:57:27 +0930
commit06b42604a44f49e94bad277f87c9024b40a7e491 (patch)
treec48aabb4c1891af3f87cedb4e961954a2931df2a
parent3662f8b4e6f4335bd72e14f86e7237d74c595d02 (diff)
downloadlua-cjson-06b42604a44f49e94bad277f87c9024b40a7e491.tar.gz
lua-cjson-06b42604a44f49e94bad277f87c9024b40a7e491.tar.bz2
lua-cjson-06b42604a44f49e94bad277f87c9024b40a7e491.zip
Move global table init into lua_json
-rw-r--r--lua_json.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/lua_json.c b/lua_json.c
index 7dac1b4..1753e49 100644
--- a/lua_json.c
+++ b/lua_json.c
@@ -31,14 +31,17 @@
31#include <string.h> 31#include <string.h>
32#include <math.h> 32#include <math.h>
33 33
34#include <pthread.h>
35
34#include <lua.h> 36#include <lua.h>
35#include <lauxlib.h> 37#include <lauxlib.h>
36 38
37#include "lua_json.h" 39#include "lua_json.h"
38#include "lua_misc.h" 40#include "lua_misc.h"
39#include "utils.h"
40#include "strbuf.h" 41#include "strbuf.h"
41 42
43#include "die.h"
44
42/* ===== ENCODING ===== */ 45/* ===== ENCODING ===== */
43 46
44static void json_encode_exception(lua_State *l, strbuf_t *json, 47static void json_encode_exception(lua_State *l, strbuf_t *json,
@@ -342,7 +345,7 @@ static void json_process_value(lua_State *l, json_parse_t *json, json_token_t *t
342static json_token_type_t json_ch2token[256]; 345static json_token_type_t json_ch2token[256];
343static char json_ch2escape[256]; 346static char json_ch2escape[256];
344 347
345void lua_json_global_init() 348static void json_global_init()
346{ 349{
347 int i; 350 int i;
348 351
@@ -683,6 +686,8 @@ static int lua_api_json_decode(lua_State *l)
683 686
684/* ===== INITIALISATION ===== */ 687/* ===== INITIALISATION ===== */
685 688
689static pthread_once_t json_global_init_once = PTHREAD_ONCE_INIT;
690
686void lua_json_init(lua_State *l) 691void lua_json_init(lua_State *l)
687{ 692{
688 luaL_Reg reg[] = { 693 luaL_Reg reg[] = {
@@ -697,6 +702,8 @@ void lua_json_init(lua_State *l)
697 lua_pushlightuserdata(l, NULL); 702 lua_pushlightuserdata(l, NULL);
698 lua_setfield(l, -2, "null"); 703 lua_setfield(l, -2, "null");
699 lua_pop(l, 1); 704 lua_pop(l, 1);
705
706 SYS_NOFAIL(pthread_once(&json_global_init_once, json_global_init));
700} 707}
701 708
702/* vi:ai et sw=4 ts=4: 709/* vi:ai et sw=4 ts=4: