lua-users home
lua-l archive

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



You can use lua_pushvalue to duplicate the reference to the userdata
on the stack. Then you can save one in the weak table (with the light
userdata key), and do whatever you want with the other one.
 char buf[40];
 cpBody *bb = (cpBody *)lua_newuserdata(L, sizeof(cpBody));
 lua_pushvalue(L,-1);
 lua_pushstring(L,"__cpBody_ptrs");
 sprintf(buf,"%ld\0",(long)bb);
 lua_setfield(L,-2,buf);

 luaL_getmetatable(L, "cpBody");
 lua_setmetatable(L, -2);
 return bb;

what on earth does attempt to index a userdata value mean?

Thanks
Chris


--
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.