lua-users home
lua-l archive

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


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));
	lua_pushlightuserdata(lua,line)
	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
<quangnd412@yahoo.ca> wrote:
> Hi,
> I have a big problem with passing pinter to LUA. In LUA documents, they say
> that programers can use LUA number (in fact a double type!) but it sounds
> not safe at all when storing pointer in a double number form! How can I
> solve this problem?
> 
> 


-- 
Best regards,
Zigmar