Lunatic: properly protect weapondata_t members, fix Lua->CON line mapping.

Also, make -Werror-bad-getactorvar disabled by default.

git-svn-id: https://svn.eduke32.com/eduke32@3574 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2013-03-18 22:05:26 +00:00
parent c397759217
commit cec987631a
3 changed files with 41 additions and 24 deletions

View file

@ -314,24 +314,24 @@ labels =
wdata_members =
{
-- NOTE: they are lowercased for Lunatic
"int32_t workslike",
"const int32_t _workslike",
"int32_t clip",
"int32_t reload",
"int32_t firedelay",
"int32_t totaltime",
"int32_t holddelay",
"int32_t flags",
"int32_t shoots",
"const int32_t _shoots",
"int32_t spawntime",
"int32_t spawn",
"const int32_t _spawn",
"int32_t shotsperburst",
"int32_t initialsound",
"int32_t firesound",
"int32_t sound2time",
"int32_t sound2sound",
"int32_t reloadsound1",
"int32_t reloadsound2",
"int32_t selectsound",
"const int32_t _initialsound",
"const int32_t _firesound",
"int32_t sound2time", -- NOTE: this is a time number, not a sound
"const int32_t _sound2sound",
"const int32_t _reloadsound1",
"const int32_t _reloadsound2",
"const int32_t _selectsound",
"int32_t flashcolor",
}

View file

@ -299,6 +299,9 @@ struct {
}
]]
-- KEEPINSYNC weapondata_mt below.
local WEAPONDATA_STRUCT = "struct {"..table.concat(con_lang.wdata_members, ';').."; }"
local randgen = require("randgen")
local geom = require("geom")
@ -735,6 +738,7 @@ end
local actor_ptr_ct = ffi.typeof("$ *", ffi.typeof(strip_const(ACTOR_STRUCT)))
local player_ptr_ct = ffi.typeof("$ *", ffi.typeof(strip_const(DUKEPLAYER_STRUCT)))
local projectile_ptr_ct = ffi.typeof("$ *", ffi.typeof(strip_const(PROJECTILE_STRUCT)))
local weapondata_ptr_ct = ffi.typeof("$ *", ffi.typeof(strip_const(WEAPONDATA_STRUCT)))
local con_action_ct = ffi.typeof("con_action_t")
local con_move_ct = ffi.typeof("con_move_t")
local con_ai_ct = ffi.typeof("con_ai_t")
@ -914,16 +918,25 @@ ffi.metatype("actor_t", actor_mt)
local weapondata_mt = {
__newindex = function(wd, member, val)
if (string.match(member, "sound")) then
-- TODO: set to 0 if oob? (e.g. CrackDown)
if (val < 0) then
val = 0 -- Set to 0 if oob (e.g. CrackDown).
else
check_sound_idx(val)
end
elseif (member=="workslike") then
check_weapon_idx(val)
elseif (member=="shoots" or member=="spawn") then
-- TODO: set to 0 if oob? (e.g. AMC TC)
elseif (member=="spawn" or member=="shoots") then
if (val < 0) then
-- Set to 0 if oob (e.g. CrackDown). This is a bit problematic
-- for .shoots because it's used unconditionally except in one
-- case (see player.c).
val = 0
else
check_tile_idx(val)
end
end
wd[member] = val
ffi.cast(weapondata_ptr_ct, wd)['_'..member] = val
end,
}
ffi.metatype("weapondata_t", weapondata_mt)

View file

@ -98,7 +98,7 @@ local g_defaultDir = nil
-- -Wno-bad-identifier for disabling the "bad identifier" warning.
local g_warn = { ["not-redefined"]=true, ["bad-identifier"]=false,
["number-conversion"]=true, ["system-gamevar"]=true,
["error-bad-getactorvar"]=true, }
["error-bad-getactorvar"]=false, }
-- Code generation and output options.
local g_cgopt = { ["no"]=false, ["debug-lineinfo"]=false, ["gendir"]=nil,
@ -160,6 +160,8 @@ local function PLSX(s) return "player[_pli]"..s end
local function getlinecol(pos) end -- fwd-decl
local function new_initial_codetab()
-- NOTE: Keep this one line per line to not confuse the Lua->CON line
-- mapping system.
return {
"local _con, _bit, _math = require'con', require'bit', require'math';",
"local _xmath, _geom = require'xmath', require'geom';",
@ -175,10 +177,9 @@ local function new_initial_codetab()
-- Static ivec3s so that no allocations need to be made.
"local _IVEC = { _geom.ivec3(), _geom.ivec3() }",
[[local function _IV(num, x, y, z)
local v=_IVEC[num]; v.x=x; v.y=y; v.z=z; return v;
end
]],
"local function _IV(num, x, y, z)",
" local v=_IVEC[num]; v.x=x; v.y=y; v.z=z; return v;",
"end",
}
end
@ -282,7 +283,8 @@ local function new_initial_gvartab()
for w=0,MAX_WEAPONS-1 do
for i=1,#wmembers do
local member = wmembers[i]:gsub(".* ","") -- strip e.g. "int32_t "
local member = wmembers[i]:gsub(".*_t ","") -- strip e.g. "const int32_t "
:gsub("^_","") -- strip potentially leading underscore
local name = format("WEAPON%d_%s", w, member:upper())
gamevar[name] = PRW(format(PLSX".weapon[%d].%s", w, member))
@ -1106,15 +1108,17 @@ function Cmd.gamevar(identifier, initval, flags)
bit.tohex(bit.band(ogv.rbits, initval)), identifier)
end
local linestr = "--"..getlinecol(g_lastkwpos)
-- Emit code to set the variable at Lua parse time.
if (bit.band(oflags, GVFLAG.PERPLAYER) ~= 0) then
-- Replace player index by 0.
-- TODO_MP: init for all players.
local pvar, numrepls = ogv.name:gsub("_pli", "0")
assert(numrepls>=1)
addcodef("%s=%d", pvar, initval)
addcodef("%s=%d%s", pvar, initval, linestr)
else
addcodef("%s=%d", ogv.name, initval)
addcodef("%s=%d%s", ogv.name, initval, linestr)
end
return
end