diff --git a/common.h b/common.h index 9800ba6..bc081b1 100644 --- a/common.h +++ b/common.h @@ -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" diff --git a/main.cpp b/main.cpp index 9ed93b1..95e9865 100644 --- a/main.cpp +++ b/main.cpp @@ -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; } diff --git a/mongo_cxx_extension.cpp b/mongo_cxx_extension.cpp index 22b66fe..bda2852 100644 --- a/mongo_cxx_extension.cpp +++ b/mongo_cxx_extension.cpp @@ -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; @@ -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 */ @@ -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; } diff --git a/mongo_gridfilebuilder.cpp b/mongo_gridfilebuilder.cpp index 7e1a1bb..1132939 100644 --- a/mongo_gridfilebuilder.cpp +++ b/mongo_gridfilebuilder.cpp @@ -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} };