Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 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
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.1.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 .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
50 changes: 50 additions & 0 deletions .travis/setup_lua.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# A script for setting up environment for travis-ci testing.
# Sets up Lua and Luarocks.
# LUA must be "lua5.1", "lua5.2" or "luajit".
# PLATFORM must be "linux" or "macosx".

if [ "$LUA" == "luajit" ]; then
curl http://luajit.org/download/LuaJIT-2.0.2.tar.gz | tar xz
cd LuaJIT-2.0.2
make && sudo make install
cd $TRAVIS_BUILD_DIR;
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-work2.tar.gz | tar xz
cd lua-5.3.0-work2;
fi
sudo make $PLATFORM install
cd $TRAVIS_BUILD_DIR;
fi

LUAROCKS_BASE=luarocks-$LUAROCKS_VER
curl http://luarocks.org/releases/$LUAROCKS_BASE.tar.gz | tar xz
cd $LUAROCKS_BASE;

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

make && sudo make install

cd $TRAVIS_BUILD_DIR

rm -rf $LUAROCKS_BASE

if [ "$LUA" == "luajit" ]; then
rm -rf LuaJIT-2.0.2;
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-work2;
fi
37 changes: 37 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# 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()

set(CMAKE_C_FLAGS "-O2 -g -ggdb -Wall -pedantic -std=c99")
add_library(cmsgpack MODULE lua_cmsgpack.c)
set_target_properties(cmsgpack PROPERTIES PREFIX "")
target_link_libraries(cmsgpack ${_MODULE_LINK})
install(TARGETS cmsgpack DESTINATION "${_lua_module_dir}")

# vi:ai et sw=4 ts=4:
41 changes: 37 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,16 @@ 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

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