From 3a85134e31dded7e62297131870a927d3deecf44 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 24 Jan 2014 21:39:04 +0000 Subject: [PATCH] LunaCON: add codegen option -fbad-getactorvar-use-pli for C-CON compatibility. Also, improve -Wnumber-conversion warning by printing the resulting number. BUILD_LUNATIC. git-svn-id: https://svn.eduke32.com/eduke32@4266 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/doc/lunacon.txt | 11 +++++++++-- polymer/eduke32/source/lunatic/lunacon.lua | 17 +++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/polymer/eduke32/source/lunatic/doc/lunacon.txt b/polymer/eduke32/source/lunatic/doc/lunacon.txt index c4dc4d9e9..54de10c7f 100644 --- a/polymer/eduke32/source/lunatic/doc/lunacon.txt +++ b/polymer/eduke32/source/lunatic/doc/lunacon.txt @@ -127,8 +127,9 @@ one. When enabled, produces an error whenever a global or per-player gamevar is attempted to be read using ++getactorvar++. Otherwise, a warning is emitted. In this case, the generated code is either a read of the (global) gamevar, or an -access of the per-player gamevar with an actor index, which is probably not -what the coder intended. +access of the per-player gamevar with the given index or the current player +index (depending on `-fbad-getactorvar-use-pli`), which is probably not what +the coder intended. `-Wnot-redefined` (default: on):: Warns whenever a `define` directive was ignored because it attempted to @@ -167,6 +168,12 @@ If enabled, an attempt to call a `state` that was not previously defined results in an error. Otherwise, a warning is issued and no code is generated for the `state` invocation. +`-fbad-getactorvar-use-pli` (default: off):: +If enabled and `-Werror-bad-getactorvar` is off, a `getactorvar` of a +per-player variable will result the gamevar being indexed with the current +player instead of the provided index. This is the (probably unintended) +behavior of C-CON. + `-fplayervar` (default: on):: If enabled, per-player `gamevar` definitions really generate `con.playervar` initializations in the translated Lua code. Otherwise, per-player gamevars are diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index 835ece51d..84deea677 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -124,7 +124,8 @@ local g_warn = { ["not-redefined"]=true, ["bad-identifier"]=false, -- Code generation and output options. local g_cgopt = { ["no"]=false, ["debug-lineinfo"]=false, ["gendir"]=nil, ["cache-sap"]=false, ["error-nostate"]=true, - ["playervar"]=true, ["trapv"]=false, ["wrapv"]=false, } + ["playervar"]=true, ["trapv"]=false, ["wrapv"]=false, + ["bad-getactorvar-use-pli"]=false, } local function csapp() return g_cgopt["cache-sap"] end @@ -690,10 +691,10 @@ local function parse_number(pos, numstr) num = NaN end elseif (num >= 0x80000000) then - if (not hex and g_warn["number-conversion"]) then - pwarnprintf(pos, "number %s converted to a negative one", numstr) - end num = bit.tobit(num) + if (not hex and g_warn["number-conversion"]) then + pwarnprintf(pos, "number %s converted to %d", numstr, num) + end end -- printf("numstr:%s, num=%d (0x%s) '%s', resnum=%d (0x%s)", @@ -2075,6 +2076,14 @@ local function GetOrSetPerxvarCmd(Setp, Actorp) local xprintf = warnp and warnprintf or errprintf xprintf("gamevar `%s' is not per-%s", perxvarname, Actorp and "actor" or "player") + + if (warnp and bit.band(gv.flags, GVFLAG.PERX_MASK)==GVFLAG.PERPLAYER + and g_cgopt["bad-getactorvar-use-pli"]) then + -- For getactorvar[] accesses to per-player gamevars, if + -- -fbad-getactorvar-use-pli is provided, use current player + -- index, for compatibility with CON. + idx = "_pli" + end end if (not Actorp) then