From 757dbe9d6b65f43615747e3d96399a8abb941215 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Fri, 8 Aug 2014 20:02:55 +0000 Subject: [PATCH] LunaCON: properly initialize values of session (NODEFAULT) gamevars. git-svn-id: https://svn.eduke32.com/eduke32@4570 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/con_lang.lua | 1 - polymer/eduke32/source/lunatic/defs.ilua | 19 +++++++++++++------ .../eduke32/source/lunatic/doc/lunatic.txt | 4 ++-- polymer/eduke32/source/lunatic/lunacon.lua | 12 +++++++++--- 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/polymer/eduke32/source/lunatic/con_lang.lua b/polymer/eduke32/source/lunatic/con_lang.lua index 0ee301691..27119b5a8 100644 --- a/polymer/eduke32/source/lunatic/con_lang.lua +++ b/polymer/eduke32/source/lunatic/con_lang.lua @@ -431,7 +431,6 @@ local ActorLabels = { xpanning = SX".xpanning", ypanning = SX".ypanning", - -- Read access differs from write, write not available: alpha = { "_math.floor(spriteext[%s].alpha*255)", "spriteext[%s].alpha=(%%s)/255" }, isvalid = { "_con._isvalid(%s)" }, diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 9cf4b5deb..b48054cf0 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -1684,7 +1684,7 @@ local function getnumlocals(l) -- 200 is the max. number of locals at one level for i=1,200 do -- level: - -- 0 is getlocal() itself. + -- 0 is debug.getlocal() itself. -- 1 is this function (getnumlocals). -- 2 is the function calling getnumlocals() -- 3 is the function calling that one. @@ -2288,12 +2288,14 @@ do -- XXX: System gamevars? Most of them ought to be saved with C data. for modname, modvars in pairs(module_gamevars) do + local isCON = (modname==CON_MODULE_NAME) + sb:startmod(modname) -- Handle global gamevars first. for i=1,#modvars do local varname = modvars[i] - local excludedVars = modname==CON_MODULE_NAME and varname=="_V" and + local excludedVars = isCON and varname=="_V" and package_loaded[CON_MODULE_NAME]._V._IS_NORESET_GAMEVAR or nil -- Serialize gamevar named 'varname' from module named 'modname'. @@ -2303,7 +2305,7 @@ do -- We couldn't serialize that gamevar. slenptr[0] = -1 -- Signal which gamevar that was. - return (modname==CON_MODULE_NAME and "" or modname).."."..varname + return (isCON and "" or modname).."."..varname end end @@ -2335,8 +2337,8 @@ do local savecode = sb:getcode() if (ffiC._DEBUG_LUNATIC ~= 0) then - -- Dump the code if Lunatic debugging is enabled and there is a - -- LUNATIC_SAVECODE_FN variable in the environment. + -- Dump the code if Lunatic debugging is enabled (-Lopts=diag) and + -- there is a LUNATIC_SAVECODE_FN variable in the environment. local os = require("os") local fn = os.getenv("LUNATIC_SAVECODE_FN") @@ -2538,7 +2540,7 @@ if (assert(concode ~= nil)) then 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() + -- indexable with nonexistent keys. See e.g. control.lua: _A_SpawnGlass() if (ffiC._LUNATIC_STRICT ~= 0) then tab = setmetatable(tab, index_error_mt) end @@ -2588,3 +2590,8 @@ if (not g_firstRun) then ffiC.g_elFirstTime = 0 end + +if (g_restorefunc) then + -- Clear it so that it may be garbage-collected. + g_restorefunc = nil +end diff --git a/polymer/eduke32/source/lunatic/doc/lunatic.txt b/polymer/eduke32/source/lunatic/doc/lunatic.txt index 9960331e5..9e96e5187 100644 --- a/polymer/eduke32/source/lunatic/doc/lunatic.txt +++ b/polymer/eduke32/source/lunatic/doc/lunatic.txt @@ -121,8 +121,8 @@ _backtrace_ added. Additionally, errors not caught by a `pcall` result a permanent message to appear on the screen, containing the source file name and line number. -*`print(...)`*:: -The messages are printed to the OSD and the log. Color codes available in +*`print(str)`*:: +Prints a single message to the OSD and the log. Color codes available in EDuke32 (e.g. `^10` for dark red) are interpreted. Overriding `tostring` has no effect on Lunatic's `print` as it uses the initial, built-in `tostring` function instead of looking it up in the global environment. diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index a3a70b51e..c86528757 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -1476,7 +1476,6 @@ function Cmd.gamevar(identifier, initval, flags) return end - -- TODO: handle user bits like NORESET or NODEFAULT if (bit.band(flags, bit.bnot(GVFLAG.USER_MASK)) ~= 0) then -- TODO: a couple of the presumably safe ones errprintf("gamevar flags other than 1, 2, 1024 or 131072: NYI or forbidden") @@ -1492,6 +1491,7 @@ function Cmd.gamevar(identifier, initval, flags) end local ogv = g_gamevar[identifier] + -- handle NORESET or NODEFAULT local isSessionVar = (bit.band(flags, GVFLAG.NODEFAULT) ~= 0) local storeWithSavegames = (bit.band(flags, GVFLAG.NORESET) == 0) @@ -1573,9 +1573,15 @@ function Cmd.gamevar(identifier, initval, flags) end -- Declare new session gamevar. - g_gamevar[identifier] = { name=format("_gv._sessionVar[%d]", g_numSessionVars), - flags=flags, loc=getLocation(), used=0 } + local gv = { name=format("_gv._sessionVar[%d]", g_numSessionVars), + flags=flags, loc=getLocation(), used=0 } g_numSessionVars = g_numSessionVars+1 + + g_gamevar[identifier] = gv; + -- Initialize it (i.e. set to the declared initial value) on first run, + -- but not from savegames. + addcodef("if _S then %s=%d end", gv.name, initval) + return end