static int lua_dict_transaction_commit(lua_State *L);
static int lua_dict_set(lua_State *L);
static int lua_dict_unset(lua_State *L);
+static int lua_dict_set_timestamp(lua_State *L);
static luaL_Reg lua_dict_txn_methods[] = {
{ "rollback", lua_dict_transaction_rollback },
{ "commit", lua_dict_transaction_commit },
{ "set", lua_dict_set },
{ "unset", lua_dict_unset },
+ { "set_timestamp", lua_dict_set_timestamp },
{ NULL, NULL },
};
return 1;
}
+
+/*
+ * Set timestamp to the transaction [-2,+0,e]
+ *
+ * Args:
+ * 1) userdata: struct lua_dict_txn *
+ * 2) PosixTimespec : { tv_sec, tv_nsec }
+ */
+static int lua_dict_set_timestamp(lua_State *L)
+{
+ struct lua_dict_txn *txn;
+ lua_Number tv_sec, tv_nsec;
+
+ DLUA_REQUIRE_ARGS(L, 2);
+
+ txn = xlua_dict_txn_getptr(L, 1, NULL);
+ if (dlua_table_get_number_by_str(L, 2, "tv_sec", &tv_sec) <= 0)
+ luaL_error(L, "tv_sec missing from table");
+ if (dlua_table_get_number_by_str(L, 2, "tv_nsec", &tv_nsec) <= 0)
+ luaL_error(L, "tv_nsec missing from table");
+
+ struct timespec ts = {
+ .tv_sec = tv_sec,
+ .tv_nsec = tv_nsec
+ };
+ dict_transaction_set_timestamp(txn->txn, &ts);
+ return 0;
+}