Skip to content

Commit

Permalink
Use numbers in Lua 5.1/5.2 for index options
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Wang committed Dec 4, 2016
1 parent 6a47bf5 commit 439c9f0
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 5 deletions.
10 changes: 5 additions & 5 deletions c_wrapper/lua-mongoc-collection.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ lua_mongo_collection_create_index(lua_State *L)
}
}

if ( lua_istable(L, options_index) ){
if (lua_istable(L, options_index) ){
lua_getfield(L, options_index, "name"); //String
lua_getfield(L, options_index, "default_language"); //String
lua_getfield(L, options_index, "language_override"); //String
Expand Down Expand Up @@ -690,11 +690,11 @@ lua_mongo_collection_create_index(lua_State *L)
if( lua_isboolean(L, -4) ){
opt.background = lua_toboolean(L, -4);
}
if( lua_isinteger(L, -3) ){
opt.expire_after_seconds = lua_tointeger(L, -3);
if( lua_isinteger_compat(L, -3) ){
opt.expire_after_seconds = lua_tointeger_compat(L, -3);
}
if( lua_isinteger(L, -2) ){
opt.v = lua_tointeger(L, -2);
if( lua_isinteger_compat(L, -2) ){
opt.v = lua_tointeger_compat(L, -2);
}
if( lua_istable(L, -1) ){
throw_error = !(lua_table_to_bson(L, &weights, -1, false, absolute_luaBSONObjects_index, &error ));
Expand Down
22 changes: 22 additions & 0 deletions c_wrapper/lua-version-compat.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,28 @@ lua_pushinteger_compat(lua_State *L,
#endif
}

bool
lua_isinteger_compat(lua_State *L,
int index)
{
#if LUA_VERSION_NUM >= 503
return lua_isinteger(L, index);
#else
return lua_isnumber(L, index);
#endif
}

int
lua_tointeger_compat(lua_State *L,
int index)
{
#if LUA_VERSION_NUM >= 503
return lua_tointeger(L, index);
#else
return lua_tonumber(L, index);
#endif
}

void
setfuncs_compat(lua_State *L,
const struct luaL_Reg *R,
Expand Down
4 changes: 4 additions & 0 deletions c_wrapper/lua-version-compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@

void lua_pushinteger_compat(lua_State *L,
int value);
bool lua_isinteger_compat(lua_State *L,
int index);
int lua_tointeger_compat(lua_State *L,
int index);
void setfuncs_compat(lua_State *L,
const struct luaL_Reg *R,
char *name_for_lua51);
Expand Down

0 comments on commit 439c9f0

Please sign in to comment.