hlog: move startup-stats iteration into lua

It's silly to have the loop in C when we can write it in lua - yielding
fewer lines of code, more readable code, etc.

Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
2 files changed, 5 insertions(+), 19 deletions(-)

M hlog/hlog.c
M xlua/scripts/startup-stats.lua
M hlog/hlog.c +0 -18
@@ 1977,12 1977,9 @@ static int load_index(void)
 
 static void print_stats(void)
 {
-	struct index_iter_ctx ctx;
 	struct xlua_state *lua;
 	lua_State *L;
-	struct qso *qso;
 	char error[128];
-	bool failed;
 	int ret;
 
 	printf("Global call statistics:\n");

          
@@ 1995,21 1992,6 @@ static void print_stats(void)
 
 	L = xlua_lock(lua);
 
-	/* iterate over all the QSOs */
-	for (qso = index_iter_history_start(&ctx, true), failed = false;
-	     qso;
-	     qso = index_iter_history_next(&ctx)) {
-		ret = xlua_qso_call(L, "summarize_qso", qso_getref(qso),
-				    true, error, sizeof(error));
-		if (ret) {
-			printf("Error: failed to execute lua: %s\n", error);
-			failed = true;
-		}
-	}
-
-	if (failed)
-		printf("Warning: incomplete stats due to errors\n");
-
 	/* print stats */
 	ret = xlua_call(L, "print_summary", 0, 0, error, sizeof(error));
 	if (ret)

          
M xlua/scripts/startup-stats.lua +5 -1
@@ 40,7 40,7 @@ local function init_mode_band(mode, band
 	band_names[band] = band
 end
 
-function summarize_qso(qso)
+local function summarize_qso(qso)
 	local mode = qso.tx.mode
 	local band = qso.tx.band
 

          
@@ 78,6 78,10 @@ end
 function print_summary()
 	local out
 
+	for qso in hlog.index.history(true) do
+		summarize_qso(qso)
+	end
+
 	-- order the band names
 	local band_name_array = {}
 	for band, dummy in pairs(band_names) do