diff options
| author | Mark Pulford <mark@kyne.com.au> | 2011-04-25 16:57:27 +0930 |
|---|---|---|
| committer | Mark Pulford <mark@kyne.com.au> | 2011-04-25 16:57:27 +0930 |
| commit | 06b42604a44f49e94bad277f87c9024b40a7e491 (patch) | |
| tree | c48aabb4c1891af3f87cedb4e961954a2931df2a | |
| parent | 3662f8b4e6f4335bd72e14f86e7237d74c595d02 (diff) | |
| download | lua-cjson-06b42604a44f49e94bad277f87c9024b40a7e491.tar.gz lua-cjson-06b42604a44f49e94bad277f87c9024b40a7e491.tar.bz2 lua-cjson-06b42604a44f49e94bad277f87c9024b40a7e491.zip | |
Move global table init into lua_json
Diffstat (limited to '')
| -rw-r--r-- | lua_json.c | 11 |
1 files changed, 9 insertions, 2 deletions
| @@ -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 | ||
| 44 | static void json_encode_exception(lua_State *l, strbuf_t *json, | 47 | 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 | |||
| 342 | static json_token_type_t json_ch2token[256]; | 345 | static json_token_type_t json_ch2token[256]; |
| 343 | static char json_ch2escape[256]; | 346 | static char json_ch2escape[256]; |
| 344 | 347 | ||
| 345 | void lua_json_global_init() | 348 | static 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 | ||
| 689 | static pthread_once_t json_global_init_once = PTHREAD_ONCE_INIT; | ||
| 690 | |||
| 686 | void lua_json_init(lua_State *l) | 691 | void 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: |
