[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Hi and pushing existing UserData from pointer
- From: Chris Camacho <c.camacho@...>
- Date: Sun, 16 Aug 2009 18:22:46 +0100
Be careful. Lightuserdata all share the same metatable. This may not be your intent.
By adding the "cpShape" metatable I can use the "cpShape" methods
it is defiantly returning the correct pointer as the right object reacts
when I use that userdata's methods, how can what I'm returning
to lua be sharing the same metatable if I can call a method that's
unique to cpShape???
My approach to your problem would be to make a userdata the size of your pointer and then
essentially use double indirection on any appropriate pointer you receive.
really? that seems a lot of work (there must be something easier and
more elegant!)
Best
Chris
delbu9c1@erau.edu wrote:
Be careful. Lightuserdata all share the same metatable. This may not be your intent.
Lightuserdata does not create any kind of proxy. It is a pointer and that's it.
My approach to your problem would be to make a userdata the size of your pointer and then essentially use double indirection on any appropriate pointer you receive.
Matt
------Original Message------
From: Chris Camacho
Sender: lua-bounces@bazar2.conectiva.com.br
To: Lua list
ReplyTo: Lua list
Subject: Re: Hi and pushing existing UserData from pointer
Sent: Aug 16, 2009 9:49 AM
Im not too sure what you're getting at, however
I have found one answer....
lua_pushlightuserdata(L, a);
luaL_getmetatable(L, "cpShape");
lua_setmetatable(L, -2);
does actually work! I'm getting userdata of the appropriate
type and if I add an impulse to the colliding shape the correct
body moves so the above *must* be passing a userdata reference
correctly, although what I suspect I'm doing is making a
dummy user data with the pointer inside ???
(This and some other "types" I'm going to remove from the
lua GC, in any case as it make more sense to pass back these
objects back to the library when you want to remove them
from the simulation)
Can you explain your method? can you provide a simple
code example that shows your technique working?
Best
Chris
Tony Finch wrote:
On Sun, 16 Aug 2009, Chris Camacho wrote:
Is there any way to make a new userdata that is a reference to an
already allocated userdata from just a C pointer?
Create a weak table mapping lightuserdata to the full userdata. You can
convert a C pointer directly to a lightuserdata which you can use to index
the table. The table must have weak values so that your objects are still
collected. Lightuserdata doesn't affect collection of the objects it
points to.
Tony.
--
Disclaimer:
By sending an email to ANY of my addresses you are agreeing that:
1. I am by definition, "the intended recipient"
2. All information in the email is mine to do with as I see fit and
make such financial profit, political mileage, or good joke as it lends
itself to. In particular, I may quote it where I please.
3. I may take the contents as representing the views of your company.
4. This overrides any disclaimer or statement of confidentiality that
may be included on your message.