Skip to content

Commit

Permalink
add ci scripts.
Browse files Browse the repository at this point in the history
  • Loading branch information
starwing committed Jan 24, 2018
1 parent 5efe9f7 commit c5732d6
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 4 deletions.
43 changes: 43 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
language: c
sudo: false

env:
global:
- LUAROCKS=2.4.3
- ROCKSPEC=rockspecs/lua-protobuf-scm-1.rockspec
matrix:
- LUA="lua 5.1"
- LUA="lua 5.2"
- LUA="lua 5.3"
- LUA="luajit 2.0"
- LUA="luajit 2.1"

branches:
only:
- master
- new

before_install:
- pip install --user hererocks urllib3[secure] cpp-coveralls
- hererocks env --$LUA -rlatest # Use latest LuaRocks, install into 'env' directory.
- source env/bin/activate # Add directory with all installed binaries to PATH.

install:
# - sudo luarocks make $ROCKSPEC CFLAGS="-O2 -fPIC -ftest-coverage -fprofile-arcs" LIBFLAG="-shared --coverage"
- luarocks make $ROCKSPEC CFLAGS="-O3 -fPIC -Wall -Wextra --coverage" LIBFLAG="-shared --coverage"

script:
- lua test.lua
# - lunit.sh test.lua

after_success:
- coveralls
# - coveralls -b .. -r .. --dump c.report.json
# - luacov-coveralls -j c.report.json -v

notifications:
email:
on_success: change
on_failure: always

# vim: ft=yaml nu et sw=2 fdc=2 fdm=syntax
15 changes: 12 additions & 3 deletions pb.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

# define LUA_OK 0
# define lua_rawlen lua_objlen
# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))
# define luaL_setfuncs(L,l,n) (assert(n==0), luaL_register(L,NULL,l))
# define luaL_setmetatable(L, name) \
(luaL_getmetatable((L), (name)), lua_setmetatable(L, -2))
Expand All @@ -49,12 +48,22 @@ void lua_rawsetp(lua_State *L, int idx, const void *p) {
lua_rawset(L, relindex(idx, 1));
}

#ifndef luaL_newlib /* not LuaJIT 2.1 */
#define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l))

static lua_Integer lua_tointegerx(lua_State *L, int idx, int *isint) {
lua_Integer i = lua_tointeger(L, idx);
if (isint) *isint = (i != 0 || lua_type(L, idx) == LUA_TNUMBER);
return i;
}

static lua_Number lua_tonumberx(lua_State *L, int idx, int *isnum) {
lua_Number i = lua_tonumber(L, idx);
if (isnum) *isnum = (i != 0 || lua_type(L, idx) == LUA_TNUMBER);
return i;
}
#endif

#ifdef LUAI_BITSINT /* not LuaJIT */
#include <errno.h>
static int luaL_fileresult(lua_State *L, int stat, const char *fname) {
Expand Down Expand Up @@ -834,7 +843,7 @@ static int Lslice_enter(lua_State *L) {
pb_SliceExt view;
if (lua_isnoneornil(L, 2)) {
if (pb_readbytes(&s->curr.base, &view.base) == 0)
argerror(L, 1, "bytes wireformat expected at offset %d",
return argerror(L, 1, "bytes wireformat expected at offset %d",
lpb_offset(&s->curr));
view.head = view.base.p;
lpb_enterview(L, s, view);
Expand Down Expand Up @@ -1412,7 +1421,7 @@ LUALIB_API int luaopen_pb(lua_State *L) {
return 1;
}

/* cc: flags+='-ggdb -pedantic -std=c90 -Wall -Wextra --coverage'
/* cc: flags+='-O3 -ggdb -pedantic -std=c90 -Wall -Wextra --coverage'
* maccc: flags+='-shared -undefined dynamic_lookup' output='pb.so'
* win32cc: flags+='-mdll -DLUA_BUILD_AS_DLL ' output='pb.dll' libs+='-llua53' */

27 changes: 27 additions & 0 deletions rockspecs/lua-protobuf-scm-1.rockspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package = "lua-protobuf"
version = "scm-1"

source = {
url = "git://github.com/starwing/lua-protobuf.git",
}

description = {
summary = "protobuf data support for Lua",
detailed = [[
This project offers a simple C library for basic protobuf wire format encode/decode.
]],
homepage = "https://github.com/starwing/lua-protobuf",
license = "MIT",
}

dependencies = {
"lua >= 5.1"
}

build = {
type = "builtin",
modules = {
pb = "pb.c";
protoc = "protoc.lua";
}
}
4 changes: 3 additions & 1 deletion test.lua
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,9 @@ end
function _G.test_buffer()
eq(buffer.pack("vvv", 1,2,3), "\1\2\3")
eq(buffer.tohex(pb.pack("d", 4294967295)), "FF FF FF FF")
eq(buffer.tohex(pb.pack("q", 9223372036854775807)), "FF FF FF FF FF FF FF 7F")
if _VERSION == "Lua 5.3" then
eq(buffer.tohex(pb.pack("q", 9223372036854775807)), "FF FF FF FF FF FF FF 7F")
end
eq(pb.pack("s", "foo"), "\3foo")
eq(pb.pack("cc", "foo", "bar"), "foobar")
eq(buffer():pack("vvv", 1,2,3):result(), "\1\2\3")
Expand Down

0 comments on commit c5732d6

Please sign in to comment.