Skip to content

Incorporate all issues, add tests, add features, improve performance. #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 30 commits into from
Dec 5, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
4473a53
Fixed faulty implementation of table_is_an_array().
Jun 18, 2012
fd2f98c
Compensate for Lua telling us +-inf is an integer
Jun 18, 2012
dccf0fe
Added tests for +-inf to test.lua
Jun 18, 2012
48f338c
Add stream support
Jun 18, 2012
41e4e12
Correct 1-indexing and encode popping
Jun 18, 2012
ed6abff
Add cmsgpack.safe version
mattsta Apr 5, 2014
5308f7c
Remove noop stack setter
mattsta Apr 5, 2014
df39126
Update tests and add build infrastructure
mattsta Apr 5, 2014
155a6ba
Add better type checking when Lua 5.3 is available
mattsta Apr 5, 2014
cdb4e48
Cleanup: limit to 80 chars wide
mattsta Apr 5, 2014
507f353
Add fine-grained control of unpacking objects
mattsta Apr 6, 2014
6deb449
Use stack allocation for mp_cur
fperrad Nov 2, 2012
29c78ea
Add large pack test
mattsta Apr 6, 2014
e93d977
Unpack integers as integers instead of numbers
mattsta Apr 6, 2014
acb2f79
Add better testing for verifying serializations
mattsta Apr 6, 2014
4ca832b
Malloc one buffer per pack() instead of per arg
mattsta Apr 7, 2014
067a258
Use Lua memory allocator instead of malloc
mattsta Apr 7, 2014
72e64c2
Fix potential segfault
mattsta Apr 7, 2014
8692d79
Add tests to detect arrays with string keys
moteus Apr 11, 2014
351d38e
Fix array detection when keys are strings
moteus Apr 11, 2014
2820da3
Fix comment typos
dchest Apr 9, 2014
ef6b618
Fix Lua 5.2 compatability by using table.unpack
moteus Apr 14, 2014
4505263
Bump to version 0.4.0
mattsta Apr 7, 2014
17f2606
Add Travis CI
moteus May 23, 2014
31b260e
Allow LUACMSGPACK_MAX_NESTING to be set by CPP
moteus May 23, 2014
6078bbd
Add tests for more edge cases
mattsta May 26, 2014
9c85420
Allow forcing 32 bit builds on 64 bit platforms
mattsta Nov 24, 2014
587922d
Update CI to test against 5.3.0 beta
mattsta Nov 24, 2014
42f7a28
Fix 64 bit integer processing on 32 bit platforms
mattsta Nov 24, 2014
afbc009
5.3 compat: short functions to long functions
mattsta Nov 25, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@

*.o
*.so

build/
29 changes: 29 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
language: erlang

env:
global:
- PLATFORM=linux
- LUAROCKS_VER=2.2.0
matrix:
- LUA=lua5.1 LUA_SFX=
- LUA=lua5.2 LUA_SFX=
- LUA=luajit LUA_SFX=jit
- LUA=lua5.3 LUA_SFX=

before_install:
- bash -x .travis/setup_lua.sh
- sudo pip install cpp-coveralls

install:
- sudo luarocks make rockspec/lua-cmsgpack-scm-1.rockspec CFLAGS="-O2 -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="-shared --coverage"

script:
- lua$LUA_SFX test.lua

after_success:
- coveralls

notifications:
email:
on_success: change
on_failure: always
15 changes: 15 additions & 0 deletions .travis/platform.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
if [ -z "$PLATFORM" ]; then
PLATFORM=$TRAVIS_OS_NAME;
fi

if [ "$PLATFORM" == "osx" ]; then
PLATFORM="macosx";
fi

if [ -z "$PLATFORM" ]; then
if [ "$(uname)" == "Linux" ]; then
PLATFORM="linux";
else
PLATFORM="macosx";
fi;
fi
101 changes: 101 additions & 0 deletions .travis/setup_lua.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
#! /bin/bash

# A script for setting up environment for travis-ci testing.
# Sets up Lua and Luarocks.
# LUA must be "lua5.1", "lua5.2" or "luajit".
# luajit2.0 - master v2.0
# luajit2.1 - master v2.1

LUAJIT_BASE="LuaJIT-2.0.3"

source .travis/platform.sh

LUAJIT="no"

if [ "$PLATFORM" == "macosx" ]; then
if [ "$LUA" == "luajit" ]; then
LUAJIT="yes";
fi
if [ "$LUA" == "luajit2.0" ]; then
LUAJIT="yes";
fi
if [ "$LUA" == "luajit2.1" ]; then
LUAJIT="yes";
fi;
elif [ "$(expr substr $LUA 1 6)" == "luajit" ]; then
LUAJIT="yes";
fi

if [ "$LUAJIT" == "yes" ]; then

if [ "$LUA" == "luajit" ]; then
curl http://luajit.org/download/$LUAJIT_BASE.tar.gz | tar xz;
else
git clone http://luajit.org/git/luajit-2.0.git $LUAJIT_BASE;
fi

cd $LUAJIT_BASE

if [ "$LUA" == "luajit2.1" ]; then
git checkout v2.1;
fi

make && sudo make install

if [ "$LUA" == "luajit2.1" ]; then
sudo ln -s /usr/local/bin/luajit-2.1.0-alpha /usr/local/bin/luajit
sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua;
else
sudo ln -s /usr/local/bin/luajit /usr/local/bin/lua;
fi;

else
if [ "$LUA" == "lua5.1" ]; then
curl http://www.lua.org/ftp/lua-5.1.5.tar.gz | tar xz
cd lua-5.1.5;
elif [ "$LUA" == "lua5.2" ]; then
curl http://www.lua.org/ftp/lua-5.2.3.tar.gz | tar xz
cd lua-5.2.3;
elif [ "$LUA" == "lua5.3" ]; then
curl http://www.lua.org/work/lua-5.3.0-beta.tar.gz | tar xz
cd lua-5.3.0-beta;
fi
sudo make $PLATFORM install;
fi

cd $TRAVIS_BUILD_DIR;

LUAROCKS_BASE=luarocks-$LUAROCKS

# curl http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz

git clone https://github.com/keplerproject/luarocks.git $LUAROCKS_BASE
cd $LUAROCKS_BASE

git checkout v$LUAROCKS

if [ "$LUA" == "luajit" ]; then
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0;
elif [ "$LUA" == "luajit2.0" ]; then
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.0;
elif [ "$LUA" == "luajit2.1" ]; then
./configure --lua-suffix=jit --with-lua-include=/usr/local/include/luajit-2.1;
else
./configure;
fi

make build && sudo make install

cd $TRAVIS_BUILD_DIR

rm -rf $LUAROCKS_BASE

if [ "$LUAJIT" == "yes" ]; then
rm -rf $LUAJIT_BASE;
elif [ "$LUA" == "lua5.1" ]; then
rm -rf lua-5.1.5;
elif [ "$LUA" == "lua5.2" ]; then
rm -rf lua-5.2.3;
elif [ "$LUA" == "lua5.3" ]; then
rm -rf lua-5.3.0-beta;
fi
45 changes: 45 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# If Lua is installed in a non-standard location, please set the LUA_DIR
# environment variable to point to prefix for the install. Eg:
# Unix: export LUA_DIR=/home/user/pkg
# Windows: set LUA_DIR=c:\lua51

project(lua-cmsgpack C)
cmake_minimum_required(VERSION 2.6)

if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING
"Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel."
FORCE)
endif()

find_package(Lua51 REQUIRED)
include_directories(${LUA_INCLUDE_DIR})

if(APPLE)
set(CMAKE_SHARED_MODULE_CREATE_C_FLAGS
"${CMAKE_SHARED_MODULE_CREATE_C_FLAGS} -undefined dynamic_lookup")
endif()

if(WIN32)
# Win32 modules need to be linked to the Lua library.
set(_MODULE_LINK ${LUA_LIBRARY} ${_MODULE_LINK})
set(_lua_module_dir "${_lua_lib_dir}")
else()
set(_lua_module_dir "${_lua_lib_dir}/lua/5.1")
endif()

option(Build32Bit "Build 32-bit Library" OFF)

set(CMAKE_C_FLAGS "-O2 -g -ggdb -Wall -pedantic -std=c99")
add_library(cmsgpack MODULE lua_cmsgpack.c)
set_target_properties(cmsgpack PROPERTIES PREFIX "")

if(Build32Bit)
set_target_properties(cmsgpack
PROPERTIES COMPILE_FLAGS "-m32" LINK_FLAGS "-m32")
endif()

target_link_libraries(cmsgpack ${_MODULE_LINK})
install(TARGETS cmsgpack DESTINATION "${_lua_module_dir}")

# vi:ai et sw=4 ts=4:
48 changes: 44 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ README for lua-cmsgpack.c
===

Lua-cmsgpack is a [MessagePack](http://msgpack.org) implementation and bindings for
Lua 5.1/5.2 in a self contained C file without external dependencies.
Lua 5.1/5.2/5.3 in a self contained C file without external dependencies.

This library is open source software licensed under the BSD two-clause license.

Expand Down Expand Up @@ -33,10 +33,33 @@ interpreter:
USAGE
---

The exported API is very simple, consisting in two functions:
The exported API is very simple, consisting of four functions:

msgpack = cmsgpack.pack(lua_object)
lua_object = cmsgpack.unpack(msgpack)
Basic API:

msgpack = cmsgpack.pack(lua_object1, lua_object2, ..., lua_objectN)
lua_object1, lua_object2, ..., lua_objectN = cmsgpack.unpack(msgpack)

Detailed API giving you more control over unpacking multiple values:

resume_offset, lua_object1 = cmsgpack.unpack_one(msgpack)
resume_offset1, lua_object2 = cmsgpack.unpack_one(msgpack, resume_offset)
...
-1, lua_objectN = cmsgpack.unpack_one(msgpack, resume_offset_previous)

resume_offset, lua_object1, lua_object2 = cmsgpack.unpack_limit(msgpack, 2)
resume_offset2, lua_object3 = cmsgpack.unpack_limit(msgpack, 1, resume_offset1)

Functions:

- `pack(arg1, arg2, ..., argn)` - pack any number of lua objects into one msgpack stream. returns: msgpack
- `unpack(msgpack)` - unpack all objects in msgpack to individual return values. returns: object1, object2, ..., objectN
- `unpack_one(msgpack); unpack_one(msgpack, offset)` - unpacks the first object after offset. returns: offset, object
- `unpack_limit(msgpack, limit); unpack_limit(msgpack, limit, offset)` - unpacks the first `limit` objects and returns: offset, object1, objet2, ..., objectN (up to limit, but may return fewer than limit if not that many objects remain to be unpacked)

When you reach the end of your input stream with `unpack_one` or `unpack_limit`, an offset of `-1` is returned.

You may `require "msgpack"` or you may `require "msgpack.safe"`. The safe version returns errors as (nil, errstring).

However because of the nature of Lua numerical and table type a few behavior
of the library must be well understood to avoid problems:
Expand All @@ -50,6 +73,23 @@ maps.
* When a Lua number is converted to float or double, the former is preferred if there is no loss of precision compared to the double representation.
* When a MessagePack big integer (64 bit) is converted to a Lua number it is possible that the resulting number will not represent the original number but just an approximation. This is unavoidable because the Lua numerical type is usually a double precision floating point type.

TESTING
---

Build and test:

mkdir build; cd build
cmake ..
make
lua ../test.lua

You can build a 32-bit module on a 64-bit platform with:

mkdir build; cd build
cmake -DBuild32Bit=ON ..
make
lua ../test.lua

NESTED TABLES
---
Nested tables are handled correctly up to `LUACMSGPACK_MAX_NESTING` levels of
Expand Down
Loading