lua-users home
lua-l archive

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


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.