mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-25 03:00:46 +00:00
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
This commit is contained in:
parent
d25dcbff17
commit
2f29a89368
5 changed files with 41 additions and 52 deletions
|
@ -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))
|
||||
|
|
|
@ -1351,19 +1351,17 @@ local allowed_modules = {
|
|||
}
|
||||
|
||||
-- Protect base modules.
|
||||
do
|
||||
local function basemodule_newindex()
|
||||
local function basemodule_newindex()
|
||||
error("modifying base module table forbidden", 2)
|
||||
end
|
||||
end
|
||||
|
||||
for modname, themodule in pairs(allowed_modules) do
|
||||
for modname, themodule in pairs(allowed_modules) do
|
||||
local mt = {
|
||||
__index = themodule,
|
||||
__newindex = basemodule_newindex,
|
||||
}
|
||||
|
||||
allowed_modules[modname] = setmtonce({}, mt)
|
||||
end
|
||||
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.
|
||||
|
|
|
@ -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`::
|
||||
|
|
|
@ -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 = {} -- [<label>] = true
|
||||
|
||||
local function reset_labels()
|
||||
g_badids = {}
|
||||
|
@ -622,6 +623,7 @@ local function reset_labels()
|
|||
|
||||
for varname,_ in pairs(g_labeldef) do
|
||||
g_labeltype[varname] = LABEL.NUMBER
|
||||
g_labelspecial[varname] = true
|
||||
end
|
||||
|
||||
-- Initialize default defines.
|
||||
|
@ -3319,6 +3321,17 @@ local function get_code_string(codetab, lineinfop)
|
|||
-- Finalize translated code: return table containing gamevar and gamearray
|
||||
-- tables. CON_GAMEVARS.
|
||||
codetab[#codetab+1] = "return { V=_V, A=_A }"
|
||||
|
||||
-- Return defined labels in a table...
|
||||
codetab[#codetab+1] = ",{"
|
||||
for label, val in pairs(g_labeldef) do
|
||||
-- ... skipping 'NO' and those that are gamevars in C-CON.
|
||||
if (g_labeltype[label]==LABEL.NUMBER and not g_labelspecial[label]) then
|
||||
codetab[#codetab+1] = format("[%q]=%d,", label, val)
|
||||
end
|
||||
end
|
||||
codetab[#codetab+1] = "}"
|
||||
|
||||
local flatcode = flatten_codetab(codetab)
|
||||
local lineinfo = lineinfop and get_lineinfo(flatcode)
|
||||
return table.concat(flatcode, "\n"), lineinfo
|
||||
|
|
|
@ -538,3 +538,8 @@ spritesofsect(0)
|
|||
-- This will complain about wrong usage of 'error'. In particular,
|
||||
-- the nil must not propagate to C!
|
||||
checkfail('error(nil)', "error using 'error': error message must be a string")
|
||||
|
||||
local D = require("CON.DEFS")
|
||||
checkfail('require("CON.DEFS").APLAYER=123', "modifying base module table forbidden")
|
||||
-- Test with lunatic/test/rotfixed_actor.con.
|
||||
print("DUKECAR="..tostring(D.DUKECAR))
|
||||
|
|
Loading…
Reference in a new issue