diff --git a/polymer/eduke32/source/lunatic/control.lua b/polymer/eduke32/source/lunatic/control.lua index 1d181411e..4287f3bf1 100644 --- a/polymer/eduke32/source/lunatic/control.lua +++ b/polymer/eduke32/source/lunatic/control.lua @@ -903,7 +903,7 @@ end function _digitalnumber(tilenum, x, y, num, shade, pal, orientation, cx1, cy1, cx2, cy2, zoom) - if (not (tilenum >= 0 and tilenum >= ffiC.MAXTILES-9)) then + if (not (tilenum >= 0 and tilenum < ffiC.MAXTILES-9)) then error("invalid base tile number "..tilenum, 2) end diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 9d029859f..7d076edfe 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -749,6 +749,7 @@ end local player_static_members = {} +--[[ player_static_members._INPUT_BITS = defs_c.conststruct { JUMP = 1, @@ -791,6 +792,7 @@ player_static_members._INPUT_EXT_BITS = defs_c.conststruct TURN_LEFT = 16, TURN_RIGHT = 32, } +--]] local band = bit.band local lsh = bit.lshift @@ -2424,17 +2426,17 @@ end --printkv('_G AFTER DECLS', _G) +local index_error_mt = { + __index = function(_, key) + error("attempt to read undeclared variable '"..key.."'", 2) + end, + + __metatable = true, +} -- PiL 14.2 continued -- We need this at the end because we were previously doing just that! -setmetatable( - G_, { - __index = function (_, n) - error("attempt to read undeclared variable '"..n.."'", 2) - end, - - __metatable = true, - }) +setmetatable(G_, index_error_mt) local global_mt = { __index = G_, @@ -2479,6 +2481,9 @@ if (concode) then table.remove(modname_stack) local function protect_con_table(tab) + -- NOTE: Some of our code specifically excepts the name tables to be + -- indexable with nonexistent keys. See e.g. control.c: _A_SpawnGlass() +-- tab = setmetatable(tab, index_error_mt) return setmtonce({}, { __index=tab, __newindex=basemod_newidx }) end diff --git a/polymer/eduke32/source/lunatic/defs_common.lua b/polymer/eduke32/source/lunatic/defs_common.lua index f06ed80d2..7ffc76324 100644 --- a/polymer/eduke32/source/lunatic/defs_common.lua +++ b/polymer/eduke32/source/lunatic/defs_common.lua @@ -897,6 +897,18 @@ local bitar = require("bitar") -- machines. This sucks. static_members.sector.showbitmap = bitar.new(ffiC.MAXSECTORS-1, ffi.cast("int32_t *", ffiC.show2dsector)) +local function iter_allsprites(_, curi) + for i=curi+1,ffiC.MAXSPRITES-1 do + if (ffiC.sprite[i].statnum ~= ffiC.MAXSTATUS) then + return i + end + end +end + +function static_members.sprite.all() + return iter_allsprites, nil, -1 +end + local sms = static_members.sprite sms._headspritesect = creategtab(ffiC.headspritesect, ffiC.MAXSECTORS, 'headspritesect[]') -- NOTE: don't allow freelist access diff --git a/polymer/eduke32/source/lunatic/doc/lunatic.txt b/polymer/eduke32/source/lunatic/doc/lunatic.txt index 38e5a441e..fadf11e03 100644 --- a/polymer/eduke32/source/lunatic/doc/lunatic.txt +++ b/polymer/eduke32/source/lunatic/doc/lunatic.txt @@ -812,6 +812,10 @@ _`index_of_spr`_ is the sprite index corresponding to `spr`. This method is provided for convenience, but may be slower than the static function `updatesect`. +===== `sprite` iterators + ++*for* i *in* sprite.all()+:: +Iterates over all sprites currently in the game world. ===== `sprite` static functions diff --git a/polymer/eduke32/source/lunatic/test.lua b/polymer/eduke32/source/lunatic/test.lua index 4f85bce32..36ae83852 100644 --- a/polymer/eduke32/source/lunatic/test.lua +++ b/polymer/eduke32/source/lunatic/test.lua @@ -226,6 +226,7 @@ gameevent{gv.EVENT_JUMP, end } +--[[ gameevent { "PROCESSINPUT", @@ -244,6 +245,7 @@ gameevent end end } +--]] local D = require("CON.DEFS") local WEAPON = gv.WEAPON