[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Pushing custom-type elements into the stack.
- From: "Wesley Smith" <wesley.hoke@...>
- Date: Thu, 16 Aug 2007 18:26:44 -0700
I've been writing Lua and Lua from C code about everyday for a year
now and I still find PiL invaluable. Just yesterday in fact I looked
up how to write an 'ipairs' like function from C using userdata (p.
261). If you look the book up on amazon, you can see the table of
contents. A good portion of the book is on the C stuff.
wes
On 8/16/07, L-28C <kixdemp@gmail.com> wrote:
> I've been reluctant to buy that because I thought it only covered the
> basics of Lua coding, like, not the C API... But now that you say it
> does, I have some questions:
>
> 1) What does it cover the most? I already know most of the "plain Lua"
> part of it, I've made 2 games for the PSP Lua Player.
> 2) Is it the best book about it out there?
>
> And back to the subject, it prints out just a number '1'... Looking at
> the code, it seems it can either be a userdata or a table, so it's a
> userdata... But what does the '1' mean?
>
> Thanks for everything, Mr. Smith!
>
> Wesley Smith wrote:
> > I would highly recommend picking up programming in Lua. It has all
> > kind of stuff in there like this. You will learn Lua much faster!
> >
> > int stackDump(lua_State *L)
> > {
> > int i;
> > int top = lua_gettop(L);
> >
> > printf("stack dump %d:\n", top);
> > for(i=top; i >= 1; i--) {
> > int t = lua_type(L, i);
> >
> > switch(t)
> > {
> > case LUA_TSTRING:
> > printf("%d \t'%s' string\n", i, lua_tostring(L, i));
> > break;
> >
> > case LUA_TBOOLEAN:
> > printf(lua_toboolean(L, i) ? "\ttrue\n" : "\tfalse\n");
> > break;
> >
> > case LUA_TNUMBER:
> > printf("%d \t'%f' number\n", i, lua_tonumber(L, i));
> > break;
> >
> > case LUA_TLIGHTUSERDATA:
> > printf("%d \t'%x'\n", i, lua_touserdata(L, i));
> > break;
> >
> > case LUA_TUSERDATA:
> > printf("%d ", i);
> > lua_getglobal(L, "print");
> > lua_pushvalue(L, i);
> > lua_call(L, 1, 0);
> > //printf("%d \t'%x %s'\n", i, lua_touserdata(L, i), T::name);
> > break;
> >
> > case LUA_TFUNCTION:
> > printf("%d \t'func: %x'\n", i, lua_tocfunction(L, i));
> > break;
> >
> > case LUA_TTABLE:
> > printf("%d ", i);
> > lua_getglobal(L, "print");
> > lua_pushvalue(L, i);
> > lua_call(L, 1, 0);
> > break;
> >
> > default:
> > printf("%d \t'%s'\n", i, lua_typename(L, t));
> > break;
> > }
> > }
> >
> > return 0;
> > }
> >
>
>