提交 25572716 编写于 作者: L Lion

return err for buffer functions

上级 7c588b9c
......@@ -65,11 +65,15 @@ end
-- create the searcher based on the cache-policy
local searcher, v_index, content
if cachePolicy == "file" then
searcher = xdb.new_with_file_only(dbFile)
searcher, err = xdb.new_with_file_only(dbFile)
if err ~= nil then
print(string.format("failed to create searcher: %s", err))
return
end
elseif cachePolicy == "vectorIndex" then
v_index = xdb.load_vector_index(dbFile)
if v_index == nil then
print(string.format("failed to load vector index from '%s'", dbFile))
v_index, err = xdb.load_vector_index(dbFile)
if err ~= nil then
print(string.format("failed to load vector index: %s", err))
return
end
......@@ -79,8 +83,8 @@ elseif cachePolicy == "vectorIndex" then
return
end
elseif cachePolicy == "content" then
content = xdb.load_content(dbFile)
if content == nil then
content, err = xdb.load_content(dbFile)
if err ~= nil then
print(string.format("failed to load xdb content from '%s'", dbFile))
return
end
......@@ -174,4 +178,4 @@ if count > 0 then
avg_costs = c_time / count
end
print(string.format("Bench finished, {cachePolicy: %s, total: %d, took: %.3f s, cost: %.3f μs/op}",
cachePolicy, count, (xdb.now() - s_time)/1e6, c_time / count))
cachePolicy, count, (xdb.now() - s_time)/1e6, c_time / count))
\ No newline at end of file
......@@ -68,9 +68,9 @@ if cachePolicy == "file" then
return
end
elseif cachePolicy == "vectorIndex" then
v_index = xdb.load_vector_index(dbFile)
if v_index == nil then
print(string.format("failed to load vector index from '%s'", dbFile))
v_index, err = xdb.load_vector_index(dbFile)
if err ~= nil then
print(string.format("failed to load vector index: %s", err))
return
end
......@@ -80,8 +80,8 @@ elseif cachePolicy == "vectorIndex" then
return
end
elseif cachePolicy == "content" then
content = xdb.load_content(dbFile)
if content == nil then
content, err = xdb.load_content(dbFile)
if err ~= nil then
print(string.format("failed to load xdb content from '%s'", dbFile))
return
end
......
......@@ -152,13 +152,16 @@ static int lua_xdb_load_header_from_file(lua_State *L) {
header = xdb_load_header_from_file(db_path);
if (header == NULL) {
lua_pushnil(L);
return 1;
lua_pushfstring(L, "load header from `%s`", db_path);
return 2;
}
// alloc the buffer.
buffer = (xdb_buffer_t *) lua_newuserdata(L, sizeof(xdb_buffer_t));
if (buffer == NULL) {
return luaL_error(L, "failed to alloc xdb buffer entry");
lua_pushnil(L);
lua_pushfstring(L, "failed to alloc xdb buffer entry");
return 2;
}
// init the buffer
......@@ -170,8 +173,9 @@ static int lua_xdb_load_header_from_file(lua_State *L) {
// set the metatable of the header buffer object and push onto the stack
luaL_getmetatable(L, XDB_BUFFER_METATABLE_NAME);
lua_setmetatable(L, -2);
lua_pushnil(L);
return 1;
return 2;
}
static int lua_xdb_load_vector_index_from_file(lua_State *L) {
......@@ -184,13 +188,16 @@ static int lua_xdb_load_vector_index_from_file(lua_State *L) {
v_index = xdb_load_vector_index_from_file(db_path);
if (v_index == NULL) {
lua_pushnil(L);
return 1;
lua_pushfstring(L, "load vector index from `%s`", db_path);
return 2;
}
// alloc the buffer.
buffer = (xdb_buffer_t *) lua_newuserdata(L, sizeof(xdb_buffer_t));
if (buffer == NULL) {
return luaL_error(L, "failed to alloc xdb buffer entry");
lua_pushnil(L);
lua_pushstring(L, "failed to alloc xdb buffer entry");
return 2;
}
// init the buffer
......@@ -202,8 +209,9 @@ static int lua_xdb_load_vector_index_from_file(lua_State *L) {
// set the metatable of the header buffer object and push onto the stack
luaL_getmetatable(L, XDB_BUFFER_METATABLE_NAME);
lua_setmetatable(L, -2);
lua_pushnil(L);
return 1;
return 2;
}
static int lua_xdb_load_content_from_file(lua_State *L) {
......@@ -216,13 +224,16 @@ static int lua_xdb_load_content_from_file(lua_State *L) {
content = xdb_load_content_from_file(db_path);
if (content == NULL) {
lua_pushnil(L);
return 1;
lua_pushfstring(L, "load xdb content from `%s`", db_path);
return 2;
}
// alloc the buffer.
buffer = (xdb_buffer_t *) lua_newuserdata(L, sizeof(xdb_buffer_t));
if (buffer == NULL) {
return luaL_error(L, "failed to alloc xdb buffer entry");
lua_pushnil(L);
lua_pushstring(L, "failed to alloc xdb buffer entry");
return 2;
}
// init the buffer
......@@ -234,8 +245,9 @@ static int lua_xdb_load_content_from_file(lua_State *L) {
// set the metatable of the header buffer object and push onto the stack
luaL_getmetatable(L, XDB_BUFFER_METATABLE_NAME);
lua_setmetatable(L, -2);
lua_pushnil(L);
return 1;
return 2;
}
// --- End of buffer api
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册