[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Pass pointer into LUA
- From: "Nguyen Dang Quang" <quangnd412@...>
- Date: Fri, 1 Apr 2005 08:26:44 +0700
Hi Pavel Antokolsky,
Thank for replying me. Could you send me a sample code in with you pass
an pointer to LUA and LUA store it in a variable and then LUA pass back this
pointer to other C pointer. Thank you very much.
----- Original Message -----
From: "Pavel Antokolsky aka Zigmar" <email@example.com>
To: "Lua list" <firstname.lastname@example.org>
Sent: Thursday, March 31, 2005 7:00 PM
Subject: Re: Pass pointer into LUA
> There is no need to use numerical type to store pointer, and sure it
> unsafe. There is a special datatype for passing pointers into lua:
> "light userdata".
> For more documentation see "lua_pushlightuserdata" and #28.5 in
> "Programming in Lua book".
> Here is a small code snipplet:
> The function exported to Lua that creates C++ object and returns
> userdata with pointer to it:
> int LuaCanvas::line_new (lua_state *lua)
> QCanvasLine *line = new QCanvasLine(getCanvas(lua));
> return 1;
> "getCanvas()" function retrivies the pointer to LuaCanvas object (the
> exported method is static) stored in lua registry. If you are
> interested, I can also send you a snippled how this pointer is stored
> and retrivied.
> On Thu, 31 Mar 2005 16:35:15 +0700, Nguyen Dang Quang
> <email@example.com> wrote:
> > Hi,
> > I have a big problem with passing pinter to LUA. In LUA documents, they
> > that programers can use LUA number (in fact a double type!) but it
> > not safe at all when storing pointer in a double number form! How can I
> > solve this problem?
> Best regards,