Skip to content

Commit

Permalink
Merge pull request #27 from pabloromeu/master
Browse files Browse the repository at this point in the history
Adapted for Lua 5.2
  • Loading branch information
pakozm committed May 6, 2014
2 parents e506238 + 26a81a5 commit f40309b
Show file tree
Hide file tree
Showing 26 changed files with 846 additions and 250 deletions.
25 changes: 25 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
gmon.out

# Building files #
##################
*.o
*.so

# Emacs backups #
#################
*~
\#*\#
.\#*

# Vim swap #
*.swp
# OS generated files #
######################
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
Icon?
ehthumbs.db
Thumbs.db
54 changes: 16 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,52 +1,30 @@
CC= g++
CFLAGS= -g -O2 -shared -fPIC -I /usr/include/lua5.1/ -I/usr/local/include/mongo/
CFLAGS= -Wall -g -O2 -shared -fPIC -I/usr/include/mongo `pkg-config --cflags lua5.2` `pkg-config --cflags libmongo-client`
AR= ar rcu
RANLIB= ranlib
RM= rm -f
LIBS=-lmongoclient -lboost_thread -lboost_filesystem
LIBS=`pkg-config --libs lua5.2` -lmongoclient -lssl -lboost_thread -lboost_filesystem
OUTLIB=mongo.so

LDFLAGS= $(LIBS)

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
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

all: luamongo
UNAME = `uname`
PLAT = DetectOS

all: $(PLAT)

DetectOS:
@make $(UNAME)

Linux:
@make -f Makefile.linux

Darwin:
@make -f Makefile.macports

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

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

echo:
@echo "CC = $(CC)"
@echo "CFLAGS = $(CFLAGS)"
@echo "AR = $(AR)"
@echo "RANLIB = $(RANLIB)"
@echo "RM = $(RM)"
@echo "LDFLAGS = $(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)

.PHONY: all
56 changes: 56 additions & 0 deletions Makefile.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
CC= g++
CFLAGS= -Wall -g -O2 -shared -fPIC -I/usr/include/mongo `pkg-config --cflags lua5.2` `pkg-config --cflags libmongo-client`
AR= ar rcu
RANLIB= ranlib
RM= rm -f
LIBS=`pkg-config --libs lua5.2` -lmongoclient -lssl -lboost_thread -lboost_filesystem
OUTLIB=mongo.so

LDFLAGS= $(LIBS)

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

all: luamongo

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

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

echo:
@echo "CC = $(CC)"
@echo "CFLAGS = $(CFLAGS)"
@echo "AR = $(AR)"
@echo "RANLIB = $(RANLIB)"
@echo "RM = $(RM)"
@echo "LDFLAGS = $(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
56 changes: 56 additions & 0 deletions Makefile.macports
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
CC= g++
CFLAGS= -Wall -g -O2 -fPIC `pkg-config --cflags "lua >= 5.2"` -I/opt/local/include/mongo/
AR= ar rcu
RANLIB= ranlib
RM= rm -f
LIBS=`pkg-config --libs "lua >= 5.2"` -lmongoclient -lssl -lboost_thread-mt -lboost_filesystem-mt -flat_namespace -bundle -L/opt/local/lib -rdynamic
OUTLIB=mongo.so

LDFLAGS= $(LIBS)

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

all: luamongo

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

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

echo:
@echo "CC = $(CC)"
@echo "CFLAGS = $(CFLAGS)"
@echo "AR = $(AR)"
@echo "RANLIB = $(RANLIB)"
@echo "RM = $(RM)"
@echo "LDFLAGS = $(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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@

## Support

Submit issues to the <a href="https://github.com/moai/luamongo/issues">moai github site</a>.
Submit issues to the <a href="https://github.com/pakozm/luamongo/issues">pakozm github site</a>.

There is a <a href="http://groups.google.com/group/luamongo">Google Groups mailing list</a>.

## Example

require('mongo')
local mongo = require('mongo')

-- Create a connection object
local db = assert(mongo.Connection.New())
Expand Down Expand Up @@ -54,9 +54,9 @@ There is a <a href="http://groups.google.com/group/luamongo">Google Groups maili

## How It Works

luamongo is a Lua library that wraps the <a href="https://github.com/mongodb/mongo/blob/master/src/mongo/client/dbclient.h">mongodb C++ API</a>.
luamongo is a Lua library that wraps the <a href="https://github.com/mongodb/mongo-cxx-driver">mongodb C++ API</a>.

The current implementation does not give you raw access to the BSON objects. BSON objects are passed to the API using a Lua table or a JSON string representation. Every returned BSON document is fully marshalled to a Lua table.
The current implementation does not give you raw access to the BSON objects. BSON objects are passed to the API using a Lua table or a JSON string representation. Every returned BSON document is fully marshalled to a Lua table.

## Installing

Expand All @@ -66,5 +66,5 @@ luarocks can be used to install luamongo.

## History

This project was forked from the <a href="http://code.google.com/p/luamongo/">luamongo project</a> on googlecode.
This project was forked from the <a href="http://github.com/moai/luamongo/">luamongo project</a> on GitHub.

24 changes: 15 additions & 9 deletions common.h
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#define LUAMONGO_ROOT "mongo"
#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_NAME "mongo"
#define LUAMONGO_NAME_STRING "_NAME"
#define LUAMONGO_VERSION "0.4"
#define LUAMONGO_VERSION_STRING "_VERSION"

#define LUAMONGO_ROOT "mongo"
#define LUAMONGO_CONNECTION "Connection"
#define LUAMONGO_REPLICASET "ReplicaSet"
#define LUAMONGO_CURSOR "Cursor"
#define LUAMONGO_QUERY "Query"
#define LUAMONGO_GRIDFS "GridFS"
#define LUAMONGO_GRIDFILE "GridFile"
#define LUAMONGO_GRIDFSCHUNK "GridFSChunk"
#define LUAMONGO_GRIDFILEBUILDER "GridFileBuilder"

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

#define LUAMONGO_ERR_CONNECTION_FAILED "Connection failed: %s"
#define LUAMONGO_ERR_REPLICASET_FAILED "ReplicaSet.New failed: %s"
Expand Down
10 changes: 5 additions & 5 deletions debian/control
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
Source: luamongo
Section: database
Priority: optional
Maintainer: Evan Wies <neomantra@gmail.com>
Build-Depends: debhelper (>= 7.0.50), liblua5.1-0-dev,
Maintainer: Francisco Zamora-Martinez <pakozm@gmail.com>
Build-Depends: debhelper (>= 7.0.50), liblua5.2-dev,
mongodb (>= 1.6) | mongodb-stable (>= 1.6) | mongodb-unstable (>= 1.6)
| mongodb-snapshot (>= 1.6) | libmongoclient-dev (>= 1.6) | mongodb-dev (>= 1.6),
libboost-thread-dev (>= 1.40), libboost-filesystem-dev (>= 1.40)
Standards-Version: 3.8.4
Homepage: http://code.google.com/p/luamongo/
Homepage: https://github.com/pabloromeu/luamongo

Package: liblua5.1-mongo
Package: liblua5.2-mongo
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, lua5.1
Depends: ${shlibs:Depends}, ${misc:Depends}, lua5.2
Description: Lua driver for MongoDB
Lua (http://www.lua.org) driver for MongoDB (http://www.mongodb.org).
2 changes: 1 addition & 1 deletion debian/install
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mongo.so usr/lib/lua/5.1
mongo.so usr/lib/lua/5.2
48 changes: 35 additions & 13 deletions main.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright (c) 2014 Francisco Zamora-Martinez (pakozm@gmail.com)
* Copyright (c) 2009 Neil Richardson (nrich@iinet.net.au)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
Expand All @@ -20,19 +21,8 @@
* IN THE SOFTWARE.
*/

extern "C" {
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>

#if !defined(LUA_VERSION_NUM) || (LUA_VERSION_NUM < 501)
#include <compat-5.1.h>
#endif
};

#include <iostream>
#include <client/dbclient.h>

#include "utils.h"
#include "common.h"

Expand All @@ -44,6 +34,7 @@ extern int mongo_query_register(lua_State *L);
extern int mongo_gridfs_register(lua_State *L);
extern int mongo_gridfile_register(lua_State *L);
extern int mongo_gridfschunk_register(lua_State *L);
extern int mongo_gridfilebuilder_register(lua_State *L);

/*
*
Expand All @@ -54,21 +45,52 @@ extern int mongo_gridfschunk_register(lua_State *L);
extern "C" {

LM_EXPORT int luaopen_mongo(lua_State *L) {
// bsontypes is the root table
mongo_bsontypes_register(L);

// LUAMONGO_CONNECTION
mongo_connection_register(L);
lua_setfield(L, -2, LUAMONGO_CONNECTION);

// LUAMONGO_REPLICASET
mongo_replicaset_register(L);
lua_setfield(L, -2, LUAMONGO_REPLICASET);

// LUAMONGO_CURSOR
mongo_cursor_register(L);
lua_setfield(L, -2, LUAMONGO_CURSOR);

// LUAMONGO_QUERY
mongo_query_register(L);

lua_setfield(L, -2, LUAMONGO_QUERY);

// LUAMONGO_GRIDFS
mongo_gridfs_register(L);
lua_setfield(L, -2, LUAMONGO_GRIDFS);

// LUAMONGO_GRIDFILE
mongo_gridfile_register(L);
lua_setfield(L, -2, LUAMONGO_GRIDFILE);

// LUAMONGO_GRIDFSCHUNK
mongo_gridfschunk_register(L);
lua_setfield(L, -2, LUAMONGO_GRIDFSCHUNK);

// LUAMONGO_GRIDFILEBUILDER
mongo_gridfilebuilder_register(L);
lua_setfield(L, -2, LUAMONGO_GRIDFILEBUILDER);

/*
* push the created table to the top of the stack
* so "mongo = require('mongo')" works
*/
lua_getglobal(L, LUAMONGO_ROOT);
// lua_getglobal(L, LUAMONGO_ROOT);

// push the version number and module name
lua_pushstring(L, LUAMONGO_NAME);
lua_setfield(L, -2, LUAMONGO_NAME_STRING);
lua_pushstring(L, LUAMONGO_VERSION);
lua_setfield(L, -2, LUAMONGO_VERSION_STRING);

return 1;
}
Expand Down
Loading

0 comments on commit f40309b

Please sign in to comment.