Why does not replace the return value type(i.e. GCobject*) of luaC_newobj() function with the type of union GCunion* to avoid the explicit cast(i.e. gco2t, gco2p, gco2u and etc)?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Why does not replace the return value type(i.e. GCobject*) of luaC_newobj() function with the type of union GCunion* to avoid the explicit cast(i.e. gco2t, gco2p, gco2u and etc)?

孙世龙 sunshilong
Hi, list

Why does not replace the return value type(i.e. GCobject*) of
luaC_newobj() function with the type of union GCunion* to avoid
calling the explicit cast(i.e. gco2t, gco2p, gco2u and etc.) and make
the code more concise?

It's likely that there are some aspects where I have not kept pace.
So please let me know if I missed something.

Here are some related code snippets:
Table *luaH_new (lua_State *L)
{
  GCObject *o = luaC_newobj(L, LUA_VTABLE, sizeof(Table));
  Table *t = gco2t(o);
   ...
}

CClosure *luaF_newCclosure (lua_State *L, int nupvals)
{
  GCObject *o = luaC_newobj(L, LUA_VCCL, sizeCclosure(nupvals));
  CClosure *c = gco2ccl(o);
  ...
}

static TString *createstrobj (lua_State *L, size_t l, int tag, unsigned int h)
{
  TString *ts;
  GCObject *o;
  size_t totalsize;  /* total size of TString object */
  totalsize = sizelstring(l);
  o = luaC_newobj(L, tag, totalsize);
  ts = gco2ts(o);
 ...
}

I would be grateful to have some help with this question.
Best regards
Sunshilong
Reply | Threaded
Open this post in threaded view
|

Re: Why does not replace the return value type(i.e. GCobject*) of luaC_newobj() function with the type of union GCunion* to avoid the explicit cast(i.e. gco2t, gco2p, gco2u and etc)?

Ranier Vilela-2
Em qui., 22 de out. de 2020 às 23:14, 孙世龙 sunshilong <[hidden email]> escreveu:
Hi, list

Why does not replace the return value type(i.e. GCobject*) of
luaC_newobj() function with the type of union GCunion* to avoid
Are you suggesting creating a new type?
GCunion* 

calling the explicit cast(i.e. gco2t, gco2p, gco2u and etc.) and make
the code more concise?
Can you elaborate a small example?
 
regards,
Ranier Vilela