[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Problems with creating a table from backend
- From: jdarling@...
- Date: Thu, 13 Apr 2006 10:31:12 -0700
Its actually generic Pascal. I am using Delphi to test in as it still
works a bit better then Lazarus in my openion, but I can also compile
it in Pascal.
Just to make a sanity check then (I'll leave out all specific code) it
should look something like this then:
lua_newtable(L);
tbl = lua_gettop(L);
lua_pushstring(L, 'Params');
lua_pushvalue(L, tbl);
lua_settable(L, LUA_GLOBALSINDEX);
lua_pushnumber(L, 1);
lua_pushstring(L, 'Value 1');
lua_settable(L, tbl);
lua_pushnumber(L, 2);
lua_pushstring(L, 'Value 2');
lua_settable(L, tbl);
lua_remove(L, tbl);
then in my lua:
function Test(v, k)
print(v..' '..k.."\n")
end
table.foreach(Params, Test)
In theory my output should be:
1 Value 1
2 Value 2
If so then this blows up in my face as well. No warnings or errors, the
app just closes and dies. I can read/write C/C++ as well, if you happen
to have some sample code of embedding a table in a table that would be
excelent :)
- Jeremy
"Help I suffer from the oxymoron Corporate Security."
> -------- Original Message --------
> Subject: Re: Problems with creating a table from backend
> From: Matt Campbell <mattc@freedombox.cc>
> Date: Thu, April 13, 2006 11:08 am
> To: Lua list <lua@bazar2.conectiva.com.br>
>
> Hello Jeremy:
>
> The problem is that in the second procedure, you create the table,
> retrieve its stack index, and then call lua_settable to make it a global
> variable. Calling lua_settable pops the newly created table from the
> stack, making your stored stack index invalid. Instead, that function
> should begin as follows:
>
> lua_newtable(L);
> tbl := lua_gettop(L);// get the table reference
> lua_pushstring(L, 'Params');
> lua_pushvalue(L, tbl); // push it again to make it a global
> lua_settable(L, LUA_GLOBALSINDEX);//set the var name "Params" = table
> instance
>
> To keep your pushes and pops balanced, the function should now have this
> at the end:
>
> lua_remove(L, tbl);
>
> I hope this helps.
>
> BTW, is this Delphi, or some other form of Pascal? I don't really know
> Pascal, but the relevant code was similar enough to C that I could
> follow it.
>
> --
> Matt Campbell
> Lead Programmer
> Serotek Corporation
> www.freedombox.info
> "The Accessibility Anywhere People"