lua-users home
lua-l archive

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


Hi,

Some very strange behavior (to a Lua novice that is!:-)...

In My Lua Script I have an "OnEvent" function that is called from my C++ app
on, well, as event...

It stores the app-returned userdata in a table.

A further app-called function gets previously stored data from the table &
tries to use it. Kaboom!

The userdata is returned from an instantiation method created by toLua. The
value returned from toLua works fine (I can make class method calls with no
problems)

I store the userdata in a table.

later on the app calls the draw function and retrieves the userdata stored
previously. The "value" is different & it will crash if I try to use it as
the previous usertype.

>From poking around it seems that userdata is a kind of 'object' - so I
thought I might need some other method on the userdat to get to the actual
raw data. When I tried looking for metamathods there were none.

I dont know enough about lua to know where to go from here...

Help!:-)

Andy




<--------------- Lua Script --------------->

------------------------------------------
-- some globals
------------------------------------------
verts		= {}
num_verts	= 0


------------------------------------------
-- onEvent function
-- called from app
------------------------------------------
function onEvent()

	-- create a manuipulator at the coordinate position
	handle_box = manipulator:create()

	-- call methods on the manipulator class
	-- everything works fine

	-- this prints: "userdata: 012BE288"
	print("On Create handle_box: "..tostring(handle_box).."\n")

	-- now store the userdata
      num_verts = num_verts + 1
	verts[num_verts] = handle_box
end



------------------------------------------
-- onDraw function
-- called from app
------------------------------------------
function onDraw()
	if num_verts > 0 then
		for i=1,num_verts do

			handle_box = verts[i]

			-- this prints: "userdata: 012BC270"
			print("In Draw handle_box: "..tostring(handle_box).."\n")

			handle_box:draw()

		end
	end
end


<--------------- Lua Script --------------->