Turn the lua sector lines hack into a macro
This commit is contained in:
parent
15008f31a7
commit
8bc8946be8
|
@ -371,4 +371,12 @@ typedef UINT32 tic_t;
|
||||||
#define WSTRING2(s) L ## s
|
#define WSTRING2(s) L ## s
|
||||||
#define WSTRING(s) WSTRING2 (s)
|
#define WSTRING(s) WSTRING2 (s)
|
||||||
|
|
||||||
|
/*
|
||||||
|
A hack by Monster Iestyn: Return a pointer to a field of
|
||||||
|
a struct from a pointer to another field in the struct.
|
||||||
|
Needed for some lua shenanigans.
|
||||||
|
*/
|
||||||
|
#define FIELDFROM( type, field, have, want ) \
|
||||||
|
(void *)((intptr_t)(field) - offsetof (type, have) + offsetof (type, want))
|
||||||
|
|
||||||
#endif //__DOOMTYPE__
|
#endif //__DOOMTYPE__
|
||||||
|
|
|
@ -447,7 +447,7 @@ static int sectorlines_get(lua_State *L)
|
||||||
// get the "linecount" by shifting our retrieved memory address of "lines" to where "linecount" is in the sector_t, then dereferencing the result
|
// get the "linecount" by shifting our retrieved memory address of "lines" to where "linecount" is in the sector_t, then dereferencing the result
|
||||||
// we need this to determine the array's actual size, and therefore also the maximum value allowed as an index
|
// we need this to determine the array's actual size, and therefore also the maximum value allowed as an index
|
||||||
// this only works if seclines is actually a pointer to a sector's lines member in memory, oh boy
|
// this only works if seclines is actually a pointer to a sector's lines member in memory, oh boy
|
||||||
numoflines = (size_t)(*(size_t *)(((size_t)seclines) - (offsetof(sector_t, lines) - offsetof(sector_t, linecount))));
|
numoflines = *(size_t *)FIELDFROM (sector_t, seclines, lines,/* -> */linecount);
|
||||||
|
|
||||||
/* OLD HACK
|
/* OLD HACK
|
||||||
// check first linedef to figure which of its sectors owns this sector->lines pointer
|
// check first linedef to figure which of its sectors owns this sector->lines pointer
|
||||||
|
|
Loading…
Reference in a new issue