Skip to content

Commit 904b68b

Browse files
committed
rewrite client demo by lua, remove old C version client demo
1 parent 1e9a272 commit 904b68b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+11717
-12
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
*.o
22
*.a
33
skynet
4-
client
54
3rd/lua/lua
65
3rd/lua/luac
76
cservice

3rd/lua-cjson/CMakeLists.txt

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# If Lua is installed in a non-standard location, please set the LUA_DIR
2+
# environment variable to point to prefix for the install. Eg:
3+
# Unix: export LUA_DIR=/home/user/pkg
4+
# Windows: set LUA_DIR=c:\lua51
5+
6+
project(lua-cjson C)
7+
cmake_minimum_required(VERSION 2.6)
8+
9+
option(USE_INTERNAL_FPCONV "Use internal strtod() / g_fmt() code for performance")
10+
option(MULTIPLE_THREADS "Support multi-threaded apps with internal fpconv - recommended" ON)
11+
12+
if(NOT CMAKE_BUILD_TYPE)
13+
set(CMAKE_BUILD_TYPE Release CACHE STRING
14+
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
15+
FORCE)
16+
endif()
17+
18+
find_package(Lua51 REQUIRED)
19+
include_directories(${LUA_INCLUDE_DIR})
20+
21+
if(NOT USE_INTERNAL_FPCONV)
22+
# Use libc number conversion routines (strtod(), sprintf())
23+
set(FPCONV_SOURCES fpconv.c)
24+
else()
25+
# Use internal number conversion routines
26+
add_definitions(-DUSE_INTERNAL_FPCONV)
27+
set(FPCONV_SOURCES g_fmt.c dtoa.c)
28+
29+
include(TestBigEndian)
30+
TEST_BIG_ENDIAN(IEEE_BIG_ENDIAN)
31+
if(IEEE_BIG_ENDIAN)
32+
add_definitions(-DIEEE_BIG_ENDIAN)
33+
endif()
34+
35+
if(MULTIPLE_THREADS)
36+
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
37+
find_package(Threads REQUIRED)
38+
if(NOT CMAKE_USE_PTHREADS_INIT)
39+
message(FATAL_ERROR
40+
"Pthreads not found - required by MULTIPLE_THREADS option")
41+
endif()
42+
add_definitions(-DMULTIPLE_THREADS)
43+
endif()
44+
endif()
45+
46+
# Handle platforms missing isinf() macro (Eg, some Solaris systems).
47+
include(CheckSymbolExists)
48+
CHECK_SYMBOL_EXISTS(isinf math.h HAVE_ISINF)
49+
if(NOT HAVE_ISINF)
50+
add_definitions(-DUSE_INTERNAL_ISINF)
51+
endif()
52+
53+
set(_MODULE_LINK "${CMAKE_THREAD_LIBS_INIT}")
54+
get_filename_component(_lua_lib_dir ${LUA_LIBRARY} PATH)
55+
56+
if(APPLE)
57+
set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
58+
"${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -undefined dynamic_lookup")
59+
endif()
60+
61+
if(WIN32)
62+
# Win32 modules need to be linked to the Lua library.
63+
set(_MODULE_LINK ${LUA_LIBRARY} ${_MODULE_LINK})
64+
set(_lua_module_dir "${_lua_lib_dir}")
65+
# Windows sprintf()/strtod() handle NaN/inf differently. Not supported.
66+
add_definitions(-DDISABLE_INVALID_NUMBERS)
67+
else()
68+
set(_lua_module_dir "${_lua_lib_dir}/lua/5.1")
69+
endif()
70+
71+
add_library(cjson MODULE lua_cjson.c strbuf.c ${FPCONV_SOURCES})
72+
set_target_properties(cjson PROPERTIES PREFIX "")
73+
target_link_libraries(cjson ${_MODULE_LINK})
74+
install(TARGETS cjson DESTINATION "${_lua_module_dir}")
75+
76+
# vi:ai et sw=4 ts=4:

3rd/lua-cjson/LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
Copyright (c) 2010-2012 Mark Pulford <mark@kyne.com.au>
2+
3+
Permission is hereby granted, free of charge, to any person obtaining
4+
a copy of this software and associated documentation files (the
5+
"Software"), to deal in the Software without restriction, including
6+
without limitation the rights to use, copy, modify, merge, publish,
7+
distribute, sublicense, and/or sell copies of the Software, and to
8+
permit persons to whom the Software is furnished to do so, subject to
9+
the following conditions:
10+
11+
The above copyright notice and this permission notice shall be
12+
included in all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

3rd/lua-cjson/Makefile

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
##### Available defines for CJSON_CFLAGS #####
2+
##
3+
## USE_INTERNAL_ISINF: Workaround for Solaris platforms missing isinf().
4+
## DISABLE_INVALID_NUMBERS: Permanently disable invalid JSON numbers:
5+
## NaN, Infinity, hex.
6+
##
7+
## Optional built-in number conversion uses the following defines:
8+
## USE_INTERNAL_FPCONV: Use builtin strtod/dtoa for numeric conversions.
9+
## IEEE_BIG_ENDIAN: Required on big endian architectures.
10+
## MULTIPLE_THREADS: Must be set when Lua CJSON may be used in a
11+
## multi-threaded application. Requries _pthreads_.
12+
13+
##### Build defaults #####
14+
LUA_VERSION = 5.1
15+
TARGET = cjson.so
16+
PREFIX = /usr/local
17+
#CFLAGS = -g -Wall -pedantic -fno-inline
18+
CFLAGS = -O3 -Wall -pedantic -DNDEBUG
19+
CJSON_CFLAGS = -fpic
20+
CJSON_LDFLAGS = -shared
21+
LUA_INCLUDE_DIR = $(PREFIX)/include
22+
LUA_CMODULE_DIR = $(PREFIX)/lib/lua/$(LUA_VERSION)
23+
LUA_MODULE_DIR = $(PREFIX)/share/lua/$(LUA_VERSION)
24+
LUA_BIN_DIR = $(PREFIX)/bin
25+
26+
##### Platform overrides #####
27+
##
28+
## Tweak one of the platform sections below to suit your situation.
29+
##
30+
## See http://lua-users.org/wiki/BuildingModules for further platform
31+
## specific details.
32+
33+
## Linux
34+
35+
## FreeBSD
36+
#LUA_INCLUDE_DIR = $(PREFIX)/include/lua51
37+
38+
## MacOSX (Macports)
39+
#PREFIX = /opt/local
40+
#CJSON_LDFLAGS = -bundle -undefined dynamic_lookup
41+
42+
## Solaris
43+
#CC = gcc
44+
#CJSON_CFLAGS = -fpic -DUSE_INTERNAL_ISINF
45+
46+
## Windows (MinGW)
47+
#TARGET = cjson.dll
48+
#PREFIX = /home/user/opt
49+
#CJSON_CFLAGS = -DDISABLE_INVALID_NUMBERS
50+
#CJSON_LDFLAGS = -shared -L$(PREFIX)/lib -llua51
51+
#LUA_BIN_SUFFIX = .lua
52+
53+
##### Number conversion configuration #####
54+
55+
## Use Libc support for number conversion (default)
56+
FPCONV_OBJS = fpconv.o
57+
58+
## Use built in number conversion
59+
#FPCONV_OBJS = g_fmt.o dtoa.o
60+
#CJSON_CFLAGS += -DUSE_INTERNAL_FPCONV
61+
62+
## Compile built in number conversion for big endian architectures
63+
#CJSON_CFLAGS += -DIEEE_BIG_ENDIAN
64+
65+
## Compile built in number conversion to support multi-threaded
66+
## applications (recommended)
67+
#CJSON_CFLAGS += -pthread -DMULTIPLE_THREADS
68+
#CJSON_LDFLAGS += -pthread
69+
70+
##### End customisable sections #####
71+
72+
TEST_FILES = README bench.lua genutf8.pl test.lua octets-escaped.dat \
73+
example1.json example2.json example3.json example4.json \
74+
example5.json numbers.json rfc-example1.json \
75+
rfc-example2.json types.json
76+
DATAPERM = 644
77+
EXECPERM = 755
78+
79+
ASCIIDOC = asciidoc
80+
81+
BUILD_CFLAGS = -I$(LUA_INCLUDE_DIR) $(CJSON_CFLAGS)
82+
OBJS = lua_cjson.o strbuf.o $(FPCONV_OBJS)
83+
84+
.PHONY: all clean install install-extra doc
85+
86+
.SUFFIXES: .html .txt
87+
88+
.c.o:
89+
$(CC) -c $(CFLAGS) $(CPPFLAGS) $(BUILD_CFLAGS) -o $@ $<
90+
91+
.txt.html:
92+
$(ASCIIDOC) -n -a toc $<
93+
94+
all: $(TARGET)
95+
96+
doc: manual.html performance.html
97+
98+
$(TARGET): $(OBJS)
99+
$(CC) $(LDFLAGS) $(CJSON_LDFLAGS) -o $@ $(OBJS)
100+
101+
install: $(TARGET)
102+
mkdir -p $(DESTDIR)/$(LUA_CMODULE_DIR)
103+
cp $(TARGET) $(DESTDIR)/$(LUA_CMODULE_DIR)
104+
chmod $(EXECPERM) $(DESTDIR)/$(LUA_CMODULE_DIR)/$(TARGET)
105+
106+
install-extra:
107+
mkdir -p $(DESTDIR)/$(LUA_MODULE_DIR)/cjson/tests \
108+
$(DESTDIR)/$(LUA_BIN_DIR)
109+
cp lua/cjson/util.lua $(DESTDIR)/$(LUA_MODULE_DIR)/cjson
110+
chmod $(DATAPERM) $(DESTDIR)/$(LUA_MODULE_DIR)/cjson/util.lua
111+
cp lua/lua2json.lua $(DESTDIR)/$(LUA_BIN_DIR)/lua2json$(LUA_BIN_SUFFIX)
112+
chmod $(EXECPERM) $(DESTDIR)/$(LUA_BIN_DIR)/lua2json$(LUA_BIN_SUFFIX)
113+
cp lua/json2lua.lua $(DESTDIR)/$(LUA_BIN_DIR)/json2lua$(LUA_BIN_SUFFIX)
114+
chmod $(EXECPERM) $(DESTDIR)/$(LUA_BIN_DIR)/json2lua$(LUA_BIN_SUFFIX)
115+
cd tests; cp $(TEST_FILES) $(DESTDIR)/$(LUA_MODULE_DIR)/cjson/tests
116+
cd tests; chmod $(DATAPERM) $(TEST_FILES); chmod $(EXECPERM) *.lua *.pl
117+
118+
clean:
119+
rm -f *.o $(TARGET)

3rd/lua-cjson/NEWS

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
Version 2.1.0 (Mar 1 2012)
2+
* Added cjson.safe module interface which returns nil after an error
3+
* Improved Makefile compatibility with Solaris make
4+
5+
Version 2.0.0 (Jan 22 2012)
6+
* Improved platform compatibility for strtod/sprintf locale workaround
7+
* Added option to build with David Gay's dtoa.c for improved performance
8+
* Added support for Lua 5.2
9+
* Added option to encode infinity/NaN as JSON null
10+
* Fixed encode bug with a raised default limit and deeply nested tables
11+
* Updated Makefile for compatibility with non-GNU make implementations
12+
* Added CMake build support
13+
* Added HTML manual
14+
* Increased default nesting limit to 1000
15+
* Added support for re-entrant use of encode and decode
16+
* Added support for installing lua2json and json2lua utilities
17+
* Added encode_invalid_numbers() and decode_invalid_numbers()
18+
* Added decode_max_depth()
19+
* Removed registration of global cjson module table
20+
* Removed refuse_invalid_numbers()
21+
22+
Version 1.0.4 (Nov 30 2011)
23+
* Fixed numeric conversion under locales with a comma decimal separator
24+
25+
Version 1.0.3 (Sep 15 2011)
26+
* Fixed detection of objects with numeric string keys
27+
* Provided work around for missing isinf() on Solaris
28+
29+
Version 1.0.2 (May 30 2011)
30+
* Portability improvements for Windows
31+
- No longer links with -lm
32+
- Use "socket" instead of "posix" for sub-second timing
33+
* Removed UTF-8 test dependency on Perl Text::Iconv
34+
* Added simple CLI commands for testing Lua <-> JSON conversions
35+
* Added cjson.encode_number_precision()
36+
37+
Version 1.0.1 (May 10 2011)
38+
* Added build support for OSX
39+
* Removed unnecessary whitespace from JSON output
40+
* Added cjson.encode_keep_buffer()
41+
* Fixed memory leak on Lua stack overflow exception
42+
43+
Version 1.0 (May 9 2011)
44+
* Initial release

3rd/lua-cjson/THANKS

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
The following people have helped with bug reports, testing and/or
2+
suggestions:
3+
4+
- Louis-Philippe Perron (@loopole)
5+
- Ondřej Jirman
6+
- Steve Donovan <steve.j.donovan@gmail.com>
7+
- Zhang "agentzh" Yichun <agentzh@gmail.com>
8+
9+
Thanks!

0 commit comments

Comments
 (0)