[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Hi and pushing existing UserData from pointer
- From: Chris Camacho <c.camacho@...>
- Date: Sun, 16 Aug 2009 10:36:44 +0100
Hi all!
First off nice language! nice and light, reasonably fast and yet small,
without being crippled....
I'm wrapping a library and have a good portion done, I've used user
data, so that I have newly created objects from the C library collected
by lua's GC (nice!)
All is working well as I'm just creating new instances and returning
them, basically very much like this
http://lua-users.org/wiki/UserDataExample
I can set up from lua a callback by having a kind of callback proxy in C
which actually receives the callback and then runs the appropriate lua
function
The Lua call back function needs to receive some references to userdata
objects that are already in existence and all I have for them is the C
pointer to the structure I've wrapped.
At the moment I can see different return values from different lua
callback functions but I cannot send them useful information!
heres what I have after trying many different things, (as a result its a
mess!)
I can pass a number as a parameter and all works as it should
void* d; // temp will live in void* data with other stuff
int CollFunc(cpShape *a, cpShape *b, cpContact *contacts, int
numContacts, cpFloat normal_coef, void *data) {
lua_getglobal(d,data); // routine name will be inside struct pointer
to callback data
// lua_pushlightuserdata(d, a);
lua_pushvalue(d,(void*)a);
luaL_getmetatable(d, "cpShape"); // luaL_pushUDfromPointer((void*)a)!
lua_setmetatable(d, -2);
// lua_pushlightuserdata(d, b);
lua_pcall(d, 1, 1, 0);
int r=lua_toboolean(d,1);
lua_pop(d,1);
return r;
}
Is there any way to make a new userdata that is a reference to an
already allocated userdata from just a C pointer?
I did google but couldn't really find too much
(I will do a quick wiki page on this once I understand how to do it...)
Best
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.