Skip to content

Commit

Permalink
Merge pull request #4 from pakozm/master
Browse files Browse the repository at this point in the history
Added GridFileBuilder and other extensions
  • Loading branch information
pakozm committed May 6, 2014
2 parents 90e4a98 + a5b3b1c commit 26a81a5
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
5 changes: 5 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
#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"
Expand Down
6 changes: 6 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ LM_EXPORT int luaopen_mongo(lua_State *L) {
* so "mongo = require('mongo')" works
*/
// 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
15 changes: 10 additions & 5 deletions mongo_cxx_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ namespace mongo_cxx_extension {
}

void GridFileBuilder::appendChunk(const char *data, size_t length) {
if (length == 0 || _client == NULL) return;
if (length == 0) return;
// check if there are pending data
if (_pending_data != NULL) {
size_t total_size = _pending_data_size + length;
Expand Down Expand Up @@ -123,7 +123,6 @@ namespace mongo_cxx_extension {

BSONObj GridFileBuilder::buildFile(const string &name,
const string& content_type) {
if (_client == NULL) return BSONObj();
privateAppendPendingData();

/* from gridfs.cpp at https://github.com/mongodb/mongo-cxx-driver/blob/legacy/src/mongo/client/gridfs.cpp */
Expand Down Expand Up @@ -162,9 +161,15 @@ namespace mongo_cxx_extension {
BSONObj ret = file.obj();
_client->insert(_filesNS.c_str(), ret);

// disallow builder object
_client = NULL;

// resets the object
_current_chunk = 0;
_pending_data = NULL;
_pending_data_size = 0;
_file_length = 0;
OID id;
id.init();
_file_id = BSON("_id" << id);

return ret;
}

Expand Down
1 change: 1 addition & 0 deletions mongo_gridfilebuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ static int gridfilebuilder_tostring(lua_State *L) {
int mongo_gridfilebuilder_register(lua_State *L) {
static const luaL_Reg gridfilebuilder_methods[] = {
{"append", gridfilebuilder_append},
{"write", gridfilebuilder_append},
{"build", gridfilebuilder_build},
{NULL, NULL}
};
Expand Down

0 comments on commit 26a81a5

Please sign in to comment.