Skip to content

Commit 4505263

Browse files
committed
Bump to version 0.4.0
Changes: - Improve table vs. array detection - Improve packing +-inf - Add multiple pack/unpack support - Add cmsgpack.safe module variant - Add local build infrastructure for easier testing - Add user-controlled unpack support limiting returned objects - Add Lua 5.3 compatibility - Remove an unnecessary malloc - Use Lua memory allocator instead of malloc for buffer creation Issues involved: - closes #16 - allow multi pack/unpack by default - closes #10 - unpack one/limit API added - closes #13 and closes #20 - use Lua allocator - closes #15 - (included in #16) - ignores #22 because it's confusing - closes #23 - fixed elsewhere - closes #26 - extracted some useful parts from a difficult commit - closes #28 - we started tagging versions again recently - closes #27 - that failure case works for me now - closes #31 - fix comment typos I merged commits with original author information where possible, but each commit required manual cleanup of one or more of: formatting fixes (no tabs, please), commit message fixes (more details please), extracting contents from a single 300 line commit with 5 different logical changes merged together, and general correctness checking after merging with newer code. As of this commit, all tests pass on Lua 5.1.5 and Lua 5.3-work2.
1 parent ef6b618 commit 4505263

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

README.md

+37-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ README for lua-cmsgpack.c
22
===
33

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

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

@@ -33,10 +33,33 @@ interpreter:
3333
USAGE
3434
---
3535

36-
The exported API is very simple, consisting in two functions:
36+
The exported API is very simple, consisting of four functions:
3737

38-
msgpack = cmsgpack.pack(lua_object)
39-
lua_object = cmsgpack.unpack(msgpack)
38+
Basic API:
39+
40+
msgpack = cmsgpack.pack(lua_object1, lua_object2, ..., lua_objectN)
41+
lua_object1, lua_object2, ..., lua_objectN = cmsgpack.unpack(msgpack)
42+
43+
Detailed API giving you more control over unpacking multiple values:
44+
45+
resume_offset, lua_object1 = cmsgpack.unpack_one(msgpack)
46+
resume_offset1, lua_object2 = cmsgpack.unpack_one(msgpack, resume_offset)
47+
...
48+
-1, lua_objectN = cmsgpack.unpack_one(msgpack, resume_offset_previous)
49+
50+
resume_offset, lua_object1, lua_object2 = cmsgpack.unpack_limit(msgpack, 2)
51+
resume_offset2, lua_object3 = cmsgpack.unpack_limit(msgpack, 1, resume_offset1)
52+
53+
Functions:
54+
55+
- `pack(arg1, arg2, ..., argn)` - pack any number of lua objects into one msgpack stream. returns: msgpack
56+
- `unpack(msgpack)` - unpack all objects in msgpack to individual return values. returns: object1, object2, ..., objectN
57+
- `unpack_one(msgpack); unpack_one(msgpack, offset)` - unpacks the first object after offset. returns: offset, object
58+
- `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)
59+
60+
When you reach the end of your input stream with `unpack_one` or `unpack_limit`, an offset of `-1` is returned.
61+
62+
You may `require "msgpack"` or you may `require "msgpack.safe"`. The safe version returns errors as (nil, errstring).
4063

4164
However because of the nature of Lua numerical and table type a few behavior
4265
of the library must be well understood to avoid problems:
@@ -50,6 +73,16 @@ maps.
5073
* 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.
5174
* 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.
5275

76+
TESTING
77+
---
78+
79+
Build and test:
80+
81+
mkdir build; cd build
82+
cmake ..
83+
make
84+
lua ../test.lua
85+
5386
NESTED TABLES
5487
---
5588
Nested tables are handled correctly up to `LUACMSGPACK_MAX_NESTING` levels of

lua_cmsgpack.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
#define LUACMSGPACK_NAME "cmsgpack"
1111
#define LUACMSGPACK_SAFE_NAME "cmsgpack_safe"
12-
#define LUACMSGPACK_VERSION "lua-cmsgpack 0.3.1"
12+
#define LUACMSGPACK_VERSION "lua-cmsgpack 0.4.0"
1313
#define LUACMSGPACK_COPYRIGHT "Copyright (C) 2012, Salvatore Sanfilippo"
1414
#define LUACMSGPACK_DESCRIPTION "MessagePack C implementation for Lua"
1515

@@ -53,6 +53,7 @@
5353
* 20-Feb-2012 (ver 0.2.1): Minor bug fixing.
5454
* 20-Feb-2012 (ver 0.3.0): Module renamed lua-cmsgpack (was lua-msgpack).
5555
* 04-Apr-2014 (ver 0.3.1): Lua 5.2 support and minor bug fix.
56+
* 07-Apr-2014 (ver 0.4.0): Multiple pack/unpack, lua allocator, efficiency.
5657
* ========================================================================== */
5758

5859
/* -------------------------- Endian conversion --------------------------------
+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package = "lua-cmsgpack"
2+
version = "0.4.0-0"
3+
source = {
4+
url = "git://github.com/antirez/lua-cmsgpack.git",
5+
tag = "0.4.0"
6+
}
7+
description = {
8+
summary = "MessagePack C implementation and bindings for Lua 5.1/5.2/5.3",
9+
homepage = "http://github.com/antirez/lua-cmsgpack",
10+
license = "Two-clause BSD",
11+
maintainer = "Salvatore Sanfilippo <[email protected]>"
12+
}
13+
dependencies = {
14+
"lua >= 5.1"
15+
}
16+
build = {
17+
type = "builtin",
18+
modules = {
19+
cmsgpack = {
20+
sources = {
21+
"lua_cmsgpack.c"
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)