Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added NumberLong (64-bit) support.

Note that precision is possibly lost since Lua numbers only 52-bits of integer.

git-svn-id: http://luamongo.googlecode.com/svn/trunk@60 17e306f6-9439-11de-a13a-71b910e68cc8
  • Loading branch information...
commit 1105ff02de1cf160494b20de9ef5b6437b58f9ca 1 parent f1ce763
neomantra authored
Showing with 14 additions and 0 deletions.
  1. +10 −0 mongo_bsontypes.cpp
  2. +4 −0 utils.cpp
View
10 mongo_bsontypes.cpp
@@ -49,6 +49,13 @@ static int bson_type_NumberInt(lua_State *L) {
return 1;
}
+static int bson_type_NumberLong(lua_State *L) {
+ push_bsontype_table(L, mongo::NumberLong);
+ lua_pushvalue(L, 1);
+ lua_rawseti(L, -2, 1); // t[1] = function arg #1
+ return 1;
+}
+
static int bson_type_Symbol(lua_State *L) {
push_bsontype_table(L, mongo::Symbol);
lua_pushvalue(L, 1);
@@ -213,6 +220,7 @@ void push_bsontype_table(lua_State* L, mongo::BSONType bsontype) {
case mongo::NumberInt:
lua_pushcfunction(L, integer_value);
break;
+ case mongo::NumberLong:
case mongo::Date:
case mongo::Timestamp:
lua_pushcfunction(L, number_value);
@@ -233,6 +241,7 @@ void push_bsontype_table(lua_State* L, mongo::BSONType bsontype) {
lua_pushstring(L, "__tostring");
switch(bsontype) {
case mongo::NumberInt:
+ case mongo::NumberLong:
case mongo::Timestamp:
case mongo::Symbol:
case mongo::jstOID:
@@ -357,6 +366,7 @@ int mongo_bsontypes_register(lua_State *L) {
{"Timestamp", bson_type_Timestamp},
{"RegEx", bson_type_RegEx},
{"NumberInt", bson_type_NumberInt},
+ {"NumberLong", bson_type_NumberLong},
{"Symbol", bson_type_Symbol},
{"ObjectId", bson_type_ObjectID},
{"NULL", bson_type_NULL},
View
4 utils.cpp
@@ -97,6 +97,7 @@ void lua_push_value(lua_State *L, const BSONElement &elem) {
case mongo::NumberInt:
lua_pushinteger(L, elem.numberInt());
break;
+ case mongo::NumberLong:
case mongo::NumberDouble:
lua_pushnumber(L, elem.number());
break;
@@ -213,6 +214,9 @@ static void lua_append_bson(lua_State *L, const char *key, int stackpos, BSONObj
case mongo::NumberInt:
builder->append(key, static_cast<int32_t>(lua_tointeger(L, -1)));
break;
+ case mongo::NumberLong:
+ builder->append(key, static_cast<long long int>(lua_tonumber(L, -1)));
+ break;
case mongo::Symbol:
builder->appendSymbol(key, lua_tostring(L, -1));
break;
Please sign in to comment.
Something went wrong with that request. Please try again.