From 689349d2b6cf4daba2b42aad42d5f1410810acd0 Mon Sep 17 00:00:00 2001 From: Josh Holtrop Date: Mon, 14 Sep 2009 02:01:58 +0000 Subject: [PATCH] fixed segfault by correcting indexes for recursively printing tables git-svn-id: svn://anubis/anaglym/trunk@7 99a6e188-d820-4881-8870-2d33a10e2619 --- ag.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ag.cc b/ag.cc index a0fadd4..53975af 100644 --- a/ag.cc +++ b/ag.cc @@ -21,11 +21,13 @@ namespace ag switch (type) { case LUA_TNUMBER: + cout << lua_tonumber(L, index); + break; case LUA_TSTRING: cout << lua_tostring(L, index); break; case LUA_TTABLE: - cout << '['; + cout << "{ "; /* traverse the table and print the keys/values */ lua_checkstack(L, 3); @@ -34,13 +36,15 @@ namespace ag { if (!first) cout << ", "; - ag_print_val(L, -2); + cout << '['; + ag_print_val(L, index + 1); + cout << ']'; cout << " => "; - ag_print_val(L, -1); + ag_print_val(L, index + 2); lua_pop(L, 1); } - cout << ']'; + cout << " }"; break; case LUA_TFUNCTION: cout << "";