Skip to content

Commit

Permalink
Merge branch 'master' of ssh://github.com/moai/luamongo
Browse files Browse the repository at this point in the history
  • Loading branch information
pakozm committed Apr 26, 2015
2 parents 03184a3 + 7d3a57b commit ba33091
Show file tree
Hide file tree
Showing 18 changed files with 213 additions and 160 deletions.
22 changes: 22 additions & 0 deletions LICENSE
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2014-2015 Francisco Zamora-Martinez (pakozm@gmail.com)
Copyright (c) 2009-2015 Zipline Games, Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
104 changes: 90 additions & 14 deletions Makefile
@@ -1,30 +1,106 @@
UNAME:= $(shell uname)
PLAT= DetectOS

CC= g++
CFLAGS= -Wall -g -O2 -shared -fPIC -I/usr/include/mongo `pkg-config --cflags lua5.2` `pkg-config --cflags libmongo-client`
LUAFLAGS= $(shell pkg-config --cflags $(LUAPKG))
LUAPKG:= $(shell ( luajit -e 'print("luajit")' 2> /dev/null ) || lua5.2 -e 'print("lua5.2")' 2> /dev/null || lua5.1 -e 'print("lua5.1")' 2> /dev/null || lua -e 'print("lua" .. string.match(_VERSION, "%d+.%d+"))' 2> /dev/null)
AR= ar rcu
RANLIB= ranlib
RM= rm -f
LIBS=`pkg-config --libs lua5.2` -lmongoclient -lssl -lboost_thread -lboost_filesystem
OUTLIB=mongo.so
OUTLIB= mongo.so
OBJS = main.o mongo_bsontypes.o mongo_dbclient.o mongo_replicaset.o mongo_connection.o mongo_cursor.o mongo_gridfile.o mongo_gridfs.o mongo_gridfschunk.o mongo_query.o utils.o mongo_cxx_extension.o mongo_gridfilebuilder.o

LDFLAGS= $(LIBS)
# macports
ifneq ("$(wildcard /opt/local/include/mongo/client/dbclient.h)","")
LUA:= $(shell echo $(LUAPKG) | sed 's/[0-9].[0-9]//g')
VER:= $(shell echo $(LUAPKG) | sed 's/.*\([0-9].[0-9]\)/\1/g')
LUAFLAGS:= $(shell pkg-config --cflags '$(LUA) >= $(VER)')
MONGO_INCLUDE_DIR= /opt/local/include/mongo/
MONGO_LIB_DIR= /opt/local/lib
CFLAGS:= -Wall -g -O2 -fPIC $(LUAFLAGS) -I$(MONGO_INCLUDE_DIR)
LIBS:= $(shell pkg-config --libs "$(LUA) >= $(VER)") -lmongoclient -lssl -lboost_thread-mt -lboost_filesystem-mt -flat_namespace -bundle -L$(MONGO_LIB_DIR) -rdynamic
endif

OBJS = main.o mongo_bsontypes.o mongo_dbclient.o mongo_replicaset.o mongo_connection.o mongo_cursor.o mongo_gridfile.o mongo_gridfs.o mongo_gridfschunk.o mongo_query.o utils.o mongo_cxx_extension.o mongo_gridfilebuilder.o
# homebrew
ifneq ("$(wildcard /usr/local/include/mongo/client/dbclient.h)","")
LUA:= $(shell echo $(LUAPKG) | sed 's/[0-9].[0-9]//g')
VER:= $(shell echo $(LUAPKG) | sed 's/.*\([0-9].[0-9]\)/\1/g')
LUAFLAGS:= $(shell pkg-config --cflags '$(LUA) >= $(VER)')
MONGO_INCLUDE_DIR= /usr/local/include/mongo/
MONGO_LIB_DIR= /usr/local/lib
CFLAGS:= -Wall -g -O2 -fPIC $(LUAFLAGS) -I$(MONGO_INCLUDE_DIR)
LIBS:= $(shell pkg-config --libs "$(LUA) >= $(VER)") -lmongoclient -lssl -lboost_thread-mt -lboost_filesystem-mt -flat_namespace -bundle -L$(MONGO_LIB_DIR) -rdynamic
endif

UNAME = `uname`
PLAT = DetectOS
ifeq ("$(LIBS)", "")
MONGOFLAGS:= $(shell pkg-config --cflags libmongo-client)
CFLAGS:= -Wall -g -O2 -shared -fPIC -I/usr/include/mongo $(LUAFLAGS) $(MONGOFLAGS)
LIBS:= $(shell pkg-config --libs $(LUAPKG)) -lmongoclient -lssl -lboost_thread -lboost_filesystem -lrt
endif

all: $(PLAT)
LDFLAGS:= $(LIBS)

DetectOS:
all: check $(PLAT)

DetectOS: check
@make $(UNAME)

Linux:
@make -f Makefile.linux
Linux: luamongo

Darwin: checkdarwin luamongo

check:
@if [ -z $(LUAPKG) ]; then echo "Impossible to detect Lua version, you need LuaJIT, Lua 5.1 or Lua 5.2 installed!"; exit 1; fi
@if [ -z $(LUAFLAGS) ]; then echo "Unable to configure with pkg-config, luamongo needs developer version of $(LUAPKG). You can force other Lua version by declaring variable LUAPKG=lua5.1 or LUAPKG=lua5.2"; exit 1; fi

Darwin:
@make -f Makefile.darwin
checkdarwin:
ifeq ("$(MONGO_LIB_DIR)", "")
@echo "To build luamongo on Darwin, you must have either ports or homebrew (preferred) installed!"
exit 1
endif

echo: check
@echo "CC = $(CC)"
@echo "CFLAGS = $(CFLAGS)"
@echo "AR = $(AR)"
@echo "RANLIB = $(RANLIB)"
@echo "RM = $(RM)"
@echo "LDFLAGS = $(LDFLAGS)"

clean:
$(RM) $(OBJS) $(OUTLIB)

.PHONY: all
############################################################################~


luamongo: $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(OUTLIB) $(LDFLAGS)

main.o: main.cpp utils.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_dbclient.o: mongo_dbclient.cpp common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_connection.o: mongo_connection.cpp common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_cursor.o: mongo_cursor.cpp common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_gridfile.o: mongo_gridfile.cpp common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_gridfs.o: mongo_gridfs.cpp common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_gridfschunk.o: mongo_gridfschunk.cpp common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_query.o: mongo_query.cpp common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_replicaset.o: mongo_replicaset.cpp common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_bsontypes.o: mongo_bsontypes.cpp common.h
$(CC) -c -o $@ $< $(CFLAGS)
utils.o: utils.cpp common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_cxx_extension.o: mongo_cxx_extension.cpp mongo_cxx_extension.h
$(CC) -c -o $@ $< $(CFLAGS)
mongo_gridfilebuilder.o: mongo_gridfilebuilder.cpp mongo_cxx_extension.h common.h utils.h
$(CC) -c -o $@ $< $(CFLAGS)

.PHONY: all check checkdarwin clean DetectOS Linux Darwin echo
78 changes: 0 additions & 78 deletions Makefile.darwin

This file was deleted.

56 changes: 0 additions & 56 deletions Makefile.linux

This file was deleted.

24 changes: 24 additions & 0 deletions README.md
@@ -1,5 +1,29 @@
# A Lua driver for mongodb

## Compilation

The makefile automatically detects which platform and Lua version are you
using, so for compilation you just need to do:

```
$ make
```

You can force the platform compilation by using `$ make Linux` or `$ make Darwin`.
Additionally, you can force the Lua version by doing:

```
$ make LUAPKG=lua5.2
```

where `lua5.2` can be replaced by `lua5.1` and `luajit`.


## Installation

Copy the library file `mongo.so` to any of the paths in LUA_CPATH environment
variable or Lua string `package.path`.

## Wiki Documentation

* <a href="https://github.com/moai/luamongo/wiki/Bsontypes">BsonTypes</a>
Expand Down
14 changes: 13 additions & 1 deletion common.h
Expand Up @@ -4,6 +4,18 @@
#define LUAMONGO_VERSION_STRING "_VERSION"

#define LUAMONGO_ROOT "mongo"
#if LUA_VERSION_NUM < 502
#define LUAMONGO_CONNECTION "mongo.Connection"
#define LUAMONGO_REPLICASET "mongo.ReplicaSet"
#define LUAMONGO_CURSOR "mongo.Cursor"
#define LUAMONGO_QUERY "mongo.Query"
#define LUAMONGO_GRIDFS "mongo.GridFS"
#define LUAMONGO_GRIDFILE "mongo.GridFile"
#define LUAMONGO_GRIDFSCHUNK "mongo.GridFSChunk"
#define LUAMONGO_GRIDFILEBUILDER "mongo.GridFileBuilder"
// not an actual class, pseudo-base for error messages
#define LUAMONGO_DBCLIENT "mongo.DBClient"
#else
#define LUAMONGO_CONNECTION "Connection"
#define LUAMONGO_REPLICASET "ReplicaSet"
#define LUAMONGO_CURSOR "Cursor"
Expand All @@ -12,9 +24,9 @@
#define LUAMONGO_GRIDFILE "GridFile"
#define LUAMONGO_GRIDFSCHUNK "GridFSChunk"
#define LUAMONGO_GRIDFILEBUILDER "GridFileBuilder"

// not an actual class, pseudo-base for error messages
#define LUAMONGO_DBCLIENT "DBClient"
#endif

#define LUAMONGO_ERR_CONNECTION_FAILED "Connection failed: %s"
#define LUAMONGO_ERR_REPLICASET_FAILED "ReplicaSet.New failed: %s"
Expand Down
5 changes: 4 additions & 1 deletion mongo_bsontypes.cpp
Expand Up @@ -375,8 +375,11 @@ int mongo_bsontypes_register(lua_State *L) {
{NULL, NULL}
};

//luaL_register(L, LUAMONGO_ROOT, bsontype_methods);
#if LUA_VERSION_NUM < 502
luaL_register(L, LUAMONGO_ROOT, bsontype_methods);
#else
luaL_newlib(L, bsontype_methods);
#endif

return 1;
}
Expand Down
5 changes: 4 additions & 1 deletion mongo_connection.cpp
Expand Up @@ -120,8 +120,11 @@ int mongo_connection_register(lua_State *L) {

lua_pop(L,1);

//luaL_register(L, LUAMONGO_CONNECTION, connection_class_methods);
#if LUA_VERSION_NUM < 502
luaL_register(L, LUAMONGO_CONNECTION, connection_class_methods);
#else
luaL_newlib(L, connection_class_methods);
#endif

return 1;
}
Expand Down
7 changes: 5 additions & 2 deletions mongo_cursor.cpp
Expand Up @@ -194,8 +194,11 @@ int mongo_cursor_register(lua_State *L) {

lua_pop(L,1);

//luaL_register(L, LUAMONGO_CURSOR, cursor_class_methods);
#if LUA_VERSION_NUM < 502
luaL_register(L, LUAMONGO_CURSOR, cursor_class_methods);
#else
luaL_newlib(L, cursor_class_methods);

#endif

return 1;
}
2 changes: 2 additions & 0 deletions mongo_cxx_extension.cpp
Expand Up @@ -20,6 +20,8 @@
* IN THE SOFTWARE.
*/

#include <iostream>
#include <stdlib.h>
#include <client/redef_macros.h>
#include <client/dbclient.h>
#include <client/gridfs.h>
Expand Down

0 comments on commit ba33091

Please sign in to comment.