fixed segfault by correcting indexes for recursively printing tables

git-svn-id: svn://anubis/anaglym/trunk@7 99a6e188-d820-4881-8870-2d33a10e2619
This commit is contained in:
Josh Holtrop 2009-09-14 02:01:58 +00:00
parent 6686404032
commit 689349d2b6

12
ag.cc
View File

@ -21,11 +21,13 @@ namespace ag
switch (type) switch (type)
{ {
case LUA_TNUMBER: case LUA_TNUMBER:
cout << lua_tonumber(L, index);
break;
case LUA_TSTRING: case LUA_TSTRING:
cout << lua_tostring(L, index); cout << lua_tostring(L, index);
break; break;
case LUA_TTABLE: case LUA_TTABLE:
cout << '['; cout << "{ ";
/* traverse the table and print the keys/values */ /* traverse the table and print the keys/values */
lua_checkstack(L, 3); lua_checkstack(L, 3);
@ -34,13 +36,15 @@ namespace ag
{ {
if (!first) if (!first)
cout << ", "; cout << ", ";
ag_print_val(L, -2); cout << '[';
ag_print_val(L, index + 1);
cout << ']';
cout << " => "; cout << " => ";
ag_print_val(L, -1); ag_print_val(L, index + 2);
lua_pop(L, 1); lua_pop(L, 1);
} }
cout << ']'; cout << " }";
break; break;
case LUA_TFUNCTION: case LUA_TFUNCTION:
cout << "<function>"; cout << "<function>";