From 06b42604a44f49e94bad277f87c9024b40a7e491 Mon Sep 17 00:00:00 2001 From: Mark Pulford Date: Mon, 25 Apr 2011 16:57:27 +0930 Subject: Move global table init into lua_json --- lua_json.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'lua_json.c') 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 @@ #include #include +#include + #include #include #include "lua_json.h" #include "lua_misc.h" -#include "utils.h" #include "strbuf.h" +#include "die.h" + /* ===== ENCODING ===== */ static 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 static json_token_type_t json_ch2token[256]; static char json_ch2escape[256]; -void lua_json_global_init() +static void json_global_init() { int i; @@ -683,6 +686,8 @@ static int lua_api_json_decode(lua_State *l) /* ===== INITIALISATION ===== */ +static pthread_once_t json_global_init_once = PTHREAD_ONCE_INIT; + void lua_json_init(lua_State *l) { luaL_Reg reg[] = { @@ -697,6 +702,8 @@ void lua_json_init(lua_State *l) lua_pushlightuserdata(l, NULL); lua_setfield(l, -2, "null"); lua_pop(l, 1); + + SYS_NOFAIL(pthread_once(&json_global_init_once, json_global_init)); } /* vi:ai et sw=4 ts=4: -- cgit v1.2.3-55-g6feb