lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Just an idea: lua_isstring always returns 1, also in case of a number index, which is convertible to a string. In that case, you are in the first "if" anytime?

BetGear - Glen wrote:
Hi,

Ok, I'm going to post the parsing code, so you can pick it to bits :)

void PrintTable(lua_State *L)
{
	CString op;
	int		bah;

	lua_pushnil(L);

	while(lua_next(L, -2) != 0)
	{
		if(lua_isstring(L, -1))
		{
			if(lua_isstring(L, -2))
			{
				op.Format(_T("%s = %s\n"), lua_tostring(L,
-2), lua_tostring(L, -1));
			}
			else
			{
				op.Format(_T("%d = %d\n"), lua_tonumber(L,
-2), lua_tostring(L, -1));
			}
		}
		else if(lua_isnumber(L, -1))
		{
			if(lua_isstring(L, -2))
				op.Format(_T("%s = %d\n"), lua_tostring(L,
-2), lua_tonumber(L, -1));
			else
				op.Format(_T("%d = %d\n"), lua_tonumber(L,
-2), lua_tonumber(L, -1));
		}
		else if(lua_istable(L, -1))
			PrintTable(L);

		lua_pop(L, 1);
	}
}

Cheers

Glen.

-----Original Message-----
From: lua-bounces@bazar2.conectiva.com.br
[mailto:lua-bounces@bazar2.conectiva.com.br] On Behalf Of Luiz Henrique de
Figueiredo
Sent: 25 September 2007 15:24
To: Lua list
Subject: Re: Lua_next probles

I'm using the standard c table parsing code that is described in the lua
manual. The issue appear to be when lua_next comes to parse the "line2"
data, "line1" is parsed correctly, with the key set to 1 as is expected,
but
the next iteration causes lua to bomb out. Tracing into lua reveal an
invalid key error.

You're probably not popping the value in the loop or using lua_tostring
on numerical keys. See http://www.lua.org/manual/5.1/manual.html#lua_next


--

--

  \ /           Sol-3 GmbH & Co. KG             Eva Schmidt
 --o-- Sol-3    Eltviller Straße 2              Phone: ++49 (0) 6123 7029 23
  / \           D-65399 Kiedrich                Fax:   ++49 (0) 6123 7029 29
                USt-ID:   DE 204978307          eMail: es@sol-3.de
                Register: WI HRA 6607
                Komplementär:    Sol-3 Verwaltungs GmbH
                Register:        WI HRB 117786
                Geschäftsführer: Norbert Geus, Dirk Zoller