From 2f29a89368d445549f46f9fef5c622745aa88e40 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Wed, 12 Jun 2013 17:49:47 +0000 Subject: [PATCH] Lunatic: provide CON-defined labels in read-only table require("CON.DEFS"). git-svn-id: https://svn.eduke32.com/eduke32@3870 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/lunatic/con_lang.lua | 37 +------------------ polymer/eduke32/source/lunatic/defs.ilua | 28 ++++++++------ .../eduke32/source/lunatic/doc/lunatic.txt | 10 +++-- polymer/eduke32/source/lunatic/lunacon.lua | 13 +++++++ polymer/eduke32/source/lunatic/test.elua | 5 +++ 5 files changed, 41 insertions(+), 52 deletions(-) diff --git a/polymer/eduke32/source/lunatic/con_lang.lua b/polymer/eduke32/source/lunatic/con_lang.lua index d5065d733..a2359262b 100644 --- a/polymer/eduke32/source/lunatic/con_lang.lua +++ b/polymer/eduke32/source/lunatic/con_lang.lua @@ -71,41 +71,6 @@ PROJ = { PROJ_USERDATA = 29, } --- PROJ_* define -> projectile_t member name ---[[ -PROJ_MEMBNAME = { - [PROJ.PROJ_WORKSLIKE] = "workslike", - [PROJ.PROJ_SPAWNS] = "spawns", - [PROJ.PROJ_SXREPEAT] = "sxrepeat", - [PROJ.PROJ_SYREPEAT] = "syrepeat", - [PROJ.PROJ_SOUND] = "sound", - [PROJ.PROJ_ISOUND] = "isound", - [PROJ.PROJ_VEL] = "vel", - [PROJ.PROJ_EXTRA] = "extra", - [PROJ.PROJ_DECAL] = "decal", - [PROJ.PROJ_TRAIL] = "trail", - [PROJ.PROJ_TXREPEAT] = "txrepeat", - [PROJ.PROJ_TYREPEAT] = "tyrepeat", - [PROJ.PROJ_TOFFSET] = "toffset", - [PROJ.PROJ_TNUM] = "tnum", - [PROJ.PROJ_DROP] = "drop", - [PROJ.PROJ_CSTAT] = "cstat", - [PROJ.PROJ_CLIPDIST] = "clipdist", - [PROJ.PROJ_SHADE] = "shade", - [PROJ.PROJ_XREPEAT] = "xrepeat", - [PROJ.PROJ_YREPEAT] = "yrepeat", - [PROJ.PROJ_PAL] = "pal", - [PROJ.PROJ_EXTRA_RAND] = "extra_rand", - [PROJ.PROJ_HITRADIUS] = "hitradius", - [PROJ.PROJ_VEL_MULT] = "movecnt", -- NAME - [PROJ.PROJ_OFFSET] = "offset", - [PROJ.PROJ_BOUNCES] = "bounces", - [PROJ.PROJ_BSOUND] = "bsound", - [PROJ.PROJ_RANGE] = "range", - [PROJ.PROJ_FLASH_COLOR] = "flashcolor", -- NAME -} ---]] - -- TODO: EVENT_INIT currently can't run since we init Lunatic state only afterwards EVENT = { EVENT_INIT = 0, @@ -802,7 +767,7 @@ local ProjectileLabels = { userdata = PROJ".userdata", } --- XXX: kind of CODEDUP form above +-- XXX: kind of CODEDUP form spr2tspr local function proj2thisproj(code) if (code and code:find(PROJ"", 1, true)==1) then return THISPROJ(code:sub(#PROJ"" + 1)) diff --git a/polymer/eduke32/source/lunatic/defs.ilua b/polymer/eduke32/source/lunatic/defs.ilua index 9f07729c3..4a2d54cc1 100644 --- a/polymer/eduke32/source/lunatic/defs.ilua +++ b/polymer/eduke32/source/lunatic/defs.ilua @@ -1351,19 +1351,17 @@ local allowed_modules = { } -- Protect base modules. -do - local function basemodule_newindex() - error("modifying base module table forbidden", 2) - end +local function basemodule_newindex() + error("modifying base module table forbidden", 2) +end - for modname, themodule in pairs(allowed_modules) do - local mt = { - __index = themodule, - __newindex = basemodule_newindex, - } +for modname, themodule in pairs(allowed_modules) do + local mt = { + __index = themodule, + __newindex = basemodule_newindex, + } - allowed_modules[modname] = setmtonce({}, mt) - end + allowed_modules[modname] = setmtonce({}, mt) end @@ -2037,8 +2035,14 @@ if (concode) then error("Failure loading translated CON code: "..conerrmsg, 0) end - package_loaded[CON_MODULE_NAME] = confunc() + local conmodule, conlabels = confunc() + + package_loaded[CON_MODULE_NAME] = conmodule module_gamevars[CON_MODULE_NAME] = { "A", "V" } -- See CON_GAMEVARS is lunacon.lua. + + -- Set up CON.DEFS module, providing access to labels defined in CON from Lua. + local mt = { __index = conlabels, __newindex = basemodule_newindex } + allowed_modules["CON.DEFS"] = setmtonce({}, mt) end -- When starting a map, load Lua modules given on the command line. diff --git a/polymer/eduke32/source/lunatic/doc/lunatic.txt b/polymer/eduke32/source/lunatic/doc/lunatic.txt index 616296dc6..db8be1ff2 100644 --- a/polymer/eduke32/source/lunatic/doc/lunatic.txt +++ b/polymer/eduke32/source/lunatic/doc/lunatic.txt @@ -120,9 +120,8 @@ time. ==== The function `require(modname, ...)` -Attempts to find a Lua or Lunatic module named `modname`, which should not -contain directory separators. The name can refer to a _built-in_ module, of -which the following ones are allowed: +Attempts to find a Lua or Lunatic module named `modname`. The name can refer to +a _built-in_ module, of which the following ones are allowed: * The http://bitop.luajit.org/[`bit`] module for bitwise operations * `math`, `string` and `table`, base modules from Lua @@ -621,7 +620,10 @@ If this sprite is _view-aligned_, controls the distance at which another moving object is considered to be in collision with this *stationary* sprite. (It does not control the inverse case.) More precisely, it designates half the side-length of the bounding square divided by 4. Thus, a value of `255` keeps -moving objects away from this one at a Manhattan distance of at least 1020 +moving objects away from this one at a max-norm distance +footnote:[The max-norm distance between points _p_~1~=(x~1~, y~1~) and +_p_~2~=(x~2~, y~2~) is defined as max(abs(x~2~ -- x~1~), abs(y~2~ -- y~1~)).] +of at least 1020 BUILD x/y units. _`u8`_ `xrepeat`, `yrepeat`:: diff --git a/polymer/eduke32/source/lunatic/lunacon.lua b/polymer/eduke32/source/lunatic/lunacon.lua index 2b9dc40c0..29f3dca31 100644 --- a/polymer/eduke32/source/lunatic/lunacon.lua +++ b/polymer/eduke32/source/lunatic/lunacon.lua @@ -602,6 +602,7 @@ local LABEL_FUNCNAME = { [2]="move", [3]="ai", [5]="action" } local g_labeldef = {} -- Lua numbers for numbers, strings for composites local g_labeltype = {} +local g_labelspecial = {} -- [