typedef struct _wax_instance_userdata {
id instance;
BOOL isClass;
Class isSuper;
BOOL actAsSuper;
} wax_instance_userdata;
https://github.com/probablycorey/wax/blob/master/lib/wax_helpers.m#L497
void* afunc(){ // the function is too long
void *value = nil;
// ...
wax_instance_userdata *instanceUserdata = (wax_instance_userdata *)luaL_checkudata(L, stackIndex, WAX_INSTANCE_METATABLE_NAME);
instance = instanceUserdata->instance;
*(id *)value = instance;
return value;
}
https://github.com/probablycorey/wax/blob/master/lib/wax.m#L243
id* ret = afunc(); //same without this * .
id lastValue = *(id*)ret;
//now I can use lastValue;
Why need do this ?
I can’t understand the *(id*)
also the id* ret = afunc() ,when delete this star , it also works well.
afunc is referencing the function (void *)wax_copyToObjc(…). The intent of this function is to translate a Lua object into a C or Objective-C value. Because it could be a primitive type or an objective-c instance it doesn’t know what it is going to return. So always returns a pointer to void (meaning a pointer to something unknown). In the case of an id, it will return a pointer to an id.
It might be easier to explain what is happening with an int, it will alloc space for the int and copy the its value:
(int *)value is translates to “value is a pointer to an int”
adding the * in front of it like
*(int *)valuetranslates to “copy the int to the alloc’d memory that value points to.”In your example: