From a4510e35a19cfe3d1f6fd03a8027131f721c1fb0 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Tue, 24 Dec 2013 09:44:19 +0000 Subject: [PATCH] Lunatic: error on invalid static data read like 'sprite.picnum'. git-svn-id: https://svn.eduke32.com/eduke32@4209 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/defs.ilua | 7 ++++--- polymer/eduke32/source/lunatic/defs_common.lua | 18 +++++++++++++++++- polymer/eduke32/source/lunatic/doc/lunatic.txt | 8 ++++---- polymer/eduke32/source/lunatic/test.lua | 3 +++ 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index e79f81e4f..3a296c4c5 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -755,7 +755,7 @@ end --== "player" global, needed by the "control" module ==-- -local player_static_members = {} +local player_static_members = defs_c.static_members_tab() --[[ player_static_members._INPUT_BITS = defs_c.conststruct @@ -837,7 +837,7 @@ end local player_holdskey = player_static_members.holdskey -- Actor flags -local actor_static_members = {} +local actor_static_members = defs_c.static_members_tab() do local our_SFLAG = {} local ext_SFLAG = con_lang.labels[4] -- external actor flags only @@ -923,7 +923,7 @@ function actor_static_members.delete(i) CF.A_DeleteSprite(i) end -local tile_static_members = {} +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[]") @@ -2430,6 +2430,7 @@ if (ffiC._DEBUG_LUNATIC ~= 0) then local codestr = [[ do local _bit,_math=require'bit',require'math' + local _con=require'con' local _band,_gv=_bit.band,gv local tmp=]].. membaccode:gsub("%%s","0").." end" diff --git a/polymer/eduke32/source/lunatic/defs_common.lua b/polymer/eduke32/source/lunatic/defs_common.lua index 0ee2a3030..0bac657cc 100644 --- a/polymer/eduke32/source/lunatic/defs_common.lua +++ b/polymer/eduke32/source/lunatic/defs_common.lua @@ -878,9 +878,25 @@ function conststruct(tab) return ffi.new(table.concat(strtab)) end +do + local smt_mt = { + __index = function() + error("invalid access to static data", 2) + end + } + + function static_members_tab() + return setmtonce({}, smt_mt) + end +end + -- Static, non-instance members. Used to hold constants, for example -- sprite.CSTAT.TRANS1 -local static_members = { sector={}, wall={}, sprite={} } +local static_members = { + sector = static_members_tab(), + wall = static_members_tab(), + sprite = static_members_tab(), +} static_members.sector.STAT = conststruct { diff --git a/polymer/eduke32/source/lunatic/doc/lunatic.txt b/polymer/eduke32/source/lunatic/doc/lunatic.txt index c0cbb37b6..4bda2dcc9 100644 --- a/polymer/eduke32/source/lunatic/doc/lunatic.txt +++ b/polymer/eduke32/source/lunatic/doc/lunatic.txt @@ -1769,10 +1769,10 @@ The total number of frames in the animation. The number of consecutive tiles used to construct one frame of the animation, as viewed from different angles. Valid values are 1, 3, 5, 7 and 8. In addition, -5 and -7 are allowed, which behave like the corresponding positive -++viewtype++s, but effectively mirror the actor on the vertical axis. This can -be useful if tile data is available that has the opposite orientation of what -EDuke32 uses. See the {wiki_action}[Action entry] in the EDuke32 wiki for how -the views are constructed for different `viewtype` values. +++viewtype++s, but effectively mirror the actor around the vertical axis. This +can be useful if tile data is available that has the opposite orientation of +what EDuke32 uses. See the {wiki_action}[Action entry] in the EDuke32 wiki for +how the views are constructed for different `viewtype` values. `[4] incval` (default: 1):: The value to add the actor's _current frame_ on each frame advance. May be -1, diff --git a/polymer/eduke32/source/lunatic/test.lua b/polymer/eduke32/source/lunatic/test.lua index 19042b882..9ccca9bb9 100644 --- a/polymer/eduke32/source/lunatic/test.lua +++ b/polymer/eduke32/source/lunatic/test.lua @@ -141,6 +141,9 @@ gameevent -- actor[].t_data[] is not accessible for now checkfail('local i = actor[0].t_data[15]', "has no member named 't_data'") + + -- sprite.picnum may happen as a thinko/typo kind of error (spr.picnum was meant) + checkfail("local pic = sprite.picnum", "invalid access to static data") end }