mirror of
https://github.com/lua/lua
synced 2024-11-25 22:29:39 +03:00
use appropriate macros to convert GCObject to specific types
This commit is contained in:
parent
7021cc9bc8
commit
14929f5764
11
lfunc.c
11
lfunc.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lfunc.c,v 2.40 2014/02/15 13:12:01 roberto Exp roberto $
|
** $Id: lfunc.c,v 2.41 2014/02/18 13:39:37 roberto Exp roberto $
|
||||||
** Auxiliary functions to manipulate prototypes and closures
|
** Auxiliary functions to manipulate prototypes and closures
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -21,14 +21,16 @@
|
|||||||
|
|
||||||
|
|
||||||
Closure *luaF_newCclosure (lua_State *L, int n) {
|
Closure *luaF_newCclosure (lua_State *L, int n) {
|
||||||
Closure *c = &luaC_newobj(L, LUA_TCCL, sizeCclosure(n))->cl;
|
GCObject *o = luaC_newobj(L, LUA_TCCL, sizeCclosure(n));
|
||||||
|
Closure *c = gco2cl(o);
|
||||||
c->c.nupvalues = cast_byte(n);
|
c->c.nupvalues = cast_byte(n);
|
||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Closure *luaF_newLclosure (lua_State *L, int n) {
|
Closure *luaF_newLclosure (lua_State *L, int n) {
|
||||||
Closure *c = &luaC_newobj(L, LUA_TLCL, sizeLclosure(n))->cl;
|
GCObject *o = luaC_newobj(L, LUA_TLCL, sizeLclosure(n));
|
||||||
|
Closure *c = gco2cl(o);
|
||||||
c->l.p = NULL;
|
c->l.p = NULL;
|
||||||
c->l.nupvalues = cast_byte(n);
|
c->l.nupvalues = cast_byte(n);
|
||||||
while (n--) c->l.upvals[n] = NULL;
|
while (n--) c->l.upvals[n] = NULL;
|
||||||
@ -93,7 +95,8 @@ void luaF_close (lua_State *L, StkId level) {
|
|||||||
|
|
||||||
|
|
||||||
Proto *luaF_newproto (lua_State *L) {
|
Proto *luaF_newproto (lua_State *L) {
|
||||||
Proto *f = &luaC_newobj(L, LUA_TPROTO, sizeof(Proto))->p;
|
GCObject *o = luaC_newobj(L, LUA_TPROTO, sizeof(Proto));
|
||||||
|
Proto *f = gco2p(o);
|
||||||
f->k = NULL;
|
f->k = NULL;
|
||||||
f->sizek = 0;
|
f->sizek = 0;
|
||||||
f->p = NULL;
|
f->p = NULL;
|
||||||
|
10
lstring.c
10
lstring.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lstring.c,v 2.38 2014/03/19 18:51:42 roberto Exp roberto $
|
** $Id: lstring.c,v 2.39 2014/04/02 16:44:42 roberto Exp roberto $
|
||||||
** String table (keeps all strings handled by Lua)
|
** String table (keeps all strings handled by Lua)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -90,9 +90,11 @@ void luaS_resize (lua_State *L, int newsize) {
|
|||||||
static TString *createstrobj (lua_State *L, const char *str, size_t l,
|
static TString *createstrobj (lua_State *L, const char *str, size_t l,
|
||||||
int tag, unsigned int h) {
|
int tag, unsigned int h) {
|
||||||
TString *ts;
|
TString *ts;
|
||||||
|
GCObject *o;
|
||||||
size_t totalsize; /* total size of TString object */
|
size_t totalsize; /* total size of TString object */
|
||||||
totalsize = sizeof(TString) + ((l + 1) * sizeof(char));
|
totalsize = sizeof(TString) + ((l + 1) * sizeof(char));
|
||||||
ts = &luaC_newobj(L, tag, totalsize)->ts;
|
o = luaC_newobj(L, tag, totalsize);
|
||||||
|
ts = rawgco2ts(o);
|
||||||
ts->tsv.len = l;
|
ts->tsv.len = l;
|
||||||
ts->tsv.hash = h;
|
ts->tsv.hash = h;
|
||||||
ts->tsv.extra = 0;
|
ts->tsv.extra = 0;
|
||||||
@ -165,9 +167,11 @@ TString *luaS_new (lua_State *L, const char *str) {
|
|||||||
|
|
||||||
Udata *luaS_newudata (lua_State *L, size_t s) {
|
Udata *luaS_newudata (lua_State *L, size_t s) {
|
||||||
Udata *u;
|
Udata *u;
|
||||||
|
GCObject *o;
|
||||||
if (s > MAX_SIZE - sizeof(Udata))
|
if (s > MAX_SIZE - sizeof(Udata))
|
||||||
luaM_toobig(L);
|
luaM_toobig(L);
|
||||||
u = &luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s)->u;
|
o = luaC_newobj(L, LUA_TUSERDATA, sizeof(Udata) + s);
|
||||||
|
u = rawgco2u(o);
|
||||||
u->uv.len = s;
|
u->uv.len = s;
|
||||||
u->uv.metatable = NULL;
|
u->uv.metatable = NULL;
|
||||||
setuservalue(L, u, luaO_nilobject);
|
setuservalue(L, u, luaO_nilobject);
|
||||||
|
5
ltable.c
5
ltable.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: ltable.c,v 2.88 2014/04/15 16:32:49 roberto Exp roberto $
|
** $Id: ltable.c,v 2.89 2014/05/26 17:10:22 roberto Exp roberto $
|
||||||
** Lua tables (hash)
|
** Lua tables (hash)
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -383,7 +383,8 @@ static void rehash (lua_State *L, Table *t, const TValue *ek) {
|
|||||||
|
|
||||||
|
|
||||||
Table *luaH_new (lua_State *L) {
|
Table *luaH_new (lua_State *L) {
|
||||||
Table *t = &luaC_newobj(L, LUA_TTABLE, sizeof(Table))->h;
|
GCObject *o = luaC_newobj(L, LUA_TTABLE, sizeof(Table));
|
||||||
|
Table *t = gco2t(o);
|
||||||
t->metatable = NULL;
|
t->metatable = NULL;
|
||||||
t->flags = cast_byte(~0);
|
t->flags = cast_byte(~0);
|
||||||
t->array = NULL;
|
t->array = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user