Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make OID a BSON type

git-svn-id: http://luamongo.googlecode.com/svn/trunk@46 17e306f6-9439-11de-a13a-71b910e68cc8
  • Loading branch information...
commit b048100aabde184f6e93e3d0b7245edf9eab2c71 1 parent 18940bc
nrich@ii.net authored
Showing with 21 additions and 4 deletions.
  1. +10 −1 mongo_bsontypes.cpp
  2. +11 −3 utils.cpp
11 mongo_bsontypes.cpp
View
@@ -54,6 +54,13 @@ static int bson_type_Symbol(lua_State *L) {
return 1;
}
+static int bson_type_OID(lua_State *L) {
+ push_bsontype_table(L, mongo::jstOID);
+ lua_pushvalue(L, 1);
+ lua_rawseti(L, -2, 1); // t[1] = function arg #1
+ return 1;
+}
+
static int integer_value(lua_State *L) {
int n = lua_gettop(L);
int returncount = 1;
@@ -164,7 +171,6 @@ static int regex_tostring(lua_State *L) {
return 1;
}
-
// TODO:
// all of this should be in Lua so it can get JIT wins
// bind the bson typeids
@@ -192,6 +198,7 @@ void push_bsontype_table(lua_State* L, mongo::BSONType bsontype) {
lua_pushcfunction(L, number_value);
break;
case mongo::Symbol:
+ case mongo::jstOID:
lua_pushcfunction(L, string_value);
break;
case mongo::RegEx:
@@ -205,6 +212,7 @@ void push_bsontype_table(lua_State* L, mongo::BSONType bsontype) {
case mongo::NumberInt:
case mongo::Timestamp:
case mongo::Symbol:
+ case mongo::jstOID:
lua_pushcfunction(L, generic_tostring);
break;
case mongo::Date:
@@ -292,6 +300,7 @@ int mongo_bsontypes_register(lua_State *L) {
{"RegEx", bson_type_RegEx},
{"NumberInt", bson_type_NumberInt},
{"Symbol", bson_type_Symbol},
+ {"OID", bson_type_OID},
{"type", bson_type_name},
{"tonumber", bson_tonumber},
{NULL, NULL}
14 utils.cpp
View
@@ -75,9 +75,6 @@ void lua_push_value(lua_State *L, const BSONElement &elem) {
case mongo::Object:
bson_to_table(L, elem.embeddedObject());
break;
- case mongo::jstOID:
- lua_pushstring(L, elem.__oid().str().c_str());
- break;
case mongo::Date:
push_bsontype_table(L, mongo::Date);
lua_pushnumber(L, elem.date());
@@ -100,6 +97,11 @@ void lua_push_value(lua_State *L, const BSONElement &elem) {
lua_pushstring(L, elem.regexFlags());
lua_rawseti(L, -2, 2);
break;
+ case mongo::jstOID:
+ push_bsontype_table(L, mongo::jstOID);
+ lua_pushstring(L, elem.__oid().str().c_str());
+ lua_rawseti(L, -2, 1);
+ break;
case mongo::EOO:
break;
default:
@@ -170,6 +172,12 @@ static void lua_append_bson(lua_State *L, const char *key, int stackpos, BSONObj
case mongo::Symbol:
builder->appendSymbol(key, lua_tostring(L, -1));
break;
+ case mongo::jstOID: {
+ OID oid;
+ oid.init(lua_tostring(L, -1));
+ builder->appendOID(key, &oid);
+ break;
+ }
default:
luaL_error(L, LUAMONGO_UNSUPPORTED_BSON_TYPE, luaL_typename(L, stackpos));
}
Please sign in to comment.
Something went wrong with that request. Please try again.