[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Embedding lua - passing arrays, multidimensional arrays
- From: Ervin Hegedüs <airween@...>
- Date: Thu, 24 Sep 2015 20:33:02 +0200
Hi Sean,
thanks for the answer,
On Thu, Sep 24, 2015 at 12:05:12PM -0400, Sean Conner wrote:
> It was thus said that the Great Ervin Hegedüs once stated:
> > so, I've read the documents above - that's very-very clear.
> > Now I
> > think I understand the stack - it's not just very funny, it
> > has
> > cold logic, and pure implementation.
> >
> > Here is the sample code, what I tries first - and there is
> > the
> > state of stack, to help me to clarify the working of Lua
> > stack.
> >
> > Please review and comment it - em I understanding right it?
> >
> > /*
> > myTable = {
> > [0] = { ["a"] = 4, ["b"] = 2 },
> > [1] = { ["a"] = 13, ["b"] = 37 }
> > } */
>
> An alternative to your code:
>
> lua_newtable(L); /* t */
> lua_pushinteger(L,0); /* t n */
> lua_newtable(L); /* t n t */
> lua_pushinteger(L,4); /* t n t n */
> lua_setfield(L,-2,"a"); /* t n t */
> lua_pushinteger(L,2); /* t n t n */
> lua_setfield(L,-2,"b"); /* t n t */
> lua_settable(L,-3); /* t */
>
> lua_pushinteger(L,1); /* t n */
> lua_newtable(L); /* t n t */
> lua_pushinteger(L,13); /* t n t n */
> lua_setfield(L,-2,"a"); /* t n t */
> lua_pushinteger(L,37); /* t n t n */
> lua_setfield(L,-2,"b"); /* t n t */
> lua_settable(L,-3); /* t */
> lua_setglobal(L,"t"); /* */
well, many thanks for this - I've found lua_setfield(), but this
example is very helpful.
> The Lua stack is documented in the comments using a notation
> from Forth.
> The top of the stack is to the right; the leftmost item is at
> index 1, while
> the right most item is -1.
>
> I also have a function I occasionally use to help with the
> stack
> manipulations---it dumps out the current Lua stack (it's in C):
>
> void dump_luastack(lua_State *L)
> {
in the Lua docs, there is the stackDump() example, I've tried
that too.
I think now the working of stack, and related funcions is clear.
Thanks again,
a.
--
I � UTF-8
- References:
- Embedding lua - passing arrays, multidimensional arrays, Ervin Hegedüs
- Re: Embedding lua - passing arrays, multidimensional arrays, steve donovan
- Re: Embedding lua - passing arrays, multidimensional arrays, Ervin Hegedüs
- Re: Embedding lua - passing arrays, multidimensional arrays, Michal Kottman
- Re: Embedding lua - passing arrays, multidimensional arrays, Ervin Hegedüs
- Re: Embedding lua - passing arrays, multidimensional arrays, Sean Conner