diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index a58fec931..d34e706bb 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -951,8 +951,8 @@ end local tile_static_members = defs_c.static_members_tab() do - tile_static_members.sizx = defs_c.creategtab(ffiC.tilesizx, ffiC.MAXTILES, "tilesizx[]") - tile_static_members.sizy = defs_c.creategtab(ffiC.tilesizy, ffiC.MAXTILES, "tilesizy[]") + tile_static_members.sizx = defs_c.creategtab_membidx(ffiC.tilesiz, "x", ffiC.MAXTILES, "tilesizx[]") + tile_static_members.sizy = defs_c.creategtab_membidx(ffiC.tilesiz, "y", ffiC.MAXTILES, "tilesizy[]") end -- XXX: error message will say "g_player_ps" diff --git a/polymer/eduke32/source/lunatic/defs_common.lua b/polymer/eduke32/source/lunatic/defs_common.lua index e36be26cc..cf7405597 100644 --- a/polymer/eduke32/source/lunatic/defs_common.lua +++ b/polymer/eduke32/source/lunatic/defs_common.lua @@ -444,7 +444,7 @@ int32_t guniqhudid; const int16_t headspritesect[MAXSECTORS+1], headspritestat[MAXSTATUS+1]; const int16_t prevspritesect[MAXSPRITES], prevspritestat[MAXSPRITES]; const int16_t nextspritesect[MAXSPRITES], nextspritestat[MAXSPRITES]; -const int16_t tilesizx[MAXTILES], tilesizy[MAXTILES]; +const vec2_t tilesiz[MAXTILES]; uint8_t show2dsector[(MAXSECTORS+7)>>3]; @@ -849,7 +849,7 @@ end ---- indirect C array access ---- --- create a safe indirection for an ffi.C array +-- Create a safe indirection for an ffi.C array. function creategtab(ctab, maxidx, name) local tab = {} local tmpmt = { @@ -867,6 +867,25 @@ function creategtab(ctab, maxidx, name) return setmtonce(tab, tmpmt) end +-- Create a a safe indirection for an ffi.C struct array, accessing a given +-- member. +function creategtab_membidx(ctab, membname, maxidx, name) + local tab = {} + local tmpmt = { + __index = function(tab, key) + if (key>=0 and key < maxidx) then + return ctab[key][membname] + end + error('out-of-bounds '..name..' read access', 2) + end, + __newindex = function() + error('cannot write directly to '..name, 2) + end, + } + + return setmtonce(tab, tmpmt) +end + -- Construct const struct from table function conststruct(tab) local strtab = { "struct {" } diff --git a/polymer/eduke32/source/lunatic/dynsymlist b/polymer/eduke32/source/lunatic/dynsymlist index de3de841c..8b87ff7fa 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist +++ b/polymer/eduke32/source/lunatic/dynsymlist @@ -46,8 +46,7 @@ prevspritesect; prevspritestat; nextspritesect; nextspritestat; -tilesizx; -tilesizy; +tilesiz; show2dsector; diff --git a/polymer/eduke32/source/lunatic/dynsymlist_m32 b/polymer/eduke32/source/lunatic/dynsymlist_m32 index 040ba9f57..27d17d4b6 100644 --- a/polymer/eduke32/source/lunatic/dynsymlist_m32 +++ b/polymer/eduke32/source/lunatic/dynsymlist_m32 @@ -46,8 +46,7 @@ prevspritesect; prevspritestat; nextspritesect; nextspritestat; -tilesizx; -tilesizy; +tilesiz; show2dsector;