Permalink
Browse files

Fix insert_batch command

Bad programmer, no cookie  :(

Also, in LUA_TNUMBER case of  lua_append_bson), move lua_tointeger closer to the scope where it is actually used.

git-svn-id: http://luamongo.googlecode.com/svn/trunk@62 17e306f6-9439-11de-a13a-71b910e68cc8
  • Loading branch information...
1 parent 1105ff0 commit dff3b69ee48047781344b7b5a02e80cbaa2b1dfe neomantra committed Oct 28, 2010
Showing with 6 additions and 8 deletions.
  1. +2 −2 mongo_connection.cpp
  2. +4 −6 utils.cpp
View
4 mongo_connection.cpp
@@ -255,8 +255,8 @@ static int connection_insert_batch(lua_State *L) {
for (size_t i = 1; i < tlen; ++i) {
vdata.push_back(BSONObj());
lua_rawgeti(L, 3, i);
- lua_to_bson(L, -1, vdata.back());
- lua_pop(L, -1);
+ lua_to_bson(L, 4, vdata.back());
+ lua_pop(L, 1);
}
connection->insert(ns, vdata);
} catch (std::exception &e) {
View
10 utils.cpp
@@ -238,14 +238,11 @@ static void lua_append_bson(lua_State *L, const char *key, int stackpos, BSONObj
} else if (type == LUA_TNIL) {
builder->appendNull(key);
} else if (type == LUA_TNUMBER) {
- int intval = lua_tointeger(L, stackpos);
double numval = lua_tonumber(L, stackpos);
-
if (numval == floor(numval)) {
- /*
- * The numeric value looks like an integer, treat it as such.
- * This is closer to how JSON datatypes behave.
- */
+ // The numeric value looks like an integer, treat it as such.
+ // This is closer to how JSON datatypes behave.
+ int intval = lua_tointeger(L, stackpos);
builder->append(key, static_cast<int32_t>(intval));
} else {
builder->append(key, numval);
@@ -267,6 +264,7 @@ void bson_to_lua(lua_State *L, const BSONObj &obj) {
}
}
+// stackpos must be relative to the bottom, i.e., not negative
void lua_to_bson(lua_State *L, int stackpos, BSONObj &obj) {
BSONObjBuilder builder;

0 comments on commit dff3b69

Please sign in to comment.